Skip to content

Commit ccbb05e

Browse files
authored
Allow overriding config attrs in pip_parse-generated install_deps (bazel-contrib#751)
1 parent ad0b8f8 commit ccbb05e

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

examples/pip_parse_vendored/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,23 @@ The requirements now form a triple:
99
- requirements.in - human editable, expresses only direct dependencies and load-bearing version constraints
1010
- requirements.txt - lockfile produced by pip-compile or other means
1111
- requirements.bzl - the "parsed" version of the lockfile readable by Bazel downloader
12+
13+
The `requirements.bzl` file contains baked-in attributes such as `python_interpreter_target` as they were specified in the original `pip_parse` rule. These can be overridden at install time by passing arguments to `install_deps`. For example:
14+
15+
```python
16+
# Register a hermetic toolchain
17+
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
18+
19+
python_register_toolchains(
20+
name = "python39",
21+
python_version = "3.9",
22+
)
23+
load("@python39//:defs.bzl", "interpreter")
24+
25+
# Load dependencies vendored by some other ruleset.
26+
load("@some_rules//:py_deps.bzl", "install_deps")
27+
28+
install_deps(
29+
python_interpreter_target = interpreter,
30+
)
31+
```

examples/pip_parse_vendored/requirements.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ def _get_annotation(requirement):
4141
name = requirement.split(" ")[0].split("=")[0]
4242
return _annotations.get(name)
4343

44-
def install_deps():
44+
def install_deps(**whl_library_kwargs):
45+
whl_config = dict(_config)
46+
whl_config.update(whl_library_kwargs)
4547
for name, requirement in _packages:
4648
whl_library(
4749
name = name,
4850
requirement = requirement,
4951
annotation = _get_annotation(requirement),
50-
**_config
52+
**whl_config
5153
)

python/pip_install/extract_wheels/parse_requirements_to_bzl.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,15 @@ def _get_annotation(requirement):
158158
name = requirement.split(" ")[0].split("=")[0]
159159
return _annotations.get(name)
160160
161-
def install_deps():
161+
def install_deps(**whl_library_kwargs):
162+
whl_config = dict(_config)
163+
whl_config.update(whl_library_kwargs)
162164
for name, requirement in _packages:
163165
whl_library(
164166
name = name,
165167
requirement = requirement,
166168
annotation = _get_annotation(requirement),
167-
**_config
169+
**whl_config
168170
)
169171
""".format(
170172
all_requirements=all_requirements,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy