Skip to content

Commit 64f355c

Browse files
committed
use sha dictionary instead
1 parent ddfecc4 commit 64f355c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

python/private/pypi/parse_requirements.bzl

+12-9
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ def parse_requirements(
206206

207207
# Return normalized names
208208
ret_requirements = ret.setdefault(normalize_name(whl_name), [])
209-
210-
all_platforms = []
211-
common_sdist = None
209+
sdists_by_sha = {}
212210

213211
for r in sorted(reqs.values(), key = lambda r: r.requirement_line):
214212
whls, sdist = _add_dists(
@@ -217,11 +215,16 @@ def parse_requirements(
217215
logger = logger,
218216
)
219217

220-
if sdist and not common_sdist:
221-
common_sdist = sdist
218+
if sdist:
219+
sha = sdist.sha256
220+
if sha not in sdists_by_sha:
221+
sdists_by_sha[sha] = struct(
222+
sdist = sdist,
223+
platforms = [],
224+
)
225+
sdists_by_sha[sha].platforms.extend(r.target_platforms)
222226

223227
target_platforms = env_marker_target_platforms.get(r.requirement_line, r.target_platforms)
224-
all_platforms.extend(target_platforms)
225228

226229
ret_requirements.append(
227230
struct(
@@ -235,15 +238,15 @@ def parse_requirements(
235238
),
236239
)
237240

238-
if common_sdist:
241+
for sha, sdist_info in sdists_by_sha.items():
239242
ret_requirements.append(
240243
struct(
241244
distribution = r.distribution,
242245
srcs = r.srcs,
243-
target_platforms = sorted(all_platforms),
246+
target_platforms = sorted(sdist_info.platforms),
244247
extra_pip_args = r.extra_pip_args,
245248
whls = [],
246-
sdist = common_sdist,
249+
sdist = sdist_info.sdist,
247250
is_exposed = is_exposed,
248251
),
249252
)

0 commit comments

Comments
 (0)