Skip to content

Commit 4a816ca

Browse files
committed
Spike uv
1 parent ac3abf6 commit 4a816ca

File tree

4 files changed

+110
-27
lines changed

4 files changed

+110
-27
lines changed

examples/bzlmod/requirements_windows_3_9.txt

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
#
2-
# This file is autogenerated by pip-compile with Python 3.9
3-
# by the following command:
4-
#
5-
# bazel run //:requirements_3_9.update
6-
#
7-
--extra-index-url https://pypi.org/simple/
8-
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile /Users/groodt/work/rules_python/examples/bzlmod/requirements.in --python-platform windows --python-version 3.9 --output-file /Users/groodt/work/rules_python/examples/bzlmod/requirements_windows_3_9.txt --generate-hashes --no-strip-extras
93
alabaster==0.7.13 \
104
--hash=sha256:1ee19aca801bbabb5ba3f5f258e4422dfa86f82f3e9cefb0859b283cdd7f62a3 \
115
--hash=sha256:a27a4a084d5e690e16e01e03ad2b2e552c61a65469419b907243193de1a84ae2
@@ -30,7 +24,7 @@ colorama==0.4.6 \
3024
--hash=sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
3125
--hash=sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
3226
# via
33-
# -r requirements.in
27+
# -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
3428
# pylint
3529
# sphinx
3630
dill==0.3.6 \
@@ -186,17 +180,17 @@ pylint==2.15.9 \
186180
--hash=sha256:18783cca3cfee5b83c6c5d10b3cdb66c6594520ffae61890858fe8d932e1c6b4 \
187181
--hash=sha256:349c8cd36aede4d50a0754a8c0218b43323d13d5d88f4b2952ddfe3e169681eb
188182
# via
189-
# -r requirements.in
183+
# -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
190184
# pylint-print
191185
pylint-print==1.0.1 \
192186
--hash=sha256:30aa207e9718ebf4ceb47fb87012092e6d8743aab932aa07aa14a73e750ad3d0 \
193187
--hash=sha256:a2b2599e7887b93e551db2624c523c1e6e9e58c3be8416cd98d41e4427e2669b
194-
# via -r requirements.in
188+
# via -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
195189
python-dateutil==2.8.2 \
196190
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
197191
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
198192
# via
199-
# -r requirements.in
193+
# -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
200194
# s3cmd
201195
python-magic==0.4.27 \
202196
--hash=sha256:c1ba14b08e4a5f5c31a302b7721239695b2f0f058d125bd5ce1ee36b9d9d3c3b \
@@ -259,12 +253,16 @@ requests==2.25.1 \
259253
--hash=sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804 \
260254
--hash=sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e
261255
# via
262-
# -r requirements.in
256+
# -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
263257
# sphinx
264258
s3cmd==2.1.0 \
265259
--hash=sha256:49cd23d516b17974b22b611a95ce4d93fe326feaa07320bd1d234fed68cbccfa \
266260
--hash=sha256:966b0a494a916fc3b4324de38f089c86c70ee90e8e1cae6d59102103a4c0cc03
267-
# via -r requirements.in
261+
# via -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
262+
setuptools==65.6.3 \
263+
--hash=sha256:57f6f22bde4e042978bcd50176fdb381d7c21a9efa4041202288d3737a0c6a54 \
264+
--hash=sha256:a7620757bf984b58deaf32fc8a4577a9bbc0850cf92c20e1ce41c38c19e5fb75
265+
# via yamllint
268266
six==1.16.0 \
269267
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
270268
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
@@ -277,7 +275,7 @@ sphinx==7.2.6 \
277275
--hash=sha256:1e09160a40b956dc623c910118fa636da93bd3ca0b9876a7b3df90f07d691560 \
278276
--hash=sha256:9a5160e1ea90688d5963ba09a2dcd8bdd526620edbb65c328728f1b2228d5ab5
279277
# via
280-
# -r requirements.in
278+
# -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
281279
# sphinxcontrib-applehelp
282280
# sphinxcontrib-devhelp
283281
# sphinxcontrib-htmlhelp
@@ -307,12 +305,12 @@ sphinxcontrib-serializinghtml==1.1.9 \
307305
--hash=sha256:0c64ff898339e1fac29abd2bf5f11078f3ec413cfe9c046d3120d7ca65530b54 \
308306
--hash=sha256:9b36e503703ff04f20e9675771df105e58aa029cfcbc23b8ed716019b7416ae1
309307
# via
310-
# -r requirements.in
308+
# -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
311309
# sphinx
312310
tabulate==0.9.0 \
313311
--hash=sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c \
314312
--hash=sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f
315-
# via -r requirements.in
313+
# via -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
316314
tomli==2.0.1 \
317315
--hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
318316
--hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f
@@ -402,35 +400,42 @@ websockets==11.0.3 \
402400
--hash=sha256:f61bdb1df43dc9c131791fbc2355535f9024b9a04398d3bd0684fc16ab07df74 \
403401
--hash=sha256:fb06eea71a00a7af0ae6aefbb932fb8a7df3cb390cc217d51a9ad7343de1b8d0 \
404402
--hash=sha256:ffd7dcaf744f25f82190856bc26ed81721508fc5cbf2a330751e135ff1283564
405-
# via -r requirements.in
403+
# via -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
406404
wheel==0.40.0 \
407405
--hash=sha256:cd1196f3faee2b31968d626e1731c94f99cbdb67cf5a46e4f5656cbee7738873 \
408406
--hash=sha256:d236b20e7cb522daf2390fa84c55eea81c5c30190f90f29ae2ca1ad8355bf247
409-
# via -r requirements.in
407+
# via -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
410408
wrapt==1.14.1 \
411409
--hash=sha256:00b6d4ea20a906c0ca56d84f93065b398ab74b927a7a3dbd470f6fc503f95dc3 \
412410
--hash=sha256:01c205616a89d09827986bc4e859bcabd64f5a0662a7fe95e0d359424e0e071b \
413411
--hash=sha256:02b41b633c6261feff8ddd8d11c711df6842aba629fdd3da10249a53211a72c4 \
414412
--hash=sha256:07f7a7d0f388028b2df1d916e94bbb40624c59b48ecc6cbc232546706fac74c2 \
415413
--hash=sha256:11871514607b15cfeb87c547a49bca19fde402f32e2b1c24a632506c0a756656 \
416414
--hash=sha256:1b376b3f4896e7930f1f772ac4b064ac12598d1c38d04907e696cc4d794b43d3 \
415+
--hash=sha256:2020f391008ef874c6d9e208b24f28e31bcb85ccff4f335f15a3251d222b92d9 \
417416
--hash=sha256:21ac0156c4b089b330b7666db40feee30a5d52634cc4560e1905d6529a3897ff \
417+
--hash=sha256:240b1686f38ae665d1b15475966fe0472f78e71b1b4903c143a842659c8e4cb9 \
418418
--hash=sha256:257fd78c513e0fb5cdbe058c27a0624c9884e735bbd131935fd49e9fe719d310 \
419+
--hash=sha256:26046cd03936ae745a502abf44dac702a5e6880b2b01c29aea8ddf3353b68224 \
419420
--hash=sha256:2b39d38039a1fdad98c87279b48bc5dce2c0ca0d73483b12cb72aa9609278e8a \
420421
--hash=sha256:2cf71233a0ed05ccdabe209c606fe0bac7379fdcf687f39b944420d2a09fdb57 \
421422
--hash=sha256:2fe803deacd09a233e4762a1adcea5db5d31e6be577a43352936179d14d90069 \
423+
--hash=sha256:2feecf86e1f7a86517cab34ae6c2f081fd2d0dac860cb0c0ded96d799d20b335 \
422424
--hash=sha256:3232822c7d98d23895ccc443bbdf57c7412c5a65996c30442ebe6ed3df335383 \
423425
--hash=sha256:34aa51c45f28ba7f12accd624225e2b1e5a3a45206aa191f6f9aac931d9d56fe \
426+
--hash=sha256:358fe87cc899c6bb0ddc185bf3dbfa4ba646f05b1b0b9b5a27c2cb92c2cea204 \
424427
--hash=sha256:36f582d0c6bc99d5f39cd3ac2a9062e57f3cf606ade29a0a0d6b323462f4dd87 \
425428
--hash=sha256:380a85cf89e0e69b7cfbe2ea9f765f004ff419f34194018a6827ac0e3edfed4d \
426429
--hash=sha256:40e7bc81c9e2b2734ea4bc1aceb8a8f0ceaac7c5299bc5d69e37c44d9081d43b \
427430
--hash=sha256:43ca3bbbe97af00f49efb06e352eae40434ca9d915906f77def219b88e85d907 \
431+
--hash=sha256:49ef582b7a1152ae2766557f0550a9fcbf7bbd76f43fbdc94dd3bf07cc7168be \
428432
--hash=sha256:4fcc4649dc762cddacd193e6b55bc02edca674067f5f98166d7713b193932b7f \
429433
--hash=sha256:5a0f54ce2c092aaf439813735584b9537cad479575a09892b8352fea5e988dc0 \
430434
--hash=sha256:5a9a0d155deafd9448baff28c08e150d9b24ff010e899311ddd63c45c2445e28 \
431435
--hash=sha256:5b02d65b9ccf0ef6c34cba6cf5bf2aab1bb2f49c6090bafeecc9cd81ad4ea1c1 \
432436
--hash=sha256:60db23fa423575eeb65ea430cee741acb7c26a1365d103f7b0f6ec412b893853 \
433437
--hash=sha256:642c2e7a804fcf18c222e1060df25fc210b9c58db7c91416fb055897fc27e8cc \
438+
--hash=sha256:6447e9f3ba72f8e2b985a1da758767698efa72723d5b59accefd716e9e8272bf \
434439
--hash=sha256:6a9a25751acb379b466ff6be78a315e2b439d4c94c1e99cb7266d40a537995d3 \
435440
--hash=sha256:6b1a564e6cb69922c7fe3a678b9f9a3c54e72b469875aa8018f18b4d1dd1adf3 \
436441
--hash=sha256:6d323e1554b3d22cfc03cd3243b5bb815a51f5249fdcbb86fda4bf62bab9e164 \
@@ -453,8 +458,10 @@ wrapt==1.14.1 \
453458
--hash=sha256:9e0fd32e0148dd5dea6af5fee42beb949098564cc23211a88d799e434255a1f4 \
454459
--hash=sha256:9f3e6f9e05148ff90002b884fbc2a86bd303ae847e472f44ecc06c2cd2fcdb2d \
455460
--hash=sha256:a85d2b46be66a71bedde836d9e41859879cc54a2a04fad1191eb50c2066f6e9d \
461+
--hash=sha256:a9008dad07d71f68487c91e96579c8567c98ca4c3881b9b113bc7b33e9fd78b8 \
456462
--hash=sha256:a9a52172be0b5aae932bef82a79ec0a0ce87288c7d132946d645eba03f0ad8a8 \
457463
--hash=sha256:aa31fdcc33fef9eb2552cbcbfee7773d5a6792c137b359e82879c101e98584c5 \
464+
--hash=sha256:acae32e13a4153809db37405f5eba5bac5fbe2e2ba61ab227926a22901051c0a \
458465
--hash=sha256:b014c23646a467558be7da3d6b9fa409b2c567d2110599b7cf9a0c5992b3b471 \
459466
--hash=sha256:b21bb4c09ffabfa0e85e3a6b623e19b80e7acd709b9f91452b8297ace2a8ab00 \
460467
--hash=sha256:b5901a312f4d14c59918c221323068fad0540e34324925c8475263841dbdfe68 \
@@ -469,21 +476,16 @@ wrapt==1.14.1 \
469476
--hash=sha256:dee60e1de1898bde3b238f18340eec6148986da0455d8ba7848d50470a7a32fb \
470477
--hash=sha256:e2f83e18fe2f4c9e7db597e988f72712c0c3676d337d8b101f6758107c42425b \
471478
--hash=sha256:e3fb1677c720409d5f671e39bac6c9e0e422584e5f518bfd50aa4cbbea02433f \
479+
--hash=sha256:ecee4132c6cd2ce5308e21672015ddfed1ff975ad0ac8d27168ea82e71413f55 \
472480
--hash=sha256:ee2b1b1769f6707a8a445162ea16dddf74285c3964f605877a20e38545c3c462 \
473481
--hash=sha256:ee6acae74a2b91865910eef5e7de37dc6895ad96fa23603d1d27ea69df545015 \
474482
--hash=sha256:ef3f72c9666bba2bab70d2a8b79f2c6d2c1a42a7f7e2b0ec83bb2f9e383950af
475483
# via astroid
476484
yamllint==1.28.0 \
477485
--hash=sha256:89bb5b5ac33b1ade059743cf227de73daa34d5e5a474b06a5e17fc16583b0cf2 \
478486
--hash=sha256:9e3d8ddd16d0583214c5fdffe806c9344086721f107435f68bad990e5a88826b
479-
# via -r requirements.in
487+
# via -r /Users/groodt/work/rules_python/examples/bzlmod/requirements.in
480488
zipp==3.17.0 \
481489
--hash=sha256:0e923e726174922dce09c53c59ad483ff7bbb8e572e00c7f7c46b88556409f31 \
482490
--hash=sha256:84e64a1c28cf7e91ed2078bb8cc8c259cb19b76942096c8d7b84947690cabaf0
483491
# via importlib-metadata
484-
485-
# The following packages are considered to be unsafe in a requirements file:
486-
setuptools==65.6.3 \
487-
--hash=sha256:57f6f22bde4e042978bcd50176fdb381d7c21a9efa4041202288d3737a0c6a54 \
488-
--hash=sha256:a7620757bf984b58deaf32fc8a4577a9bbc0850cf92c20e1ce41c38c19e5fb75
489-
# via yamllint

