Skip to content

Commit 163f5c0

Browse files
committed
wip: it seems that due to circular dependencies I cannot auto-detect the values of the extra aliases field to be passed to the hub repo, because I have no visibility into what annotatinos are passed to what hubs, because of how the code is structured today. Lets just ask the user to specify those explicitly
1 parent 16c1e47 commit 163f5c0

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

python/private/pypi/extension.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def _create_whl_repos(
6868
pip_attr,
6969
whl_overrides,
7070
simpleapi_cache,
71+
whl_mods,
7172
available_interpreters = INTERPRETER_LABELS,
7273
simpleapi_download = simpleapi_download):
7374
"""create all of the whl repositories
@@ -104,6 +105,7 @@ def _create_whl_repos(
104105
# containers to aggregate outputs from this function
105106
whl_map = {}
106107
exposed_packages = {}
108+
extra_aliases = {}
107109
whl_libraries = {}
108110

109111
# if we do not have the python_interpreter set in the attributes
@@ -138,6 +140,14 @@ def _create_whl_repos(
138140
for mod, whl_name in pip_attr.whl_modifications.items():
139141
whl_modifications[normalize_name(whl_name)] = mod
140142

143+
annotation = json.decode(module_ctx.read(mod))
144+
if annotation.additive_build_content:
145+
extra_aliases.setdefault(whl_name, {}).update({
146+
line.partition("name = ")[-1].strip("\"',"): True
147+
for line in annotation.build_content.split("\n")
148+
if line.lstrip().beginswith("name = ")
149+
})
150+
141151
if pip_attr.experimental_requirement_cycles:
142152
requirement_cycles = {
143153
name: [normalize_name(whl_name) for whl_name in whls]
@@ -349,6 +359,7 @@ def _create_whl_repos(
349359
is_reproducible = is_reproducible,
350360
whl_map = whl_map,
351361
exposed_packages = exposed_packages,
362+
extra_aliases = extra_aliases,
352363
whl_libraries = whl_libraries,
353364
)
354365

@@ -433,6 +444,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
433444
hub_whl_map = {}
434445
hub_group_map = {}
435446
exposed_packages = {}
447+
extra_aliases = {}
436448
whl_libraries = {}
437449

438450
is_reproducible = True
@@ -477,11 +489,15 @@ You cannot use both the additive_build_content and additive_build_content_file a
477489
pip_attr = pip_attr,
478490
simpleapi_cache = simpleapi_cache,
479491
whl_overrides = whl_overrides,
492+
whl_mods = whl_mods,
480493
**kwargs
481494
)
482495
hub_whl_map.setdefault(hub_name, {})
483496
for key, settings in out.whl_map.items():
484497
hub_whl_map[hub_name].setdefault(key, []).extend(settings)
498+
extra_aliases.setdefault(hub_name, {})
499+
for whl_name, extra_aliases in out.extra_aliases.items():
500+
extra_aliases[hub_name].setdefault(whl_name, {}).update(extra_aliases)
485501
exposed_packages.setdefault(hub_name, {}).update(out.exposed_packages)
486502
whl_libraries.update(out.whl_libraries)
487503
is_reproducible = is_reproducible and out.is_reproducible
@@ -510,6 +526,13 @@ You cannot use both the additive_build_content and additive_build_content_file a
510526
for hub_name, group_map in sorted(hub_group_map.items())
511527
},
512528
exposed_packages = {k: sorted(v) for k, v in sorted(exposed_packages.items())},
529+
extra_aliases = {
530+
hub_name: {
531+
whl_name: sorted(aliases)
532+
for whl_name, aliases in extra_whl_aliases.items()
533+
}
534+
for hub_name, extra_whl_aliases in extra_aliases.items()
535+
},
513536
whl_libraries = dict(sorted(whl_libraries.items())),
514537
is_reproducible = is_reproducible,
515538
)

tests/pypi/extension/extension_tests.bzl

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,37 @@ def _parse_modules(env, **kwargs):
6161
attrs = dict(
6262
is_reproducible = subjects.bool,
6363
exposed_packages = subjects.dict,
64+
extra_aliases = subjects.dict,
6465
hub_group_map = subjects.dict,
6566
hub_whl_map = subjects.dict,
6667
whl_libraries = subjects.dict,
6768
whl_mods = subjects.dict,
6869
),
6970
)
7071

72+
def _whl_mods(
73+
*,
74+
whl_name,
75+
hub_name,
76+
additive_build_content = None,
77+
additive_build_content_file = None,
78+
copy_executables = {},
79+
copy_files = {},
80+
data = [],
81+
data_exclude_glob = [],
82+
srcs_exclude_glob = []):
83+
return struct(
84+
additive_build_content = additive_build_content,
85+
additive_build_content_file = additive_build_content_file,
86+
copy_executables = copy_executables,
87+
copy_files = copy_files,
88+
data = data,
89+
data_exclude_glob = data_exclude_glob,
90+
hub_name = hub_name,
91+
srcs_exclude_glob = srcs_exclude_glob,
92+
whl_name = whl_name,
93+
)
94+
7195
def _parse(
7296
*,
7397
hub_name,
@@ -164,11 +188,25 @@ def _test_simple_with_whl_mods(env):
164188
module_ctx = _mock_mctx(
165189
_mod(
166190
name = "rules_python",
191+
whl_mods = [
192+
_whl_mods(
193+
additive_build_content = """\
194+
filegroup(
195+
name = "foo",
196+
srcs = ["all"],
197+
)""",
198+
hub_name = "whl_mods_hub",
199+
whl_name = "simple",
200+
),
201+
],
167202
parse = [
168203
_parse(
169204
hub_name = "pypi",
170205
python_version = "3.15",
171206
requirements_lock = "requirements.txt",
207+
whl_modifications = {
208+
"@whl_mods_hub//:simple.json": "simple",
209+
},
172210
),
173211
],
174212
),
@@ -182,6 +220,11 @@ def _test_simple_with_whl_mods(env):
182220

183221
pypi.is_reproducible().equals(True)
184222
pypi.exposed_packages().contains_exactly({"pypi": []})
223+
pypi.extra_aliases().contains_exactly({
224+
"pypi": {
225+
"simple": "foo",
226+
}
227+
})
185228
pypi.hub_group_map().contains_exactly({"pypi": {}})
186229
pypi.hub_whl_map().contains_exactly({"pypi": {
187230
"simple": [
@@ -196,13 +239,25 @@ def _test_simple_with_whl_mods(env):
196239
}})
197240
pypi.whl_libraries().contains_exactly({
198241
"pypi_315_simple": {
242+
"annotation": "@whl_mods_hub//:simple.json",
199243
"dep_template": "@pypi//{name}:{target}",
200244
"python_interpreter_target": "unit_test_interpreter_target",
201245
"repo": "pypi_315",
202246
"requirement": "simple==0.0.1 --hash=sha256:deadbeef",
203247
},
204248
})
205-
pypi.whl_mods().contains_exactly({})
249+
pypi.whl_mods().contains_exactly({
250+
"whl_mods_hub": {
251+
"simple": struct(
252+
build_content = "filegroup(\n name = \"foo\",\n srcs = [\"all\"],\n)",
253+
copy_executables = {},
254+
copy_files = {},
255+
data = [],
256+
data_exclude_glob = [],
257+
srcs_exclude_glob = [],
258+
),
259+
},
260+
})
206261

207262
_tests.append(_test_simple_with_whl_mods)
208263

0 commit comments

Comments
 (0)