@@ -188,7 +188,7 @@ load("@my_deps//:requirements.bzl", "pip_install")
188
188
pip_install()
189
189
```
190
190
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 ) .
192
192
193
193
### Consuming ` pip ` dependencies
194
194
@@ -197,9 +197,7 @@ wheel's contents. Rather than depend on this target's label directly -- which
197
197
would require hardcoding the wheel repo's mangled name into your BUILD files --
198
198
you should instead use the ` requirement() ` function defined in the central
199
199
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.
203
201
204
202
``` python
205
203
load(" @my_deps//:requirements.bzl" , " requirement" )
@@ -210,17 +208,35 @@ py_library(
8000
div>
210
208
deps = [
211
209
" :myotherlib" ,
212
210
requirement(" some_pip_dep" ),
213
- requirement(" another_pip_dep[some_extra] " ),
211
+ requirement(" another_pip_dep" ),
214
212
]
215
213
)
216
214
```
217
215
216
+
218
217
For reference, the wheel repos are canonically named following the pattern:
219
218
` @{central_repo_name}_pypi__{distribution}_{version} ` . Characters in the
220
219
distribution and version that are illegal in Bazel label names (e.g. ` - ` , ` . ` )
221
220
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") ` .
224
240
225
241
### Consuming Wheel Dists Directly
226
242
0 commit comments