8000 You only need to specify extras in the requirement macro if using leg… · lapointexavier/rules_python@5126cf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5126cf1

Browse files
author
Jonathon Belotti
authored
You only need to specify extras in the requirement macro if using legacy pip_import (bazel-contrib#445)
1 parent 6f37aa9 commit 5126cf1

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ load("@my_deps//:requirements.bzl", "pip_install")
188188
pip_install()
189189
```
190190

191-
An example can be found in [`examples/legacy_pip_import](examples/legacy_pip_import).
191+
An example can be found in [`examples/legacy_pip_import`](examples/legacy_pip_import).
192192

193193
### Consuming `pip` dependencies
194194

@@ -197,9 +197,7 @@ wheel's contents. Rather than depend on this target's label directly -- which
197197
would require hardcoding the wheel repo's mangled name into your BUILD files --
198198
you should instead use the `requirement()` function defined in the central
199199
repo's `//:requirements.bzl` file. This function maps a pip package name to a
200-
label. (["Extras"](
201-
https://packaging.python.org/tutorials/installing-packages/#installing-setuptools-extras)
202-
can be referenced using the `pkg[extra]` syntax.)
200+
label.
203201

204202
```python
205203
load("@my_deps//:requirements.bzl", "requirement")
@@ -210,17 +208,35 @@ py_library(
210208
deps = [
211209
":myotherlib",
212210
requirement("some_pip_dep"),
213-
requirement("another_pip_dep[some_extra]"),
211+
requirement("another_pip_dep"),
214212
]
215213
)
216214
```
217215

216+
218217
For reference, the wheel repos are canonically named following the pattern:
219218
`@{central_repo_name}_pypi__{distribution}_{version}`. Characters in the
220219
distribution and version that are illegal in Bazel label names (e.g. `-`, `.`)
221220
are replaced with `_`. While this naming pattern doesn't change often, it is
222-
not guaranted to remain stable, so use of the `requirement()` function is
223-
recommended.
221+
not guaranted to remain stable, so use of the `requirement()` function is recommended.
222+
223+
#### 'Extras' requirement consumption
224+
225+
When using the legacy `pip_import`, you must specify the extra in the argument to the `requirement` macro. For example:
226+
227+
```python
228+
py_library(
229+
name = "mylib",
230+
srcs = ["mylib.py"],
231+
deps = [
232+
requirement("useful_dep[some_extra]"),
233+
]
234+
)
235+
```
236+
237+
If using `pip_install` or `pip_parse`, any extras specified in the requirements file will be automatically
238+
linked as a dependency of the package so that you don't need to specify the extra. In the example above,
239+
you'd just put `requirement("useful_dep")`.
224240

225241
### Consuming Wheel Dists Directly
226242

0 commit comments

Comments
 (0)
0