Skip to content

Commit 49cdf7d

Browse files
authored
fix: make the pythons_hub platform independent (#1946)
With this change we can finally have platform independent bzlmod lock files in rules_python. This cleans up code paths that were not being used in the `pip` extension for a while and the replacement is noted in the CHANGELOG. Fixes #1643
1 parent f82e3dc commit 49cdf7d

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ A brief description of the categories of changes:
5050
`{pip_hub_prefix}_{wheel_name}_{py_tag}_{abi_tag}_{platform_tag}_{sha256}`,
5151
which is an implementation detail which should not be relied on and is there
5252
purely for better debugging experience.
53+
* (bzlmod) The `pythons_hub//:interpreters.bzl` no longer has platform-specific
54+
labels which where left there for compatibility reasons. Move to
55+
`python_{version}_host` keys if you would like to have access to a Python
56+
interpreter that can be used in a repository rule context.
5357

5458
### Fixed
5559
* (gazelle) Remove `visibility` from `NonEmptyAttr`.

python/private/bzlmod/pythons_hub.bzl

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414

1515
"Repo rule used by bzlmod extension to create a repo that has a map of Python interpreters and their labels"
1616

17-
load("//python:versions.bzl", "WINDOWS_NAME")
1817
load("//python/private:full_version.bzl", "full_version")
1918
load(
2019
"//python/private:toolchains_repo.bzl",
21-
"get_host_os_arch",
22-
"get_host_platform",
2320
"python_toolchain_build_file_content",
2421
)
2522

@@ -83,7 +80,7 @@ DEFAULT_PYTHON_VERSION = "{default_python_version}"
8380
"""
8481

8582
_line_for_hub_template = """\
86-
"{key}": Label("@{name}_{platform}//:{path}"),
83+
"{name}_host": Label("@{name}_host//:python"),
8784
"""
8885

8986
def _hub_repo_impl(rctx):
@@ -101,28 +98,11 @@ def _hub_repo_impl(rctx):
10198
executable = False,
10299
)
103100

104-
(os, arch) = get_host_os_arch(rctx)
105-
platform = get_host_platform(os, arch)
106-
is_windows = (os == WINDOWS_NAME)
107-
path = "python.exe" if is_windows else "bin/python3"
108-
109101
# Create a dict that is later used to create
110102
# a symlink to a interpreter.
111103
interpreter_labels = "".join([
112-
_line_for_hub_template.format(
113-
key = name + ("" if platform_str != "host" else "_host"),
114-
name = name,
115-
platform = platform_str,
116-
path = p,
117-
)
104+
_line_for_hub_template.format(name = name)
118105
for name in rctx.attr.toolchain_user_repository_names
119-
for platform_str, p in {
120-
# NOTE @aignas 2023-12-21: maintaining the `platform` specific key
121-
# here may be unneeded in the long term, but I am not sure if there
122-
# are other users that depend on it.
123-
platform: path,
124-
"host": "python",
125-
}.items()
126106
])
127107

128108
rctx.file(

0 commit comments

Comments
 (0)