Skip to content

Commit ae7a267

Browse files
authored
Allow for requirements files to differ per platform (#531)
* 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 * Add pip_repository documentation The macros are leaky and otherwise you have to read sources to find out about the kwargs Fixes #384
1 parent 12662b6 commit ae7a267

File tree

6 files changed

+202
-17
lines changed

6 files changed

+202
-17
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/*.md linguist-generated=true

docs/BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ licenses(["notice"]) # Apache 2.0
2424
_DOCS = {
2525
"packaging": "//docs:packaging-docs",
2626
"pip": "//docs:pip-docs",
27+
"pip_repository": "//docs:pip-repository",
2728
"python": "//docs:core-docs",
2829
}
2930

@@ -104,6 +105,18 @@ stardoc(
104105
],
105106
)
106107

108+
stardoc(
109+
name = "pip-repository",
110+
out = "pip_repository.md_",
111+
input = "//python/pip_install:pip_repository.bzl",
112+
target_compatible_with = _NOT_WINDOWS,
113+
deps = [
114+
":bazel_repo_tools",
115+
":pip_install_bzl",
116+
"//third_party/github.com/bazelbuild/bazel-skylib/lib:versions",
117+
],
118+
)
119+
107120
stardoc(
108121
name = "packaging-docs",
109122
out = "packaging.md_",

docs/pip.md

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pip_repository.md

+140
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/pip.bzl

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ 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.
2727
28-
This macro runs a repository rule that invokes `pip`. In your WORKSPACE file:
28+
This macro wraps the [`pip_repository`](./pip_repository.md) rule that invokes `pip`.
29+
In your WORKSPACE file:
2930
3031
```python
3132
pip_install(
@@ -88,7 +89,7 @@ def pip_install(requirements, name = "pip", **kwargs):
8889
Args:
8990
requirements (Label): A 'requirements.txt' pip requirements file.
9091
name (str, optional): A unique name for the created external repository (default 'pip').
91-
**kwargs (dict): Keyword arguments passed directly to the `pip_repository` repository rule.
92+
**kwargs (dict): Additional arguments to the [`pip_repository`](./pip_repository.md) repository rule.
9293
"""
9394

9495
# Just in case our dependencies weren't already fetched
@@ -107,7 +108,8 @@ def pip_parse(requirements_lock, name = "pip_parsed_deps", **kwargs):
107108
Those dependencies become available in a generated `requirements.bzl` file.
108109
You can instead check this `requirements.bzl` file into your repo, see the "vendoring" section below.
109110
110-
This macro runs a repository rule that invokes `pip`. In your WORKSPACE file:
111+
This macro wraps the [`pip_repository`](./pip_repository.md) rule that invokes `pip`, with `incremental` set.
112+
In your WORKSPACE file:
111113
112114
```python
113115
load("@rules_python//python:pip.bzl", "pip_parse")
@@ -191,10 +193,11 @@ def pip_parse(requirements_lock, name = "pip_parsed_deps", **kwargs):
191193
of 'requirements' no resolve will take place and pip_repository will create
192194
individual repositories for each of your dependencies so that wheels are
193195
fetched/built only for the targets specified by 'build/run/test'.
196+
Note that if your lockfile is platform-dependent, you can use the `requirements_[platform]`
197+
attributes.
194198
name (str, optional): The name of the generated repository. The generated repositories
195199
containing each requirement will be of the form <name>_<requirement-name>.
196-
**kwargs (dict): Additional keyword arguments for the underlying
197-
`pip_repository` rule.
200+
**kwargs (dict): Additional arguments to the [`pip_repository`](./pip_repository.md) repository rule.
198201
"""
199202

200203
# Just in case our dependencies weren't already fetched

0 commit comments

Comments
 (0)