Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f480ebe

Browse filesBrowse files
Alex Eaglealexeagle
Alex Eagle
authored andcommitted
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 12662b6 commit f480ebe
Copy full SHA for f480ebe

File tree

Expand file treeCollapse file tree

3 files changed

+33
-7
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+33
-7
lines changed

‎docs/pip.md

Copy file name to clipboardExpand all lines: docs/pip.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ alias(
140140

141141
| Name | Description | Default Value |
142142
| :-------------: | :-------------: | :-------------: |
143-
| requirements | A 'requirements.txt' pip requirements file. | none |
143+
| requirements | A 'requirements.txt' pip requirements file. | <code>None</code> |
144144
| name | A unique name for the created external repository (default 'pip'). | <code>"pip"</code> |
145145
| kwargs | Keyword arguments passed directly to the <code>pip_repository</code> repository rule. | none |
146146

‎python/pip.bzl

Copy file name to clipboardExpand all lines: python/pip.bzl
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ load("//python/pip_install:requirements.bzl", _compile_pip_requirements = "compi
2020
compile_pip_requirements = _compile_pip_requirements
2121
package_annotation = _package_annotation
2222

23-
def pip_install(requirements, name = "pip", **kwargs):
23+
def pip_install(requirements = None, name = "pip", **kwargs):
2424
"""Accepts a `requirements.txt` file and installs the dependencies listed within.
2525
2626
Those dependencies become available in a generated `requirements.bzl` file.

‎python/pip_install/pip_repository.bzl

Copy file name to clipboardExpand all lines: python/pip_install/pip_repository.bzl
+31-5Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,40 @@ package(default_visibility = ["//visibility:public"])
119119
exports_files(["requirements.bzl"])
120120
"""
121121

122+
def _locked_requirements(rctx):
123+
os = rctx.os.name.lower()
124+
requirements_txt = rctx.attr.requirements_lock
125+
if os.startswith("mac os") and rctx.attr.requirements_darwin != None:
126+
requirements_txt = rctx.attr.requirements_darwin
127+
elif os.startswith("linux") and rctx.attr.requirements_linux != None:
128+
requirements_txt = rctx.attr.requirements_linux
129+
elif "win" in os:
130+
requirements_txt = rctx.attr.requirements_windows
131+
if not requirements_txt:
132+
fail("""\
133+
Incremental mode requires a requirements_lock attribute be specified,
134+
or a platform-specific lockfile using one of the requirements_* attributes.
135+
""")
136+
return requirements_txt
137+
122138
def _pip_repository_impl(rctx):
123139
python_interpreter = _resolve_python_interpreter(rctx)
124140

125-
if rctx.attr.incremental and not rctx.attr.requirements_lock:
126-
fail("Incremental mode requires a requirements_lock attribute be specified.")
127-
128141
# Write the annotations file to pass to the wheel maker
129142
annotations = {package: json.decode(data) for (package, data) in rctx.attr.annotations.items()}
130143
annotations_file = rctx.path("annotations.json")
131144
rctx.file(annotations_file, json.encode_indent(annotations, indent = " " * 4))
132145

133146
if rctx.attr.incremental:
147+
requirements_txt = _locked_requirements(rctx)
134148
args = [
135149
python_interpreter,
136150
"-m",
137151
"python.pip_install.parse_requirements_to_bzl",
138152
"--requirements_lock",
139-
rctx.path(rctx.attr.requirements_lock),
153+
rctx.path(requirements_txt),
140154
"--requirements_lock_label",
141-
str(rctx.attr.requirements_lock),
155+
str(requirements_txt),
142156
# pass quiet and timeout args through to child repos.
143157
"--quiet",
144158
str(rctx.attr.quiet),
@@ -282,6 +296,14 @@ pip_repository_attrs = {
282296
allow_single_file = True,
283297
doc = "A 'requirements.txt' pip requirements file.",
284298
),
299+
"requirements_darwin": attr.label(
300+
allow_single_file = True,
301+
doc = "Override the requirements_lock attribute when the host platform is Mac OS",
302+
),
303+
"requirements_linux": attr.label(
304+
allow_single_file = True,
305+
doc = "Override the requirements_lock attribute when the host platform is Linux",
306+
),
285307
"requirements_lock": attr.label(
286308
allow_single_file = True,
287309
doc = """
@@ -290,6 +312,10 @@ of 'requirements' no resolve will take place and pip_repository will create indi
290312
wheels are fetched/built only for the targets specified by 'build/run/test'.
291313
""",
292314
),
315+
"requirements_windows": attr.label(
316+
allow_single_file = True,
317+
doc = "Override the requirements_lock attribute when the host platform is Windows",
318+
),
293319
}
294320

295321
pip_repository_attrs.update(**common_attrs)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.