Commit b6de8cb
feat(uv): Add a clean-sheet dependency implementation (#650)
[Design doc](https://docs.google.com/document/d/1UFessu8_BwmfMJXDvhyhaASrNMo7_3-gO1lTVASbJbs)
An implementation of pip based on consuming PEP-751 [1] like lockfiles.
Specifically uv lockfiles, which contain internal dependency graph
information that the PEP-751 specification labels optional.
Follows in the footsteps of rules_js's pnpm support by consuming a
lockfile which contains enough information to produce materialize
dependencies without performing _any_ repository time operations which
could be platform dependent.
## Features
- Supports cross-platform builds of wheels
- Supports hermetic source builds of wheels
- Automatically handles dependency cycles
- Creates unified pip hubs which span virtualenv/dependency solution
boundaries
- Pip library targets from deactivated venvs are _incompatible_
- Platform constraints on pip libraries do not prevent the creation of a
library target
- Allows for `--editable`-like workflows
- Supports `console_scripts` entrypoints*
## Example
```
# MODULE.bazel content
uv = use_extensioin("@aspect_rules_py//uv:extesion.bzl", "uv")
uv.declare_hub(hub_name = "pip")
uv.declare_venv(hub_name = "pip", venv_name = "a")
uv.lockfile(hub_name = "pip", venv_name = "a", src = "third_party/py/venvs/uv-a.lock")
uv.declare_venv(hub_name = "pip", venv_name = "b")
uv.lockfile(hub_name = "pip", venv_name = "b", src = "third_party/py/venvs/uv-b.toml")
use_repo(pip, "pip")
```
```
# BUILD.bazel content
py_venv_binary(
name = "foo",
srcs = [
"foo.py",
],
main = "foo.py",
deps = [
"@pip//cowsay", # Pull cowsay from the configured venv
],
venv = "a", # Configure the default venv to be "a"; may be overriden at the CLI
)
```
The active venv state can be overriden at the cli by specifying
`--'@pip//venv=b'` here for instance, or by using transitions to(re) set
that same flag.
## Appendix
[1] https://peps.python.org/pep-0751/
[2] https://peps.python.org/pep-0751/#locking-build-requirements-for-sdists
### Changes are visible to end-users: yes
- Searched for relevant documentation and updated as needed: no
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: yes
`aspect_rules_py//uv` is now available as an alternative to `pip.parse`
### To do list
- ~[x] Audit the comments/FIXMEs for accuracy~ fast-follow
- ~[x] Go over zbarsky's nits~ mostly rejected for pythonstyle
- ~[x] Create a quick and dirty `uv_lock` rule~ fast-follow
- [x] Document the extension
- [x] Document that we consider the extension is unstable
- [x] Replace `pip.parse` internally entirely
- [x] Add support for annotating _replacement_ of pip deps with internal
builds (`--editable` / vendoring)
- [x] Implement an "all deps for all venvs" data source comparable to
the `rules_python` equivalent
- [x] Go back over the interpreter compatibility machinery and align it
with `rules_python`'s config settings for now
- [x] Go back over the interpreter feature flags and align it with
`rules_python`'s config settings for now
bazel-contrib/rules_python#3314
- ~Investigate implementing a `dist_info` target comparable to that
which `rules_python` generates~ There isn't a great way to do this
because dist-info is in our world part of the installed package, so any
such target is just ignoring the PyInfo details on the fileset.
- [x] Provide a pattern for implementing/activating venv entrypoints
- [x] Implement conditional activation of deps
- [x] Implement an "all active deps" target comparable to the
`rules_python` all list
- [x] Look into platform conditional deps & how they get represented
- [x] Flatten the git log
- [x] Ensure `python_version` transition consistency with `rules_python`
- [x] Consider a feature flag to turn on `rules_python`'s [package name
normalization](https://github.com/bazel-contrib/rules_python/blob/main/python/private/normalize_name.bzl)
so that migration is easier.
- [x] Implement extra activation
- [x] Match the `rules_python` `@hub//package[:package]` syntax?
- [X] Get a `toml.bzl` working
- [X] Toolchainize the `uv` dependency
### Test plan
- [X] Manually test flipping the venv command line flag
- [X] Manually test flipping the venv transition attr
- [x] Create `py_venv_test`s covering that different versions of the
same package can be concurrently configured via different venvs
- [x] Create a `py_venv_test` covering that Airflow or another package
with dependency cycles can be provisioned
- [x] Create a `py_venv_binary` embedded in and transitioned for a Linux
OCI container across arch boundaries
- [x] Create a `py_venv_test` covering overriding a pip dep with a
1stparty target
---------
Co-authored-by: aspect-marvin[bot] <[email protected]>1 parent 2dadcf0 commit b6de8cb
File tree
119 files changed
+16899
-1304
lines changed- .bcr/patches
- bazel
- include
- patches
- docs
- e2e
- cases/uv-deps-650
- airflow
- crossbuild
- say
- third_party/cowsay
- cowsay-6.1.dist-info
- cowsay
- py
- private
- py_venv
- toolchain
- tests
- py-binary
- py-external-venv
- py_image_layer
- py_venv_conflict
- py_venv_image_layer
- virtual/django
- tools
- py/src
- venv_shim/src
- tools/bazel
- uv
- private
- constraints
- abi
- platform
- python
- venv
- host
- hub
- manifest
- markers
- py_entrypoint_binary
- sdist_build
- tomltool
- uv
- venv_hub
- whl_install
- unstable
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
119 files changed
+16899
-1304
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 5 | | |
10 | 6 | | |
11 | 7 | | |
12 | 8 | | |
13 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 172 | + | |
181 | 173 | | |
182 | 174 | | |
183 | 175 | | |
| |||
493 | 485 | | |
494 | 486 | | |
495 | 487 | | |
| 488 | + | |
496 | 489 | | |
497 | 490 | | |
498 | 491 | | |
499 | 492 | | |
500 | 493 | | |
501 | 494 | | |
502 | | - | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
503 | 500 | | |
504 | | - | |
505 | | - | |
506 | 501 | | |
507 | | - | |
| 502 | + | |
508 | 503 | | |
509 | | - | |
510 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
511 | 515 | | |
512 | | - | |
| 516 | + | |
513 | 517 | | |
514 | 518 | | |
515 | 519 | | |
| |||
536 | 540 | | |
537 | 541 | | |
538 | 542 | | |
539 | | - | |
540 | 543 | | |
541 | 544 | | |
542 | 545 | | |
543 | 546 | | |
544 | 547 | | |
545 | 548 | | |
| 549 | + | |
546 | 550 | | |
547 | 551 | | |
548 | 552 | | |
549 | 553 | | |
550 | | - | |
| 554 | + | |
551 | 555 | | |
552 | 556 | | |
553 | 557 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | | - | |
5 | | - | |
| 3 | + | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
| |||
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
27 | 43 | | |
28 | 44 | | |
29 | 45 | | |
| |||
189 | 205 | | |
190 | 206 | | |
191 | 207 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 208 | + | |
201 | 209 | | |
202 | 210 | | |
203 | 211 | | |
| |||
513 | 521 | | |
514 | 522 | | |
515 | 523 | | |
| 524 | + | |
516 | 525 | | |
517 | 526 | | |
518 | 527 | | |
519 | 528 | | |
520 | 529 | | |
521 | 530 | | |
522 | | - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
523 | 536 | | |
524 | | - | |
525 | | - | |
526 | 537 | | |
527 | | - | |
| 538 | + | |
528 | 539 | | |
529 | | - | |
530 | | - | |
| 540 | + | |
531 | 541 | | |
532 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
533 | 553 | | |
534 | 554 | | |
535 | 555 | | |
| |||
556 | 576 | | |
557 | 577 | | |
558 | 578 | | |
559 | | - | |
560 | 579 | | |
561 | 580 | | |
562 | 581 | | |
563 | 582 | | |
564 | 583 | | |
565 | 584 | | |
| 585 | + | |
566 | 586 | | |
567 | 587 | | |
568 | 588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
6 | 4 | | |
7 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | | - | |
24 | | - | |
25 | 28 | | |
26 | | - | |
| 29 | + | |
27 | 30 | | |
28 | | - | |
29 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
30 | 42 | | |
31 | | - | |
| 43 | + | |
32 | 44 | | |
33 | 45 | | |
34 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
0 commit comments