Skip to content

Commit d2579cc

Browse files
committed
wip
1 parent 86ed8ca commit d2579cc

6 files changed

Lines changed: 46 additions & 35 deletions

File tree

python/private/pypi/hub_builder.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ def _add_whl_library(self, *, python_version, whl, repo):
332332
# extracted sources.
333333
repos_dict = self._whl_libraries
334334
deps_args = dict(repo.args)
335-
deps_args["requirement"] = requirement(deps_args["requirement"]).name
335+
# deps_args["requirement"] = requirement(deps_args["requirement"]).name
336+
336337
else:
337338
extract_args = {
338339
k: v
@@ -345,7 +346,7 @@ def _add_whl_library(self, *, python_version, whl, repo):
345346
req = requirement(extract_args["requirement"])
346347

347348
# TODO @aignas 2026-07-04: add a test
348-
extract_args["requirement"] = req.name # drop any specified extras
349+
extract_args["requirement"] = repo.args["requirement"]
349350
_add_library(
350351
self,
351352
repos_dict = self._whl_libraries,

python/private/pypi/parse_requirements.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def _package_srcs(
482482
logger.debug(lambda: "The whl dist is: {}".format(dist.filename if dist else dist))
483483

484484
if extract_url_srcs and dist:
485-
req_line = r.srcs.requirement
485+
req_line = r.srcs.requirement_line
486486
elif can_fallback or (not extract_url_srcs and dist):
487487
dist = struct(
488488
url = "",

python/private/pypi/whl_library_targets.bzl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def whl_library_targets(
121121
group_name = "",
122122
native = native,
123123
aliases = [],
124-
src_pkg = Label("//:BUILD.bazel"),
124+
src_pkg = None,
125125
rules = struct(
126126
copy_file = copy_file,
127127
py_binary = py_binary,
@@ -130,7 +130,8 @@ def whl_library_targets(
130130
venv_rewrite_shebang = venv_rewrite_shebang,
131131
env_marker_setting = env_marker_setting,
132132
create_inits = _create_inits,
133-
)):
133+
),
134+
**kwargs):
134135
"""Create all of the whl_library targets.
135136
136137
Args:
@@ -152,7 +153,12 @@ def whl_library_targets(
152153
native: {type}`native` The native struct for overriding in tests.
153154
rules: {type}`struct` A struct with references to rules for creating targets.
154155
"""
155-
src_pkg = Label(src_pkg)
156+
if src_pkg == None:
157+
src_pkg = struct(
158+
same_package_label = lambda label: ":" + label,
159+
)
160+
else:
161+
src_pkg = Label(src_pkg)
156162

157163
_config_settings(
158164
dependencies_with_markers = dependencies_with_markers,
@@ -219,7 +225,7 @@ def whl_library_targets(
219225
data = _deps(
220226
deps = dependencies,
221227
deps_conditional = deps_conditional,
222-
tmpl = dep_template.format(name = "{}", target = WHEEL_FILE_PUBLIC_LABEL),
228+
tmpl = dep_template.format(name = "{}", target = WHEEL_FILE_PUBLIC_LABEL) if dep_template else "",
223229
),
224230
visibility = impl_vis,
225231
)
@@ -228,7 +234,7 @@ def whl_library_targets(
228234
deps = [src_pkg.same_package_label(NODEPS_PY_LIBRARY_LABEL)] + _deps(
229235
deps = dependencies,
230236
deps_conditional = deps_conditional,
231-
tmpl = dep_template.format(name = "{}", target = PY_LIBRARY_PUBLIC_LABEL),
237+
tmpl = dep_template.format(name = "{}", target = PY_LIBRARY_PUBLIC_LABEL) if dep_template else "",
232238
),
233239
tags = tags,
234240
visibility = impl_vis,
@@ -292,7 +298,8 @@ def whl_library_srcs(
292298
venv_rewrite_shebang = venv_rewrite_shebang,
293299
env_marker_setting = env_marker_setting,
294300
create_inits = _create_inits,
295-
)):
301+
),
302+
**kwargs):
296303
"""Create all of the whl_library targets.
297304
298305
Args:

tests/pypi/hub_builder/hub_builder_tests.bzl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _test_simple(env):
144144
"config_load": "@pypi//:config.bzl",
145145
"dep_template": "@pypi//{name}:{target}",
146146
"python_interpreter_target": "unit_test_interpreter_target",
147-
"requirement": "simple",
147+
"requirement": "simple==0.0.1 --hash=sha256:deadbeef --hash=sha256:deadbaaf",
148148
},
149149
})
150150
pypi.extra_aliases().contains_exactly({})
@@ -153,8 +153,8 @@ _tests.append(_test_simple)
153153

154154
def _test_simple_multiple_requirements(env):
155155
sub_tests = {
156-
("osx", "aarch64"): "simple",
157-
("windows", "aarch64"): "simple",
156+
("osx", "aarch64"): "simple==0.0.2 --hash=sha256:deadb00f",
157+
("windows", "aarch64"): "simple==0.0.1 --hash=sha256:deadbeef",
158158
}
159159
for (host_os, host_arch), want_requirement in sub_tests.items():
160160
builder = hub_builder(env)
@@ -199,8 +199,8 @@ _tests.append(_test_simple_multiple_requirements)
199199

200200
def _test_simple_extras_vs_no_extras(env):
201201
sub_tests = {
202-
("osx", "aarch64"): "simple",
203-
("windows", "aarch64"): "simple",
202+
("osx", "aarch64"): "simple[foo]==0.0.1 --hash=sha256:deadbeef",
203+
("windows", "aarch64"): "simple==0.0.1 --hash=sha256:deadbeef",
204204
}
205205
for (host_os, host_arch), want_requirement in sub_tests.items():
206206
builder = hub_builder(env)
@@ -406,25 +406,25 @@ new-package==0.0.1 --hash=sha256:deadb00f2
406406
"config_load": "@pypi//:config.bzl",
407407
"dep_template": "@pypi//{name}:{target}",
408408
"python_interpreter_target": "unit_test_interpreter_target",
409-
"requirement": "old-package",
409+
"requirement": "old-package==0.0.1 --hash=sha256:deadbaaf",
410410
},
411411
"pypi_315_simple": {
412412
"config_load": "@pypi//:config.bzl",
413413
"dep_template": "@pypi//{name}:{target}",
414414
"python_interpreter_target": "unit_test_interpreter_target",
415-
"requirement": "simple",
415+
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
416416
},
417417
"pypi_316_new_package": {
418418
"config_load": "@pypi//:config.bzl",
419419
"dep_template": "@pypi//{name}:{target}",
420420
"python_interpreter_target": "unit_test_interpreter_target",
421-
"requirement": "new-package",
421+
"requirement": "new-package==0.0.1 --hash=sha256:deadb00f2",
422422
},
423423
"pypi_316_simple": {
424424
"config_load": "@pypi//:config.bzl",
425425
"dep_template": "@pypi//{name}:{target}",
426426
"python_interpreter_target": "unit_test_interpreter_target",
427-
"requirement": "simple",
427+
"requirement": "simple==0.0.2 --hash=sha256:deadb00f",
428428
},
429429
})
430430
pypi.extra_aliases().contains_exactly({})
@@ -474,7 +474,7 @@ def _test_simple_with_markers(env):
474474
"config_load": "@pypi//:config.bzl",
475475
"dep_template": "@pypi//{name}:{target}",
476476
"python_interpreter_target": "unit_test_interpreter_target",
477-
"requirement": want_requirement,
477+
"requirement": "torch==2.4.1 --hash=sha256:deadbeef",
478478
},
479479
})
480480
pypi.extra_aliases().contains_exactly({})
@@ -967,23 +967,23 @@ simple==0.0.3 \
967967
"download_only": True,
968968
"extra_pip_args": ["--platform=manylinux_2_17_x86_64", "--python-version=315", "--implementation=cp", "--abi=cp315"],
969969
"python_interpreter_target": "unit_test_interpreter_target",
970-
"requirement": "extra",
970+
"requirement": "extra==0.0.1 --hash=sha256:deadb00f",
971971
},
972972
"pypi_315_simple_linux_x86_64": {
973973
"config_load": "@pypi//:config.bzl",
974974
"dep_template": "@pypi//{name}:{target}",
975975
"download_only": True,
976976
"extra_pip_args": ["--platform=manylinux_2_17_x86_64", "--python-version=315", "--implementation=cp", "--abi=cp315"],
977977
"python_interpreter_target": "unit_test_interpreter_target",
978-
"requirement": "simple",
978+
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
979979
},
980980
"pypi_315_simple_osx_aarch64": {
981981
"config_load": "@pypi//:config.bzl",
982982
"dep_template": "@pypi//{name}:{target}",
983983
"download_only": True,
984984
"extra_pip_args": ["--platform=macosx_10_9_arm64", "--python-version=315", "--implementation=cp", "--abi=cp315"],
985985
"python_interpreter_target": "unit_test_interpreter_target",
986-
"requirement": "simple",
986+
"requirement": "simple==0.0.3 --hash=sha256:deadbaaf",
987987
},
988988
})
989989
pypi.extra_aliases().contains_exactly({})
@@ -1476,11 +1476,11 @@ optimum[onnxruntime-gpu]==1.17.1 ; sys_platform == 'linux'
14761476
},
14771477
})
14781478
pypi.whl_libraries().contains_exactly({
1479-
"pypi_315_optimum": {
1479+
"pypi_315_torch": {
14801480
"config_load": "@pypi//:config.bzl",
14811481
"dep_template": "@pypi//{name}:{target}",
14821482
"python_interpreter_target": "unit_test_interpreter_target",
1483-
"requirement": "optimum",
1483+
"requirement": "torch==2.4.1+cpu",
14841484
},
14851485
})
14861486
pypi.extra_aliases().contains_exactly({})

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _test_direct_urls_integration(env):
230230
distribution = "foo",
231231
extra_pip_args = [],
232232
filename = "package.whl",
233-
requirement_line = "foo[extra]",
233+
requirement_line = "foo[extra] @ https://some-url/package.whl",
234234
sha256 = "",
235235
target_platforms = ["linux_x86_64"],
236236
url = "https://some-url/package.whl",
@@ -648,7 +648,7 @@ def _test_optional_hash(env):
648648
struct(
649649
distribution = "bar",
650650
extra_pip_args = [],
651-
requirement_line = "bar==0.0.4",
651+
requirement_line = "bar==0.0.4 @ https://example.org/bar-0.0.4.whl",
652652
target_platforms = ["linux_x86_64"],
653653
url = "https://example.org/bar-0.0.4.whl",
654654
filename = "bar-0.0.4.whl",
@@ -666,7 +666,7 @@ def _test_optional_hash(env):
666666
struct(
667667
distribution = "foo",
668668
extra_pip_args = [],
669-
requirement_line = "foo==0.0.5",
669+
requirement_line = "foo==0.0.5 @ https://example.org/foo-0.0.5.whl --hash=sha256:deadbeef",
670670
target_platforms = ["linux_x86_64"],
671671
url = "https://example.org/foo-0.0.5.whl",
672672
filename = "foo-0.0.5.whl",
@@ -776,7 +776,7 @@ def _test_overlapping_shas_with_index_results(env):
776776
distribution = "foo",
777777
extra_pip_args = [],
778778
filename = "foo-0.0.1-py3-none-any.whl",
779-
requirement_line = "foo==0.0.3",
779+
requirement_line = "foo==0.0.3 --hash=sha256:deadbaaf --hash=sha256:5d15t",
780780
sha256 = "deadbaaf",
781781
target_platforms = ["cp39_linux_x86_64"],
782782
url = "super2",
@@ -786,7 +786,7 @@ def _test_overlapping_shas_with_index_results(env):
786786
distribution = "foo",
787787
extra_pip_args = [],
788788
filename = "foo-0.0.1-py3-none-macosx_14_0_x86_64.whl",
789-
requirement_line = "foo==0.0.3",
789+
requirement_line = "foo==0.0.3 --hash=sha256:deadbaaf --hash=sha256:deadb11f --hash=sha256:5d15t",
790790
sha256 = "deadb11f",
791791
target_platforms = ["cp39_osx_x86_64"],
792792
url = "super2",
@@ -888,7 +888,7 @@ def _test_get_index_urls_different_versions(env):
888888
distribution = "foo",
889889
extra_pip_args = [],
890890
filename = "foo-0.0.2-py3-none-any.whl",
891-
requirement_line = "foo==0.0.2",
891+
requirement_line = "foo==0.0.2 --hash=sha256:deadb11f",
892892
sha256 = "deadb11f",
893893
target_platforms = ["cp310_linux_x86_64"],
894894
url = "super2",
@@ -991,7 +991,7 @@ def _test_get_index_urls_single_py_version(env):
991991
distribution = "foo",
992992
extra_pip_args = [],
993993
filename = "foo-0.0.2-py3-none-any.whl",
994-
requirement_line = "foo==0.0.2",
994+
requirement_line = "foo==0.0.2 --hash=sha256:deadb11f",
995995
sha256 = "deadb11f",
996996
target_platforms = ["cp310_linux_x86_64"],
997997
url = "super2",
@@ -1125,7 +1125,7 @@ def _test_uv_lock_primary_source_multiple_versions(env):
11251125
struct(
11261126
distribution = "foo",
11271127
extra_pip_args = [],
1128-
requirement_line = "foo==0.0.2",
1128+
requirement_line = "foo==0.0.2 --hash=sha256:deadb11f",
11291129
target_platforms = ["linux_x86_64"],
11301130
filename = "foo-0.0.2-py3-none-any.whl",
11311131
sha256 = "deadb11f",
@@ -1580,7 +1580,7 @@ def _test_uv_lock_wheel_dedup_resolution_markers(env):
15801580
struct(
15811581
distribution = "foo",
15821582
extra_pip_args = [],
1583-
requirement_line = "foo==0.0.2",
1583+
requirement_line = "foo==0.0.2 --hash=sha256:deadb11f",
15841584
target_platforms = ["cp39_osx_aarch64"],
15851585
filename = "foo-0.0.2-cp39-cp39-macosx_11_0_arm64.whl",
15861586
sha256 = "ccc",

tests/pypi/whl_library_targets/whl_library_targets_tests.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def _test_filegroups(env):
4242
glob = glob,
4343
),
4444
rules = struct(
45+
py_library = lambda **kwargs: None,
4546
venv_rewrite_shebang = lambda **kwargs: None,
4647
),
4748
)
@@ -64,7 +65,7 @@ def _test_filegroups(env):
6465
},
6566
{
6667
"name": "whl",
67-
"srcs": [""],
68+
"srcs": [":_whl_file"],
6869
"data": [],
6970
"visibility": ["//visibility:public"],
7071
},
@@ -82,10 +83,12 @@ def _test_copy(env):
8283
copy_files = {"file_src": "file_dest"},
8384
copy_executables = {"exec_src": "exec_dest"},
8485
native = struct(
86+
filegroup = lambda **kwargs: None,
8587
glob = lambda *args, **kwargs: [],
8688
),
8789
rules = struct(
8890
copy_file = lambda **kwargs: calls.append(kwargs),
91+
py_library = lambda **kwargs: None,
8992
venv_rewrite_shebang = lambda **kwargs: None,
9093
),
9194
)
@@ -152,7 +155,7 @@ def _test_whl_and_library_deps_from_requires(env):
152155
env.expect.that_collection(filegroup_calls).contains_exactly([
153156
{
154157
"name": "whl",
155-
"srcs": ["foo-0-py3-none-any.whl"],
158+
"srcs": [":_whl_file"],
156159
"data": ["@pypi//bar:whl"] + select({
157160
":is_include_bar_baz_true": ["@pypi//bar_baz:whl"],
158161
"//conditions:default": [],

0 commit comments

Comments
 (0)