Skip to content

Commit f3c01b7

Browse files
committed
Get sdist builds going with python3 -m build
1 parent f08a43d commit f3c01b7

File tree

8 files changed

+151
-16
lines changed

8 files changed

+151
-16
lines changed

requirements.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
setuptools
2+
build
13
django~=4.2.7
24
colorama~=0.4.0
35
click
@@ -8,4 +10,4 @@ snakesay
810
ftfy==6.2.0
911
neptune==1.10.2
1012
six
11-
bazel-runfiles
13+
bazel-runfiles

requirements.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ bravado==11.0.3 \
3838
bravado-core==6.1.1 \
3939
--hash=sha256:8cf1f7bbac2f7c696d37e970253938b5be4ddec92c8d5e64400b17469c3714b4
4040
# via bravado
41+
build==1.3.0 \
42+
--hash=sha256:698edd0ea270bde950f53aed21f3a0135672206f3911e0176261a31e0e07b397 \
43+
--hash=sha256:7145f0b5061ba90a1500d60bd1b13ca0a8a4cebdd0cc16ed8adf1c0e739f43b4
44+
# via -r requirements.in
4145
certifi==2024.7.4 \
4246
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
4347
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
@@ -245,6 +249,10 @@ idna==3.7 \
245249
# via
246250
# jsonschema
247251
# requests
252+
importlib-metadata==8.7.0 \
253+
--hash=sha256:d13b81ad223b890aa16c5471f2ac3056cf76c5f10f82d6f9292f0b415f389000 \
254+
--hash=sha256:e5dd1551894c77868a30651cef00984d50e1002d06942a7101d34870c5f02afd
255+
# via build
248256
iniconfig==2.0.0 \
249257
--hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \
250258
--hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374
@@ -393,6 +401,7 @@ packaging==24.0 \
393401
--hash=sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5 \
394402
--hash=sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9
395403
# via
404+
# build
396405
# neptune
397406
# pytest
398407
pandas==2.2.2 \
@@ -523,6 +532,10 @@ pyjwt==2.8.0 \
523532
--hash=sha256:57e28d156e3d5c10088e0c68abb90bfac3df82b40a71bd0daa20c65ccd5c23de \
524533
--hash=sha256:59127c392cc44c2da5bb3192169a91f429924e17aff6534d70fdc02ab3e04320
525534
# via neptune
535+
pyproject-hooks==1.2.0 \
536+
--hash=sha256:1e859bd5c40fae9448642dd871adf459e5e2084186e8d2c2a79a824c970da1f8 \
537+
--hash=sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913
538+
# via build
526539
pytest==8.1.1 \
527540
--hash=sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7 \
528541
--hash=sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044
@@ -864,7 +877,9 @@ swagger-spec-validator==3.0.3 \
864877
tomli==2.0.1 \
865878
--hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
866879
--hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f
867-
# via pytest
880+
# via
881+
# build
882+
# pytest
868883
types-python-dateutil==2.9.0.20240316 \
869884
--hash=sha256:5d2f2e240b86905e40944dd787db6da9263f0deabef1076ddaed797351ec0202 \
870885
--hash=sha256:6b8cb66d960771ce5ff974e9dd45e38facb81718cc1e208b10b1baccbfdbee3b
@@ -904,3 +919,13 @@ websocket-client==1.8.0 \
904919
--hash=sha256:17b44cc997f5c498e809b22cdf2d9c7a9e71c02c8cc2b6c56e7c2d1239bfa526 \
905920
--hash=sha256:3239df9f44da632f96012472805d40a23281a991027ce11d2f45a6f24ac4c3da
906921
# via neptune
922+
zipp==3.23.0 \
923+
--hash=sha256:071652d6115ed432f5ce1d34c336c0adfd6a884660d1e9712a256d3d3bd4b14e \
924+
--hash=sha256:a07157588a12518c9d4034df3fbbee09c814741a33ff63c05fa29d26a2404166
925+
# via importlib-metadata
926+
927+
# The following packages are considered to be unsafe in a requirements file:
928+
setuptools==80.9.0 \
929+
--hash=sha256:062d34222ad13e0cc312a4c02d73f059e86a4acbfbdea8f8f76b28c99f306922 \
930+
--hash=sha256:f36b47402ecde768dbfafc46e8e4207b4360c654f1f3bb84475f0a28628fb19c
931+
# via -r requirements.in

uv.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

uv/private/extension.bzl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,13 @@ def _sbuild_repos(module_ctx, lock_specs, override_specs):
373373
sdist_build(
374374
name = name,
375375
src = "@" + _sdist_repo_name(package) + "//file",
376+
# FIXME: Add support for build deps and annotative build deps
376377
deps = [
377378
"@" + _venv_target(hub_name, venv_name, package["name"])
378-
for package in package.get("dependencies", [])
379+
for package in package.get("build-dependencies", [
380+
{"name": "setuptools"},
381+
{"name": "build"}
382+
])
379383
],
380384
)
381385

