|
| 1 | + |
| 2 | +We're adding uv.lock support to pip.parse. |
| 3 | + |
| 4 | +A test has been added to `//test/uv_pypi` |
| 5 | + |
| 6 | +Verify functionality by running `bazel run //tests/uv_pypi:bin` |
| 7 | + |
| 8 | +The desired interface is by setting a `uv_lock` attribute in `pip.parse`. This |
| 9 | +has been configured in MODULE.bazel for the test already: |
| 10 | + |
| 11 | +``` |
| 12 | +dev_pip.parse( |
| 13 | + hub_name = "uv_pypi", |
| 14 | + python_version = "3.12", |
| 15 | + uv_lock = "//tests/uv_pypi:uv.lock", |
| 16 | +) |
| 17 | +``` |
| 18 | + |
| 19 | +A key helper to accomplish this is to use the toml2json tool, which handles |
| 20 | +converting the toml-format of uv.lock to JSON, which can then be processed |
| 21 | +by Starlark code. The name of this helper is `convert_uv_lock_to_json` |
| 22 | +in `python/private/pypi/uv_lock.bzl` |
| 23 | + |
| 24 | +Some background: |
| 25 | + |
| 26 | +The pypi integration uses a "hub" and "spokes" design. The hub is the |
| 27 | +`@uv_pypi` repo. This is basically a collection of BUILD files that |
| 28 | +have aliases that point to spoke repos. Spoke repos use the `whl_library` |
| 29 | +repository rule which downloads and extracts that actual wheel. |
| 30 | + |
| 31 | +Part 1: |
| 32 | + |
| 33 | +Analyze the pypi extension code base and write a plan of changes to make to |
| 34 | +`plan.md` that accomplish the different parts of what needs to be done. |
| 35 | + |
| 36 | +Part 2: |
| 37 | + |
| 38 | +Modify the pip.parse extension to convert the uv.lock file to JSON. |
| 39 | + |
| 40 | +From that, create a whl_library for each wheel URL. For now, if there |
| 41 | +are multiple versions of a package, take the highest version package. If |
| 42 | +there are multiple wheel URLs, use the first one. |
| 43 | + |
| 44 | +Part 3: |
| 45 | + |
| 46 | +Modify the whl_library generation logic to handle when there are multiple |
| 47 | +versions of a package available. This should use the "resolution-markers" |
| 48 | +information to generate select() expressions to pick between the different |
| 49 | +packages available. The wheel_tags_settings rule is a key helper for this: |
| 50 | +it can take a resolution-markers expression and evaluate it so that select() |
| 51 | +expressions can match it. |
| 52 | + |
| 53 | +As part of implementing this logic, the BUILD file for a package in the hub |
| 54 | +repo should use wheel_tags_settings. For example, if the absl_py package |
| 55 | +has two wheels, then the hub build file should look something like: |
| 56 | + |
| 57 | +``` |
| 58 | +# File: @uv_pypi//absl_py:BUILD.bazel |
| 59 | +
|
| 60 | +define_wheel_tag_settings([ |
| 61 | + ("@absl_py_a//:pkg", "resolution marker expr for a"), |
| 62 | + ("@absl_py_b//:pkg", "resolution marker expr for b"), |
| 63 | +]) |
| 64 | +alias( |
| 65 | + name = "absl_py", |
| 66 | + actual = select({ |
| 67 | + "pick_0": "@absl_py_a//:pkg", |
| 68 | + "pick_1": "@absl_py_b//:pkg", |
| 69 | + }) |
| 70 | +) |
| 71 | +``` |
0 commit comments