Skip to content

Commit 82ebb17

Browse files
author
Alex Eagle
committed
Allow for requirements files to differ per platform
As a common example, we need a compiled requirements file for linux that differs from mac os
1 parent 9f59762 commit 82ebb17

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

python/pip.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
load("//python/pip_install:pip_repository.bzl", "pip_repository")
1717
load("//python/pip_install:repositories.bzl", "pip_install_dependencies")
1818

19-
def pip_install(requirements, name = "pip", **kwargs):
19+
def pip_install(requirements = None, name = "pip", **kwargs):
2020
"""Imports a `requirements.txt` file and generates a new `requirements.bzl` file.
2121
2222
This is used via the `WORKSPACE` pattern:

python/pip_install/pip_repository.bzl

+13-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ def _pip_repository_impl(rctx):
101101

102102
pypath = _construct_pypath(rctx)
103103

104+
os = rctx.os.name.lower()
105+
requirements_txt = rctx.attr.requirements
106+
107+
if os in rctx.attr.platform_requirements:
108+
requirements_txt = Label(rctx.attr.platform_requirements[os])
109+
110+
if requirements_txt == None:
111+
fail("Expected one of requirements attribute, or platform_requirements attribute to have key " + os)
112+
104113
if rctx.attr.incremental:
105114
args = [
106115
python_interpreter,
@@ -120,7 +129,7 @@ def _pip_repository_impl(rctx):
120129
"-m",
121130
"python.pip_install.extract_wheels",
122131
"--requirements",
123-
rctx.path(rctx.attr.requirements),
132+
rctx.path(requirements_txt),
124133
]
125134

126135
args += ["--repo", rctx.attr.name]
@@ -208,6 +217,9 @@ pip_repository_attrs = {
208217
allow_single_file = True,
209218
doc = "A 'requirements.txt' pip requirements file.",
210219
),
220+
"platform_requirements": attr.string_dict(
221+
doc = "Override the requirements attribute when running on a matching host platform",
222+
),
211223
"requirements_lock": attr.label(
212224
allow_single_file = True,
213225
doc = """

0 commit comments

Comments
 (0)