Skip to content

Commit 922929b

Browse files
authored
refactor: stop warning if we don't find anything via SimpleAPI (#2532)
The warning is somewhat non-actionable and the sources can be inspected via the MODULE.bazel.lock file if needed. This makes it easier to make this option a default at some point. At the same time cleanup the code since we are not using the `get_index_urls` to print the warning. Work towards #260
1 parent b5729b4 commit 922929b

File tree

2 files changed

+56
-68
lines changed

2 files changed

+56
-68
lines changed

python/private/pypi/extension.bzl

Lines changed: 52 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def _create_whl_repos(
105105

106106
# containers to aggregate outputs from this function
107107
whl_map = {}
108-
exposed_packages = {}
109108
extra_aliases = {
110109
whl_name: {alias: True for alias in aliases}
111110
for whl_name, aliases in pip_attr.extra_hub_aliases.items()
@@ -219,8 +218,6 @@ def _create_whl_repos(
219218
)
220219

221220
for whl_name, requirements in requirements_by_platform.items():
222-
whl_name = normalize_name(whl_name)
223-
224221
group_name = whl_group_mapping.get(whl_name)
225222
group_deps = requirement_cycles.get(group_name, [])
226223

@@ -261,68 +258,55 @@ def _create_whl_repos(
261258
if v != default
262259
})
263260

264-
is_exposed = False
265-
if get_index_urls:
266-
# TODO @aignas 2024-05-26: move to a separate function
267-
found_something = False
268-
for requirement in requirements:
269-
is_exposed = is_exposed or requirement.is_exposed
270-
dists = requirement.whls
271-
if not pip_attr.download_only and requirement.sdist:
272-
dists = dists + [requirement.sdist]
273-
274-
for distribution in dists:
275-
found_something = True
276-
is_reproducible = False
277-
278-
args = dict(whl_library_args)
279-
if pip_attr.netrc:
280-
args["netrc"] = pip_attr.netrc
281-
if pip_attr.auth_patterns:
282-
args["auth_patterns"] = pip_attr.auth_patterns
283-
284-
if not distribution.filename.endswith(".whl"):
285-
# pip is not used to download wheels and the python
286-
# `whl_library` helpers are only extracting things, however
287-
# for sdists, they will be built by `pip`, so we still
288-
# need to pass the extra args there.
289-
args["extra_pip_args"] = requirement.extra_pip_args
290-
291-
# This is no-op because pip is not used to download the wheel.
292-
args.pop("download_only", None)
293-
294-
repo_name = whl_repo_name(pip_name, distribution.filename, distribution.sha256)
295-
args["requirement"] = requirement.srcs.requirement
296-
args["urls"] = [distribution.url]
297-
args["sha256"] = distribution.sha256
298-
args["filename"] = distribution.filename
299-
args["experimental_target_platforms"] = requirement.target_platforms
300-
301-
# Pure python wheels or sdists may need to have a platform here
302-
target_platforms = None
303-
if distribution.filename.endswith("-any.whl") or not distribution.filename.endswith(".whl"):
304-
if len(requirements) > 1:
305-
target_platforms = requirement.target_platforms
306-
307-
whl_libraries[repo_name] = args
308-
309-
whl_map.setdefault(whl_name, {})[whl_config_setting(
310-
version = major_minor,
311-
filename = distribution.filename,
312-
target_platforms = target_platforms,
313-
)] = repo_name
314-
315-
if found_something:
316-
if is_exposed:
317-
exposed_packages[whl_name] = None
318-
continue
319-
320-
is_exposed = False
261+
# TODO @aignas 2024-05-26: move to a separate function
321262
for requirement in requirements:
322-
is_exposed = is_exposed or requirement.is_exposed
323-
if get_index_urls:
324-
logger.warn(lambda: "falling back to pip for installing the right file for {}".format(requirement.srcs.requirement_line))
263+
dists = requirement.whls
264+
if not pip_attr.download_only and requirement.sdist:
265+
dists = dists + [requirement.sdist]
266+
267+
for distribution in dists:
268+
args = dict(whl_library_args)
269+
if pip_attr.netrc:
270+
args["netrc"] = pip_attr.netrc
271+
if pip_attr.auth_patterns:
272+
args["auth_patterns"] = pip_attr.auth_patterns
273+
274+
if not distribution.filename.endswith(".whl"):
275+
# pip is not used to download wheels and the python
276+
# `whl_library` helpers are only extracting things, however
277+
# for sdists, they will be built by `pip`, so we still
278+
# need to pass the extra args there.
279+
args["extra_pip_args"] = requirement.extra_pip_args
280+
281+
# This is no-op because pip is not used to download the wheel.
282+
args.pop("download_only", None)
283+
284+
repo_name = whl_repo_name(pip_name, distribution.filename, distribution.sha256)
285+
args["requirement"] = requirement.srcs.requirement
286+
args["urls"] = [distribution.url]
287+
args["sha256"] = distribution.sha256
288+
args["filename"] = distribution.filename
289+
args["experimental_target_platforms"] = requirement.target_platforms
290+
291+
# Pure python wheels or sdists may need to have a platform here
292+
target_platforms = None
293+
if distribution.filename.endswith("-any.whl") or not distribution.filename.endswith(".whl"):
294+
if len(requirements) > 1:
295+
target_platforms = requirement.target_platforms
296+
297+
whl_libraries[repo_name] = args
298+
299+
whl_map.setdefault(whl_name, {})[whl_config_setting(
300+
version = major_minor,
301+
filename = distribution.filename,
302+
target_platforms = target_platforms,
303+
)] = repo_name
304+
305+
if dists:
306+
is_reproducible = False
307+
continue
325308

309+
# Fallback to a pip-installed wheel
326310
args = dict(whl_library_args) # make a copy
327311
args["requirement"] = requirement.srcs.requirement_line
328312
if requirement.extra_pip_args:
@@ -343,13 +327,14 @@ def _create_whl_repos(
343327
target_platforms = target_platforms or None,
344328
)] = repo_name
345329

346-
if is_exposed:
347-
exposed_packages[whl_name] = None
348-
349330
return struct(
350331
is_reproducible = is_reproducible,
351332
whl_map = whl_map,
352-
exposed_packages = exposed_packages,
333+
exposed_packages = {
334+
whl_name: None
335+
for whl_name, requirements in requirements_by_platform.items()
336+
if len([r for r in requirements if r.is_exposed]) > 0
337+
},
353338
extra_aliases = extra_aliases,
354339
whl_libraries = whl_libraries,
355340
)

python/private/pypi/parse_requirements.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def parse_requirements(
203203
sorted(requirements),
204204
))
205205

206+
# Return normalized names
207+
ret_requirements = ret.setdefault(normalize_name(whl_name), [])
208+
206209
for r in sorted(reqs.values(), key = lambda r: r.requirement_line):
207210
whls, sdist = _add_dists(
208211
requirement = r,
@@ -211,7 +214,7 @@ def parse_requirements(
211214
)
212215

213216
target_platforms = env_marker_target_platforms.get(r.requirement_line, r.target_platforms)
214-
ret.setdefault(whl_name, []).append(
217+
ret_requirements.append(
215218
struct(
216219
distribution = r.distribution,
217220
srcs = r.srcs,

0 commit comments

Comments
 (0)