@@ -448,7 +452,7 @@ def _collect_entrypoints(module_ctx, lock_specs):
448452
res = module_ctx.execute(
449453
[
450454
"tar", # FIXME: Use a hermetic tar here somehow?
451-
"-xOzf",
455+
"-xzOif",
452456
file,
453457
"*.dist-info/entry_points.txt",
454458
],
@@ -460,6 +464,11 @@ def _collect_entrypoints(module_ctx, lock_specs):
460464
entrypoints[package["name"]][normalize_name(name)] = entrypoint
461465

462466
packages_to_collect.pop(package["name"])
467+
else:
468+
fail("Unable to analyze wheel for %s\n%s" % (package["name"], res.stderr))
469+
470+
if packages_to_collect:
471+
fail("Unable to identify entrypoints for %r", packages_to_collect.keys())
463472

464473
return entrypoints
465474

@@ -702,14 +711,14 @@ def _uv_impl(module_ctx):
702711
lock_specs = _parse_locks(module_ctx, venv_specs)
703712

704713
override_specs = _parse_overrides(module_ctx, venv_specs)
705-
print(override_specs)
706714
# Roll through all the configured wheels, collect & validate the unique
707715
# platform configurations so that we can go create an appropriate power set
708716
# of conditions.
709717
configurations = _collect_configurations(module_ctx, lock_specs)
710718

711719
# Collect declared entrypoints for packages
712720
entrypoints = _collect_entrypoints(module_ctx, lock_specs)
721+
print(entrypoints)
713722

714723
# Roll through and create sdist and whl repos for all configured sources
715724
# Note that these have no deps to this point

uv/private/sdist_build/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ bzl_library(
2020
srcs = ["repository.bzl"],
2121
deps = [":rule"],
2222
)
23+
24+
exports_files(["build_helper.py"])
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
3+
from argparse import ArgumentParser
4+
from shutil import copytree
5+
import sys
6+
from tempfile import mkdtemp
7+
from os import chdir, path
8+
from runpy import run_module
9+
10+
# Under Bazel, the source dir of a sdist to build is immutable. `build` and
11+
# other tools however are constitutionally incapable of not writing to the
12+
# source tree.
13+
#
14+
# As a workaround, we use this launcher which exists to do two things.
15+
# - It makes a writable tempdir with a copy of the source tree
16+
# - It punts to `build` targeting the tempdir
17+
18+
PARSER = ArgumentParser()
19+
PARSER.add_argument("srcdir")
20+
PARSER.add_argument("outdir")
21+
opts, args = PARSER.parse_known_args()
22+
23+
t = mkdtemp()
24+
copytree(opts.srcdir, t, dirs_exist_ok=True)
25+
outdir = path.abspath(opts.outdir)
26+
sys.argv.pop()
27+
sys.argv.pop()
28+
sys.argv.extend([
29+
"--wheel",
30+
"--no-isolation",
31+
"--outdir", outdir,
32+
t,
33+
])
34+
run_module("build")

uv/private/sdist_build/repository.bzl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ sibling `rule.bzl` file for the implementation of `sdist_build`.
99
def _sdist_build_impl(repository_ctx):
1010
repository_ctx.file("BUILD.bazel", content = """
1111
load("@aspect_rules_py//uv/private/sdist_build:rule.bzl", "sdist_build")
12+
load("@aspect_rules_py//py/unstable:defs.bzl", "py_venv")
1213
14+
py_venv(
15+
name = "build_venv",
16+
deps = {deps},
17+
)
18+
1319
sdist_build(
1420
name = "whl",
1521
src = "{src}",
16-
deps = {deps},
22+
venv = ":build_venv",
1723
visibility = ["//visibility:public"],
1824
)
1925
""".format(

uv/private/sdist_build/rule.bzl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Actually building sdists.
44

55
# buildifier: disable=bzl-visibility
66
load("//py/private/toolchain:types.bzl", "PY_TOOLCHAIN")
7+
load("//py/private/py_venv:py_venv.bzl", "VirtualenvInfo")
78

89
TAR_TOOLCHAIN = "@tar.bzl//tar/toolchain:type"
910
UV_TOOLCHAIN = "@multitool//tools/uv:toolchain_type"
@@ -42,6 +43,9 @@ def _sdist_build(ctx):
4243
"build",
4344
)
4445

46+
venv = ctx.attr.venv
47+
print(venv[VirtualenvInfo], venv[DefaultInfo])
48+
4549
# Options here:
4650
# 1. Use `uv build` and provide it the path for our Python toolchain
4751
# 2. Use the Python toolchain and a downloaded build.
@@ -50,21 +54,17 @@ def _sdist_build(ctx):
5054
#
5155
# We're going with #1 for now.
5256
ctx.actions.run(
53-
executable = uv.executable,
57+
executable = venv[VirtualenvInfo].home.path + "/bin/python3",
5458
arguments = [
55-
"build",
56-
"--wheel",
57-
"--offline",
58-
"--no-cache",
59-
"--out-dir",
59+
ctx.file._helper.path,
6060
wheel_dir.path,
61-
"--python",
62-
py_toolchain.interpreter.path,
6361
unpacked_sdist.path,
6462
],
6563
inputs = [
6664
unpacked_sdist,
67-
] + py_toolchain.files.to_list(),
65+
venv[VirtualenvInfo].home,
66+
ctx.file._helper,
67+
] + py_toolchain.files.to_list() + ctx.attr.venv[DefaultInfo].files.to_list(),
6868
outputs = [
6969
wheel_dir,
7070
],
@@ -88,7 +88,8 @@ specified Python dependencies under the configured Python toochain.
8888
""",
8989
attrs = {
9090
"src": attr.label(doc = ""),
91-
"deps": attr.label_list(doc = ""),
91+
"venv": attr.label(doc = ""),
92+
"_helper": attr.label(allow_single_file = True, default = Label(":build_helper.py"))
9293
},
9394
toolchains = [
9495
# TODO: Py toolchain needs to be in the `host` configuration, not the

0 commit comments

Comments
 (0)