Skip to content

Commit 8935418

Browse files
committed
fix: correctly aggregate the whl results from multiple req files
1 parent dce2981 commit 8935418

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

python/private/pypi/parse_requirements.bzl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _package_srcs(
223223
env_marker_target_platforms,
224224
extract_url_srcs):
225225
"""A function to return sources for a particular package."""
226-
srcs = []
226+
srcs = {}
227227
for r in sorted(reqs.values(), key = lambda r: r.requirement_line):
228228
whls, sdist = _add_dists(
229229
requirement = r,
@@ -249,21 +249,31 @@ def _package_srcs(
249249
)]
250250
req_line = r.srcs.requirement_line
251251

252+
extra_pip_args = tuple(r.extra_pip_args)
252253
for dist in all_dists:
253-
srcs.append(
254+
key = (
255+
dist.filename,
256+
req_line,
257+
extra_pip_args,
258+
)
259+
entry = srcs.setdefault(
260+
key,
254261
struct(
255262
distribution = name,
256263
extra_pip_args = r.extra_pip_args,
257264
requirement_line = req_line,
258-
target_platforms = target_platforms,
265+
target_platforms = [],
259266
filename = dist.filename,
260267
sha256 = dist.sha256,
261268
url = dist.url,
262269
yanked = dist.yanked,
263270
),
264271
)
272+
for p in target_platforms:
273+
if p not in entry.target_platforms:
274+
entry.target_platforms.append(p)
265275

266-
return srcs
276+
return srcs.values()
267277

268278
def select_requirement(requirements, *, platform):
269279
"""A simple function to get a requirement for a particular platform.

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ foo==0.0.4 @ https://example.org/foo-0.0.4.whl
6767
foo==0.0.5 @ https://example.org/foo-0.0.5.whl --hash=sha256:deadbeef
6868
""",
6969
"requirements_osx": """\
70-
foo==0.0.3 --hash=sha256:deadbaaf
70+
foo==0.0.3 --hash=sha256:deadbaaf --hash=sha256:deadb11f
7171
""",
7272
"requirements_osx_download_only": """\
7373
--platform=macosx_10_9_arm64
@@ -515,6 +515,68 @@ def _test_git_sources(env):
515515

516516
_tests.append(_test_git_sources)
517517

518+
def _test_overlapping_shas_with_index_results(env):
519+
got = parse_requirements(
520+
ctx = _mock_ctx(),
521+
requirements_by_platform = {
522+
"requirements_linux": ["cp39_linux_x86_64"],
523+
"requirements_osx": ["cp39_osx_x86_64"],
524+
},
525+
get_index_urls = lambda _, __: {
526+
"foo": struct(
527+
sdists = {
528+
},
529+
whls = {
530+
"deadb11f": struct(
531+
url = "super2",
532+
sha256 = "deadb11f",
533+
filename = "foo-0.0.1-py3-none-macosx_14_0_x86_64.whl",
534+
yanked = False,
535+
),
536+
"deadbaaf": struct(
537+
url = "super2",
538+
sha256 = "deadbaaf",
539+
filename = "foo-0.0.1-py3-none-any.whl",
540+
yanked = False,
541+
),
542+
},
543+
),
544+
},
545+
)
546+
547+
env.expect.that_collection(got).contains_exactly([
548+
struct(
549+
name = "foo",
550+
is_exposed = True,
551+
# TODO @aignas 2025-05-25: how do we rename this?
552+
is_multiple_versions = True,
553+
srcs = [
554+
struct(
555+
distribution = "foo",
556+
extra_pip_args = [],
557+
filename = "foo-0.0.1-py3-none-any.whl",
558+
requirement_line = "foo==0.0.3",
559+
sha256 = "deadbaaf",
560+
target_platforms = ["cp39_linux_x86_64", "cp39_osx_x86_64"],
561+
url = "super2",
562+
yanked = False,
563+
),
564+
struct(
565+
distribution = "foo",
566+
extra_pip_args = [],
567+
filename = "foo-0.0.1-py3-none-macosx_14_0_x86_64.whl",
568+
requirement_line = "foo==0.0.3",
569+
sha256 = "deadb11f",
570+
target_platforms = ["cp39_osx_x86_64"],
571+
url = "super2",
572+
yanked = False,
573+
),
574+
],
575+
),
576+
])
577+
578+
_tests.append(_test_overlapping_shas_with_index_results)
579+
518580
def parse_requirements_test_suite(name):
519581
"""Create the test suite.
520582

0 commit comments

Comments
 (0)