Skip to content

Commit d098305

Browse files
committed
simplify logic assuming one sdist always per version
1 parent c036d29 commit d098305

File tree

2 files changed

+44
-62
lines changed

2 files changed

+44
-62
lines changed

python/private/pypi/parse_requirements.bzl

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -207,65 +207,47 @@ def parse_requirements(
207207
# Return normalized names
208208
ret_requirements = ret.setdefault(normalize_name(whl_name), [])
209209

210-
# First, find if there's a common sdist across all platforms
211-
common_sdist = None
212-
common_sdist_hash = None
213210
all_platforms = []
211+
common_sdist = None
212+
214213
for r in sorted(reqs.values(), key = lambda r: r.requirement_line):
215-
target_platforms = env_marker_target_platforms.get(r.requirement_line, r.target_platforms)
216-
all_platforms.extend(target_platforms)
217214
whls, sdist = _add_dists(
218215
requirement = r,
219216
index_urls = index_urls.get(whl_name),
220217
logger = logger,
221218
)
222-
if sdist:
223-
if not common_sdist:
224-
common_sdist = sdist
225-
common_sdist_hash = sdist.sha256
226-
elif sdist.sha256 == common_sdist_hash:
227-
continue
228-
else:
229-
common_sdist = None
230-
break
231-
232-
# If we found a common sdist, add it as a separate entry
219+
220+
if sdist and not common_sdist:
221+
common_sdist = sdist
222+
223+
target_platforms = env_marker_target_platforms.get(r.requirement_line, r.target_platforms)
224+
all_platforms.extend(target_platforms)
225+
226+
ret_requirements.append(
227+
struct(
228+
distribution = r.distribution,
229+
srcs = r.srcs,
230+
target_platforms = sorted(target_platforms),
231+
extra_pip_args = r.extra_pip_args,
232+
whls = whls,
233+
sdist = None,
234+
is_exposed = is_exposed,
235+
),
236+
)
237+
233238
if common_sdist:
234-
# Take the first requirement's info as base since version should be same
235-
base_req = sorted(reqs.values(), key = lambda r: r.requirement_line)[0]
236239
ret_requirements.append(
237240
struct(
238-
distribution = base_req.distribution,
239-
srcs = base_req.srcs,
241+
distribution = r.distribution,
242+
srcs = r.srcs,
240243
target_platforms = sorted(all_platforms),
241-
extra_pip_args = base_req.extra_pip_args,
244+
extra_pip_args = r.extra_pip_args,
242245
whls = [],
243246
sdist = common_sdist,
244247
is_exposed = is_exposed,
245248
),
246249
)
247250

248-
# Now add platform-specific entries with wheels
249-
for r in sorted(reqs.values(), key = lambda r: r.requirement_line):
250-
whls, sdist = _add_dists(
251-
requirement = r,
252-
index_urls = index_urls.get(whl_name),
253-
logger = logger,
254-
)
255-
if not common_sdist or len(whls) > 0: # Only add entries that have wheels
256-
target_platforms = env_marker_target_platforms.get(r.requirement_line, r.target_platforms)
257-
ret_requirements.append(
258-
struct(
259-
distribution = r.distribution,
260-
srcs = r.srcs,
261-
target_platforms = sorted(target_platforms),
262-
extra_pip_args = r.extra_pip_args,
263-
whls = whls,
264-
sdist = None if common_sdist else sdist, # No sdist in wheel-specific entries
265-
is_exposed = is_exposed,
266-
),
267-
)
268-
269251
if logger:
270252
logger.debug(lambda: "Will configure whl repos: {}".format(ret.keys()))
271253

tests/pypi/parse_requirements/parse_requirements_tests.bzl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -489,26 +489,6 @@ def _test_sdist_different_hashes(env):
489489
)
490490
env.expect.that_dict(got).contains_exactly({
491491
"foo": [
492-
struct(
493-
distribution = "foo",
494-
extra_pip_args = [],
495-
is_exposed = True,
496-
sdist = struct(
497-
filename = "foo-0.0.1.tar.gz",
498-
url = "https://pypi.org/foo-0.0.1.tar.gz",
499-
sha256 = "cafebabe",
500-
yanked = False,
501-
),
502-
srcs = struct(
503-
marker = "",
504-
requirement = "foo==0.0.1",
505-
requirement_line = "foo==0.0.1 --hash=sha256:deadbaaf --hash=sha256:cafebabe",
506-
shas = ["cafebabe", "deadbaaf"],
507-
version = "0.0.1",
508-
),
509-
target_platforms = ["cp315_linux_x86_64", "cp315_windows_x86_64"],
510-
whls = [],
511-
),
512492
struct(
513493
distribution = "foo",
514494
extra_pip_args = [],
@@ -553,6 +533,26 @@ def _test_sdist_different_hashes(env):
553533
),
554534
],
555535
),
536+
struct(
537+
distribution = "foo",
538+
extra_pip_args = [],
539+
is_exposed = True,
540+
sdist = struct(
541+
filename = "foo-0.0.1.tar.gz",
542+
url = "https://pypi.org/foo-0.0.1.tar.gz",
543+
sha256 = "cafebabe",
544+
yanked = False,
545+
),
546+
srcs = struct(
547+
marker = "",
548+
requirement = "foo==0.0.1",
549+
requirement_line = "foo==0.0.1 --hash=sha256:deadbeef --hash=sha256:cafebabe",
550+
shas = ["cafebabe", "deadbeef"],
551+
version = "0.0.1",
552+
),
553+
target_platforms = ["cp315_linux_x86_64", "cp315_windows_x86_64"],
554+
whls = [],
555+
),
556556
],
557557
})
558558

0 commit comments

Comments
 (0)