Skip to content

Commit

Permalink
Allow for requirements files to differ per platform
Browse files Browse the repository at this point in the history
As a common example, we need a compiled requirements file for linux that differs from mac os
  • Loading branch information
Alex Eagle committed Sep 8, 2021
1 parent 9f59762 commit 956e1bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
load("//python/pip_install:pip_repository.bzl", "pip_repository")
load("//python/pip_install:repositories.bzl", "pip_install_dependencies")

def pip_install(requirements, name = "pip", **kwargs):
def pip_install(requirements = None, name = "pip", **kwargs):
"""Imports a `requirements.txt` file and generates a new `requirements.bzl` file.
This is used via the `WORKSPACE` pattern:
Expand Down
14 changes: 13 additions & 1 deletion python/pip_install/pip_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,21 @@ def _pip_repository_impl(rctx):
str(rctx.attr.timeout),
]
else:
os = rctx.os.name.lower()
requirements_txt = rctx.attr.requirements

if os in rctx.attr.platform_requirements:
requirements_txt = Label(rctx.attr.platform_requirements[os])

if requirements_txt == None:
fail("You must set the requirements attribute, or platform_requirements attribute must include key " + os)

args = [
python_interpreter,
"-m",
"python.pip_install.extract_wheels",
"--requirements",
rctx.path(rctx.attr.requirements),
rctx.path(requirements_txt),
]

args += ["--repo", rctx.attr.name]
Expand Down Expand Up @@ -204,6 +213,9 @@ pip_repository_attrs = {
default = False,
doc = "Create the repository in incremental mode.",
),
"platform_requirements": attr.string_dict(
doc = "Override the requirements attribute when running on a matching host platform",
),
"requirements": attr.label(
allow_single_file = True,
doc = "A 'requirements.txt' pip requirements file.",
Expand Down

0 comments on commit 956e1bf

Please sign in to comment.