python/private/bzlmod/pin.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
uv_path=$1
6+
shift
7+
8+
$uv_path pip compile \
9+
"$@"

python/private/bzlmod/pip.bzl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"pip module extension for use with bzlmod"
1616

17+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
1719
load("@bazel_features//:features.bzl", "bazel_features")
1820
load("@pythons_hub//:interpreters.bzl", "DEFAULT_PYTHON_VERSION", "INTERPRETER_LABELS")
1921
load(
@@ -323,6 +325,52 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides, group_map, s
323325

324326
return is_hub_reproducible
325327

328+
# TODO(groodt): Add more platforms
329+
_UV_DEPS = {
330+
"linux_aarch64": (
331+
"https://files.pythonhosted.org/packages/00/82/3d0acad7ebd4098aaa23f163b492b47fd9321b2681c55918fe5f18856513/uv-0.2.12-py3-none-manylinux_2_28_aarch64.whl",
332+
"05d809516b651997a151585c9bbd150d888e71976a734781a3dde95430c1cab2"
333+
),
334+
"linux_x86_64": (
335+
"https://files.pythonhosted.org/packages/d9/85/e608bfe78772afa3f9807a074203982131ff9c12e279bb3bc502e14d51ab/uv-0.2.12-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
336+
"78d5329094de1f6b503bffe00abcdf1aaa7b3e4aa2aa373e128d7faf39b98de9",
337+
),
338+
"osx_x86_64": (
339+
"https://files.pythonhosted.org/packages/ff/f5/df24800e195f10e41aeb4a89f38488aca76c22d0f87c3eb8bf309f940aa3/uv-0.2.12-py3-none-macosx_10_12_x86_64.whl",
340+
"85d2b9649c14014d6c54ecfb5d36f57e5c0e890957078ed4937e03569141d99b",
341+
),
342+
}
343+
344+
# Repository to retrieve tools for pinning dependencies.
345+
# We currently use uv as a dependency for the pinning tool.
346+
def _fetch_pin_dependencies(python_version, platform):
347+
url, sha256 = _UV_DEPS.get(platform)
348+
py_version_label = "cp" + version_label(python_version)
349+
350+
name = "{py_version_label}_{platform}_uv".format(
351+
py_version_label = py_version_label,
352+
platform = platform,
353+
)
354+
maybe(
355+
http_archive,
356+
name = name,
357+
build_file_content = """
358+
filegroup(
359+
name = "uv",
360+
srcs = glob(["*/scripts/uv"]),
361+
visibility = ["//visibility:public"],
362+
)
363+
""",
364+
sha256 = sha256,
365+
type = "zip",
366+
urls = [url],
367+
)
368+
369+
return "@{py_version_label}_{platform}_uv//:uv".format(
370+
py_version_label = py_version_label,
371+
platform = platform,
372+
)
373+
326374
def _pip_impl(module_ctx):
327375
"""Implementation of a class tag that creates the pip hub and corresponding pip spoke whl repositories.
328376
@@ -472,6 +520,10 @@ def _pip_impl(module_ctx):
472520
is_hub_reproducible = _create_whl_repos(module_ctx, pip_attr, hub_whl_map, whl_overrides, hub_group_map, simpleapi_cache)
473521
is_extension_reproducible = is_extension_reproducible and is_hub_reproducible
474522

523+
# Register repository for pin tooling
524+
repository_platform = host_platform(module_ctx.os)
525+
pin_tool_label = _fetch_pin_dependencies(_major_minor_version(DEFAULT_PYTHON_VERSION), repository_platform)
526+
475527
for hub_name, whl_map in hub_whl_map.items():
476528
pip_repository(
477529
name = hub_name,
@@ -482,6 +534,7 @@ def _pip_impl(module_ctx):
482534
},
483535
default_version = _major_minor_version(DEFAULT_PYTHON_VERSION),
484536
groups = hub_group_map.get(hub_name),
537+
pin_tool_label = pin_tool_label,
485538
)
486539

487540
if bazel_features.external_deps.extension_metadata_has_reproducible:

python/private/bzlmod/pip_repository.bzl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ package(default_visibility = ["//visibility:public"])
2626
2727
# Ensure the `requirements.bzl` source can be accessed by stardoc, since users load() from it
2828
exports_files(["requirements.bzl"])
29+
30+
sh_binary(
31+
name = "pin",
32+
srcs = ["pin.sh"],
33+
data = [
34+
"{pin_tool_label}",
35+
],
36+
args = [
37+
"$(location {pin_tool_label})",
38+
],
39+
visibility = ["//visibility:public"],
40+
)
2941
"""
3042

3143
def _pip_repository_impl(rctx):
@@ -48,7 +60,10 @@ def _pip_repository_impl(rctx):
4860
# `requirement`, et al. macros.
4961
macro_tmpl = "@@{name}//{{}}:{{}}".format(name = rctx.attr.name)
5062

51-
rctx.file("BUILD.bazel", _BUILD_FILE_CONTENTS)
63+
rctx.template("pin.sh", rctx.attr._pin)
64+
rctx.file("BUILD.bazel", _BUILD_FILE_CONTENTS.format(
65+
pin_tool_label = rctx.attr.pin_tool_label,
66+
))
5267
rctx.template("requirements.bzl", rctx.attr._template, substitutions = {
5368
"%%ALL_DATA_REQUIREMENTS%%": render.list([
5469
macro_tmpl.format(p, "data")
@@ -91,6 +106,10 @@ in the pip.parse tag class.
91106
"_template": attr.label(
92107
default = ":requirements.bzl.tmpl",
93108
),
109+
"_pin": attr.label(default = ":pin.sh"),
110+
"pin_tool_label": attr.string(
111+
mandatory = True,
112+
),
94113
}
95114

96115
pip_repository = repository_rule(

0 commit comments

Comments
 (0)