Skip to content
Open
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
2 changes: 2 additions & 0 deletions python/private/pypi/hub_builder.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ def _create_whl_repos(
extra_pip_args = pip_attr.extra_pip_args,
get_index_urls = self._get_index_urls.get(pip_attr.python_version),
evaluate_markers = _evaluate_markers(self, pip_attr),
download_only = pip_attr.download_only,
python_version = pip_attr.python_version,
logger = logger,
)

Expand Down
11 changes: 10 additions & 1 deletion python/private/pypi/parse_requirements.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def parse_requirements(
get_index_urls = None,
evaluate_markers = None,
extract_url_srcs = True,
download_only = False,
python_version = None,
logger):
"""Get the requirements with platforms that the requirements apply to.

Expand Down Expand Up @@ -114,7 +116,14 @@ def parse_requirements(
# output all of the requirement lines that have a marker
if ";" in requirement_line:
reqs_with_env_markers.setdefault(requirement_line, []).append(plat)
options[plat] = pip_args
plat_args = list(pip_args)
if download_only and plat.endswith("freethreaded") and python_version:
if not any([a.startswith("--abi") for a in plat_args]):
major, _, tail = python_version.partition(".")
minor, _, _ = tail.partition(".")
if major and minor:
plat_args.append("--abi=cp{}{}t".format(major, minor))
options[plat] = plat_args
Comment on lines +119 to +126
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation creates a new list copy for every platform, even when no modifications are needed. This can be optimized by only copying the list if the conditions for adding the --abi flag are met. Additionally, the check for existing --abi flags can be made more precise to avoid matching other flags that might start with the same prefix (though unlikely in this context).

Suggested change
plat_args = list(pip_args)
if download_only and plat.endswith("freethreaded") and python_version:
if not any([a.startswith("--abi") for a in plat_args]):
major, _, tail = python_version.partition(".")
minor, _, _ = tail.partition(".")
if major and minor:
plat_args.append("--abi=cp{}{}t".format(major, minor))
options[plat] = plat_args
plat_args = pip_args
if download_only and plat.endswith("freethreaded") and python_version:
if not any([a == "--abi" or a.startswith("--abi=") for a in plat_args]):
major, _, tail = python_version.partition(".")
minor, _, _ = tail.partition(".")
if major and minor:
plat_args = list(pip_args)
plat_args.append("--abi=cp{}{}t".format(major, minor))
options[plat] = plat_args


# Parse the index URL from the requirement files
index_url = argparse.index_url(pip_args, index_url)
Expand Down