Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: stop warning if we don't find anything via SimpleAPI #2532

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 52 additions & 67 deletions python/private/pypi/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def _create_whl_repos(

# containers to aggregate outputs from this function
whl_map = {}
exposed_packages = {}
extra_aliases = {
whl_name: {alias: True for alias in aliases}
for whl_name, aliases in pip_attr.extra_hub_aliases.items()
Expand Down Expand Up @@ -219,8 +218,6 @@ def _create_whl_repos(
)

for whl_name, requirements in requirements_by_platform.items():
whl_name = normalize_name(whl_name)

group_name = whl_group_mapping.get(whl_name)
group_deps = requirement_cycles.get(group_name, [])

Expand Down Expand Up @@ -261,68 +258,55 @@ def _create_whl_repos(
if v != default
})

is_exposed = False
if get_index_urls:
# TODO @aignas 2024-05-26: move to a separate function
found_something = False
for requirement in requirements:
is_exposed = is_exposed or requirement.is_exposed
dists = requirement.whls
if not pip_attr.download_only and requirement.sdist:
dists = dists + [requirement.sdist]

for distribution in dists:
found_something = True
is_reproducible = False

args = dict(whl_library_args)
if pip_attr.netrc:
args["netrc"] = pip_attr.netrc
if pip_attr.auth_patterns:
args["auth_patterns"] = pip_attr.auth_patterns

if not distribution.filename.endswith(".whl"):
# pip is not used to download wheels and the python
# `whl_library` helpers are only extracting things, however
# for sdists, they will be built by `pip`, so we still
# need to pass the extra args there.
args["extra_pip_args"] = requirement.extra_pip_args

# This is no-op because pip is not used to download the wheel.
args.pop("download_only", None)

repo_name = whl_repo_name(pip_name, distribution.filename, distribution.sha256)
args["requirement"] = requirement.srcs.requirement
args["urls"] = [distribution.url]
args["sha256"] = distribution.sha256
args["filename"] = distribution.filename
args["experimental_target_platforms"] = requirement.target_platforms

# Pure python wheels or sdists may need to have a platform here
target_platforms = None
if distribution.filename.endswith("-any.whl") or not distribution.filename.endswith(".whl"):
if len(requirements) > 1:
target_platforms = requirement.target_platforms

whl_libraries[repo_name] = args

whl_map.setdefault(whl_name, {})[whl_config_setting(
version = major_minor,
filename = distribution.filename,
target_platforms = target_platforms,
)] = repo_name

if found_something:
if is_exposed:
exposed_packages[whl_name] = None
continue

is_exposed = False
# TODO @aignas 2024-05-26: move to a separate function
for requirement in requirements:
is_exposed = is_exposed or requirement.is_exposed
if get_index_urls:
logger.warn(lambda: "falling back to pip for installing the right file for {}".format(requirement.srcs.requirement_line))
dists = requirement.whls
if not pip_attr.download_only and requirement.sdist:
dists = dists + [requirement.sdist]

for distribution in dists:
args = dict(whl_library_args)
if pip_attr.netrc:
args["netrc"] = pip_attr.netrc
if pip_attr.auth_patterns:
args["auth_patterns"] = pip_attr.auth_patterns

if not distribution.filename.endswith(".whl"):
# pip is not used to download wheels and the python
# `whl_library` helpers are only extracting things, however
# for sdists, they will be built by `pip`, so we still
# need to pass the extra args there.
args["extra_pip_args"] = requirement.extra_pip_args

# This is no-op because pip is not used to download the wheel.
args.pop("download_only", None)

repo_name = whl_repo_name(pip_name, distribution.filename, distribution.sha256)
args["requirement"] = requirement.srcs.requirement
args["urls"] = [distribution.url]
args["sha256"] = distribution.sha256
args["filename"] = distribution.filename
args["experimental_target_platforms"] = requirement.target_platforms

# Pure python wheels or sdists may need to have a platform here
target_platforms = None
if distribution.filename.endswith("-any.whl") or not distribution.filename.endswith(".whl"):
if len(requirements) > 1:
target_platforms = requirement.target_platforms

whl_libraries[repo_name] = args

whl_map.setdefault(whl_name, {})[whl_config_setting(
version = major_minor,
filename = distribution.filename,
target_platforms = target_platforms,
)] = repo_name

if dists:
is_reproducible = False
continue

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

if is_exposed:
exposed_packages[whl_name] = None

return struct(
is_reproducible = is_reproducible,
whl_map = whl_map,
exposed_packages = exposed_packages,
exposed_packages = {
whl_name: None
for whl_name, requirements in requirements_by_platform.items()
if len([r for r in requirements if r.is_exposed]) > 0
},
extra_aliases = extra_aliases,
whl_libraries = whl_libraries,
)
Expand Down
5 changes: 4 additions & 1 deletion python/private/pypi/parse_requirements.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def parse_requirements(
sorted(requirements),
))

# Return normalized names
ret_requirements = ret.setdefault(normalize_name(whl_name), [])

for r in sorted(reqs.values(), key = lambda r: r.requirement_line):
whls, sdist = _add_dists(
requirement = r,
Expand All @@ -211,7 +214,7 @@ def parse_requirements(
)

target_platforms = env_marker_target_platforms.get(r.requirement_line, r.target_platforms)
ret.setdefault(whl_name, []).append(
ret_requirements.append(
struct(
distribution = r.distribution,
srcs = r.srcs,
Expand Down