Skip to content

Commit e78c9eb

Browse files
committed
Update python/pip.bzl
1 parent b08bc97 commit e78c9eb

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

docs/pip.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ compile_pip_requirements(<a href="#compile_pip_requirements-name">name</a>, <a h
99
<a href="#compile_pip_requirements-kwargs">kwargs</a>)
1010
</pre>
1111

12-
Macro creating targets for running pip-compile
12+
Generates targets for managing pip dependencies with pip-compile.
1313

14-
Produce a filegroup by default, named "[name]" which can be included in the data
14+
By default this rules generates a filegroup named "[name]" which can be included in the data
1515
of some other compile_pip_requirements rule that references these requirements
16-
(e.g. with `-r ../other/requirements.txt`)
16+
(e.g. with `-r ../other/requirements.txt`).
1717

18-
Produce two targets for checking pip-compile:
18+
It also generates two targets for running pip-compile:
1919

2020
- validate with `bazel test <name>_test`
2121
- update with `bazel run <name>.update`
@@ -43,7 +43,7 @@ Produce two targets for checking pip-compile:
4343
pip_import(<a href="#pip_import-kwargs">kwargs</a>)
4444
</pre>
4545

46-
46+
Rule for installing packages listed in a requirements file.
4747

4848
**PARAMETERS**
4949

@@ -61,17 +61,19 @@ pip_import(<a href="#pip_import-kwargs">kwargs</a>)
6161
pip_install(<a href="#pip_install-requirements">requirements</a>, <a href="#pip_install-name">name</a>, <a href="#pip_install-kwargs">kwargs</a>)
6262
</pre>
6363

64-
Imports a `requirements.txt` file and generates a new `requirements.bzl` file.
64+
Accepts a `requirements.txt` file and installs the dependencies listed within.
65+
66+
Those dependencies become available in a generated `requirements.bzl` file.
6567

66-
This is used via the `WORKSPACE` pattern:
68+
This macro runs a repository rule that invokes `pip`. In your WORKSPACE file:
6769

6870
```python
6971
pip_install(
7072
requirements = ":requirements.txt",
7173
)
7274
```
7375

74-
You can then reference imported dependencies from your `BUILD` file with:
76+
You can then reference installed dependencies from a `BUILD` file with:
7577

7678
```python
7779
load("@pip//:requirements.bzl", "requirement")
@@ -86,9 +88,16 @@ py_library(
8688
)
8789
```
8890

89-
In addition to the `requirement` macro, which is used to access the generated `py_library`
90-
target generated from a package's wheel, The generated `requirements.bzl` file contains
91-
functionality for exposing [entry points][whl_ep] as `py_binary` targets as well.
91+
> Note that this convenience comes with a cost.
92+
> Analysis of any BUILD file which loads the requirements helper in this way will
93+
> cause an eager-fetch of all the pip dependencies,
94+
> even if no python targets are requested to be built.
95+
> In a multi-language repo, this may cause developers to fetch dependencies they don't need,
96+
> so consider using the long form for dependencies if this happens.
97+
98+
In addition to the `requirement` macro, which is used to access the `py_library`
99+
target generated from a package's wheel, the generated `requirements.bzl` file contains
100+
functionality for exposing [entry points][whl_ep] as `py_binary` targets.
92101

93102
[whl_ep]: https://packaging.python.org/specifications/entry-points/
94103

@@ -104,7 +113,7 @@ alias(
104113
)
105114
```
106115

107-
Note that for packages who's name and script are the same, only the name of the package
116+
Note that for packages whose name and script are the same, only the name of the package
108117
is needed when calling the `entry_point` macro.
109118

110119
```python
@@ -135,9 +144,11 @@ alias(
135144
pip_parse(<a href="#pip_parse-requirements_lock">requirements_lock</a>, <a href="#pip_parse-name">name</a>, <a href="#pip_parse-kwargs">kwargs</a>)
136145
</pre>
137146

138-
Imports a locked/compiled requirements file and generates a new `requirements.bzl` file.
147+
Accepts a locked/compiled requirements file and installs the dependencies listed within.
139148

140-
This is used via the `WORKSPACE` pattern:
149+
Those dependencies become available in a generated `requirements.bzl` file.
150+
151+
This macro runs a repository rule that invokes `pip`. In your WORKSPACE file:
141152

142153
```python
143154
load("@rules_python//python:pip.bzl", "pip_parse")
@@ -152,7 +163,7 @@ load("@pip_deps//:requirements.bzl", "install_deps")
152163
install_deps()
153164
```
154165

155-
You can then reference imported dependencies from your `BUILD` file with:
166+
You can then reference installed dependencies from a `BUILD` file with:
156167

157168
```python
158169
load("@pip_deps//:requirements.bzl", "requirement")
@@ -186,7 +197,7 @@ alias(
186197
)
187198
```
188199

189-
Note that for packages who's name and script are the same, only the name of the package
200+
Note that for packages whose name and script are the same, only the name of the package
190201
is needed when calling the `entry_point` macro.
191202

192203
```python
@@ -217,7 +228,7 @@ alias(
217228
pip_repositories()
218229
</pre>
219230

220-
231+
Obsolete macro to pull in dependencies needed to use the pip_import rule.
221232

222233
**PARAMETERS**
223234

python/pip.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ def pip_install(requirements, name = "pip", **kwargs):
4747
)
4848
```
4949
50+
> Note that this convenience comes with a cost.
51+
> Analysis of any BUILD file which loads the requirements helper in this way will
52+
> cause an eager-fetch of all the pip dependencies,
53+
> even if no python targets are requested to be built.
54+
> In a multi-language repo, this may cause developers to fetch dependencies they don't need,
55+
> so consider using the long form for dependencies if this happens.
56+
5057
In addition to the `requirement` macro, which is used to access the `py_library`
5158
target generated from a package's wheel, the generated `requirements.bzl` file contains
5259
functionality for exposing [entry points][whl_ep] as `py_binary` targets.

0 commit comments

Comments
 (0)