Skip to content

Commit dab3d0f

Browse files
committed
test: finish the test with get_index_url
1 parent dfb24be commit dab3d0f

File tree

3 files changed

+125
-15
lines changed

3 files changed

+125
-15
lines changed

examples/bzlmod/MODULE.bazel.lock

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

python/private/pypi/extension.bzl

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,35 @@ def _whl_mods_impl(whl_mods_dict):
6262
whl_mods = whl_mods,
6363
)
6464

65-
def _create_whl_repos(module_ctx, *, pip_attr, whl_map, whl_overrides, group_map, simpleapi_cache, exposed_packages, whl_libraries, available_interpreters):
65+
def _create_whl_repos(
66+
module_ctx,
67+
*,
68+
pip_attr,
69+
whl_map,
70+
whl_overrides,
71+
group_map,
72+
simpleapi_cache,
73+
exposed_packages,
74+
whl_libraries,
75+
available_interpreters = INTERPRETER_LABELS,
76+
simpleapi_download = simpleapi_download):
77+
"""create all of the whl repositories
78+
79+
Args:
80+
module_ctx: TODO
81+
pip_attr: TODO
82+
whl_map: TODO
83+
whl_overrides: TODO
84+
group_map: TODO
85+
simpleapi_cache: TODO
86+
exposed_packages: TODO
87+
whl_libraries: TODO
88+
simpleapi_download: Used for testing overrides
89+
available_interpreters: {type}`dict[str, Label]` The dictionary of available
90+
interpreters that have been registered using the `python` bzlmod extension.
91+
The keys are in the form `python_{snake_case_version}_host`. This is to be
92+
used during the `repository_rule` and must be always compatible with the host.
93+
"""
6694
logger = repo_utils.logger(module_ctx, "pypi:create_whl_repos")
6795
python_interpreter_target = pip_attr.python_interpreter_target
6896
is_hub_reproducible = True
@@ -321,16 +349,13 @@ def _create_whl_repos(module_ctx, *, pip_attr, whl_map, whl_overrides, group_map
321349

322350
return is_hub_reproducible
323351

324-
def parse_modules(module_ctx, _fail = fail, available_interpreters = INTERPRETER_LABELS):
352+
def parse_modules(module_ctx, _fail = fail, **kwargs):
325353
"""Implementation of parsing the tag classes for the extension and return a struct for registering repositories.
326354
327355
Args:
328356
module_ctx: {type}`module_ctx` module context.
329357
_fail: {type}`function` the failure function, mainly for testing.
330-
available_interpreters: {type}`dict[str, Label]` The dictionary of available
331-
interpreters that have been registered using the `python` bzlmod extension.
332-
The keys are in the form `python_{snake_case_version}_host`. This is to be
333-
used during the `repository_rule` and must be always compatible with the host.
358+
**kwargs: Extra arguments passed to the layers below.
334359
335360
Returns:
336361
A struct with the following attributes:
@@ -453,15 +478,15 @@ You cannot use both the additive_build_content and additive_build_content_file a
453478
whl_map = hub_whl_map,
454479
whl_overrides = whl_overrides,
455480
whl_libraries = whl_libraries,
456-
available_interpreters = available_interpreters,
481+
**kwargs
457482
)
458483
is_reproducible = is_reproducible and is_hub_reproducible
459484

460485
return struct(
461486
whl_mods = whl_mods,
462487
hub_whl_map = hub_whl_map,
463488
hub_group_map = hub_group_map,
464-
exposed_packages = exposed_packages,
489+
exposed_packages = {k: sorted(v) for k, v in exposed_packages.items()},
465490
whl_libraries = whl_libraries,
466491
is_reproducible = is_reproducible,
467492
)
@@ -550,7 +575,7 @@ def _pip_impl(module_ctx):
550575
key: json.encode(value)
551576
for key, value in whl_map.items()
552577
},
553-
packages = sorted(mods.exposed_packages.get(hub_name, {})),
578+
packages = mods.exposed_packages.get(hub_name, []),
554579
groups = mods.hub_group_map.get(hub_name),
555580
)
556581

tests/pypi/extension/extension_tests.bzl

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _mock_mctx(*modules, environ = {}, read = None):
2727
name = "unittest",
2828
arch = "exotic",
2929
),
30-
read = read or (lambda _: ""),
30+
read = read or (lambda _: "simple==0.0.1 --hash=sha256:deadbeef"),
3131
modules = [
3232
struct(
3333
name = modules[0].name,
@@ -75,18 +75,18 @@ def _parse(
7575
experimental_requirement_cycles = {},
7676
experimental_target_platforms = [],
7777
extra_pip_args = [],
78-
isolated = False,
78+
isolated = True,
7979
netrc = None,
8080
pip_data_exclude = None,
8181
python_interpreter = None,
8282
python_interpreter_target = None,
83-
quiet = False,
83+
quiet = True,
8484
requirements_by_platform = {},
8585
requirements_darwin = None,
8686
requirements_linux = None,
8787
requirements_lock = None,
8888
requirements_windows = None,
89-
timeout = 42,
89+
timeout = 600,
9090
whl_modifications = {},
9191
**kwargs):
9292
return struct(
@@ -115,6 +115,10 @@ def _parse(
115115
requirements_windows = requirements_windows,
116116
timeout = timeout,
117117
whl_modifications = whl_modifications,
118+
# The following are covered by other unit tests
119+
experimental_extra_index_urls = [],
120+
parallel_download = False,
121+
experimental_index_url_overrides = {},
118122
**kwargs
119123
)
120124

@@ -147,6 +151,87 @@ def _test_simple(env):
147151

148152
_tests.append(_test_simple)
149153

154+
def _test_simple_get_index(env):
155+
got_simpleapi_download_args = []
156+
got_simpleapi_download_kwargs = {}
157+
158+
def mocksimpleapi_download(*args, **kwargs):
159+
got_simpleapi_download_args.extend(args)
160+
got_simpleapi_download_kwargs.update(kwargs)
161+
return {
162+
"simple": struct(
163+
whls = {},
164+
sdists = {
165+
"deadbeef": struct(
166+
yanked = False,
167+
filename = "simple-0.0.1.tar.gz",
168+
sha256 = "deadbeef",
169+
url = "example.org",
170+
),
171+
},
172+
),
173+
}
174+
175+
pypi = _parse_modules(
176+
env,
177+
module_ctx = _mock_mctx(
178+
_mod(
179+
name = "rules_python",
180+
parse = [
181+
_parse(
182+
hub_name = "pypi",
183+
python_version = "3.15",
184+
requirements_lock = "requirements.txt",
185+
experimental_index_url = "pypi.org",
186+
),
187+
],
188+
),
189+
),
190+
available_interpreters = {
191+
"python_3_15_host": "unit_test_interpreter_target",
192+
},
193+
simpleapi_download = mocksimpleapi_download,
194+
)
195+
196+
pypi.is_reproducible().equals(False)
197+
pypi.exposed_packages().contains_exactly({"pypi": ["simple"]})
198+
pypi.hub_group_map().contains_exactly({})
199+
pypi.hub_whl_map().contains_exactly({"pypi": {
200+
"simple": [
201+
struct(
202+
config_setting = "//_config:is_python_3.15",
203+
filename = "simple-0.0.1.tar.gz",
204+
repo = "pypi_315_simple_sdist_deadbeef",
205+
target_platforms = None,
206+
version = "3.15",
207+
),
208+
],
209+
}})
210+
pypi.whl_libraries().contains_exactly({
211+
"pypi_315_simple_sdist_deadbeef": {
212+
"dep_template": "@pypi//{name}:{target}",
213+
"experimental_target_platforms": [
214+
"cp315_linux_aarch64",
215+
"cp315_linux_arm",
216+
"cp315_linux_ppc",
217+
"cp315_linux_s390x",
218+
"cp315_linux_x86_64",
219+
"cp315_osx_aarch64",
220+
"cp315_osx_x86_64",
221+
"cp315_windows_x86_64",
222+
],
223+
"filename": "simple-0.0.1.tar.gz",
224+
"python_interpreter_target": "unit_test_interpreter_target",
225+
"repo": "pypi_315",
226+
"requirement": "simple==0.0.1",
227+
"sha256": "deadbeef",
228+
"urls": ["example.org"],
229+
},
230+
})
231+
pypi.whl_mods().contains_exactly({})
232+
233+
_tests.append(_test_simple_get_index)
234+
150235
def extension_test_suite(name):
151236
"""Create the test suite.
152237

0 commit comments

Comments
 (0)