Skip to content
6 changes: 6 additions & 0 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ bzl_library(
":parse_whl_name_bzl",
":pep508_env_bzl",
":pip_repository_attrs_bzl",
":platform_bzl",
":simpleapi_download_bzl",
":whl_library_bzl",
"//python/private:auth_bzl",
Expand Down Expand Up @@ -341,6 +342,11 @@ bzl_library(
],
)

bzl_library(
name = "platform_bzl",
srcs = ["platform.bzl"],
)

bzl_library(
name = "pypi_repo_utils_bzl",
srcs = ["pypi_repo_utils.bzl"],
Expand Down
26 changes: 1 addition & 25 deletions python/private/pypi/extension.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ load(":hub_repository.bzl", "hub_repository", "whl_config_settings_to_json")
load(":parse_whl_name.bzl", "parse_whl_name")
load(":pep508_env.bzl", "env")
load(":pip_repository_attrs.bzl", "ATTRS")
load(":platform.bzl", _plat = "platform")
load(":simpleapi_download.bzl", "simpleapi_download")
load(":whl_library.bzl", "whl_library")

Expand Down Expand Up @@ -55,31 +56,6 @@ def _whl_mods_impl(whl_mods_dict):
whl_mods = whl_mods,
)

def _plat(*, name, arch_name, os_name, config_settings = [], env = {}, marker = "", whl_abi_tags = [], whl_platform_tags = []):
# NOTE @aignas 2025-07-08: the least preferred is the first item in the list
if "any" not in whl_platform_tags:
# the lowest priority one needs to be the first one
whl_platform_tags = ["any"] + whl_platform_tags

whl_abi_tags = whl_abi_tags or ["abi3", "cp{major}{minor}"]
if "none" not in whl_abi_tags:
# the lowest priority one needs to be the first one
whl_abi_tags = ["none"] + whl_abi_tags

return struct(
name = name,
arch_name = arch_name,
os_name = os_name,
config_settings = config_settings,
env = {
# defaults for env
"implementation_name": "cpython",
} | env,
marker = marker,
whl_abi_tags = whl_abi_tags,
whl_platform_tags = whl_platform_tags,
)

def _configure(config, *, override = False, **kwargs):
"""Set the value in the config if the value is provided"""
env = kwargs.get("env")
Expand Down
45 changes: 45 additions & 0 deletions python/private/pypi/platform.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""A common platform structure for using internally."""

def platform(*, name, arch_name, os_name, config_settings = [], env = {}, marker = "", whl_abi_tags = [], whl_platform_tags = []):
"""A platform structure for using internally.

Args:
name: {type}`str` the human friendly name of the platform.
arch_name: {type}`str` the @platforms//cpu:<arch_name> value.
os_name: {type}`str` the @platforms//os:<os_name> value.
config_settings: {type}`list[Label|str]` The list of labels for selecting the
platform.
env: {type}`dict[str, str]` the PEP508 environment for marker evaluation.
marker: {type}`str` the env marker expression that is evaluated to determine if we
should use the platform. This is useful to turn on certain platforms for
particular python versions.
whl_abi_tags: {type}`list[str]` A list of values for matching abi tags.
whl_platform_tags: {type}`list[str]` A list of values for matching platform tags.

Returns:
struct with the necessary values for pipstar implementation.
"""

# NOTE @aignas 2025-07-08: the least preferred is the first item in the list
if "any" not in whl_platform_tags:
# the lowest priority one needs to be the first one
whl_platform_tags = ["any"] + whl_platform_tags

whl_abi_tags = whl_abi_tags or ["abi3", "cp{major}{minor}"]
if "none" not in whl_abi_tags:
# the lowest priority one needs to be the first one
whl_abi_tags = ["none"] + whl_abi_tags

return struct(
name = name,
arch_name = arch_name,
os_name = os_name,
config_settings = config_settings,
env = {
# defaults for env
"implementation_name": "cpython",
} | env,
marker = marker,
whl_abi_tags = whl_abi_tags,
whl_platform_tags = whl_platform_tags,
)
Loading