8000 Allow overriding config attrs in pip_parse-generated install_deps by jvolkman · Pull Request #751 · bazel-contrib/rules_python · GitHub
[go: up one dir, main page]

Skip to content

Allow overriding config attrs in pip_parse-generated install_deps #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/pip_parse_vendored/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ The requirements now form a triple:
- requirements.in - human editable, expresses only direct dependencies and load-bearing version constraints
- requirements.txt - lockfile produced by pip-compile or other means
- requirements.bzl - the "parsed" version of the lockfile readable by Bazel downloader

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:

```python
# Register a hermetic toolchain
load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python39",
python_version = "3.9",
)
load("@python39//:defs.bzl", "interpreter")

# Load dependencies vendored by some other ruleset.
load("@some_rules//:py_deps.bzl", "install_deps")

install_deps(
python_interpreter_target = interpreter,
)
```
6 changes: 4 additions & 2 deletions examples/pip_parse_vendored/requirements.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ def _get_annotation(requirement):
name = requirement.split(" ")[0].split("=")[0]
return _annotations.get(name)

def install_deps():
def install_deps(**whl_library_kwargs):
whl_config = dict(_config)
whl_config.update(whl_library_kwargs)
for name, requirement in _packages:
whl_library(
name = name,
requirement = requirement,
annotation = _get_annotation(requirement),
**_config
**whl_config
)
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ def _get_annotation(requirement):
name = requirement.split(" ")[0].split("=")[0]
return _annotations.get(name)

def install_deps():
def install_deps(**whl_library_kwargs):
whl_config = dict(_config)
whl_config.update(whl_library_kwargs)
for name, requirement in _packages:
whl_library(
name = name,
requirement = requirement,
annotation = _get_annotation(requirement),
**_config
**whl_config
)
""".format(
all_requirements=all_requirements,
Expand Down
0