Skip to content

Commit 8fdd983

Browse files
committed
fix: Fixing select when we don't have specific platforms
In certain releases of Python we do not have various platforms like ppc. When using the call PLATFORMS.keys() we get all of the platforms instead of the platforms that are included with the Python version. We get the error "no such package" because, for instance, python_3_10_ppc64le-unknown-linux-gnu does not exist in Python 3.10.9 (see versions.bzl). You can recreate this error by running a bazel query command inside the examples/bzlmod directory. If you run: bazel query "deps(@python_3_10//:python_headers)" With a version of the rules previous to this commit, you will get an error. With this commit, you get a printout of all of the python_headers for all of the platforms that are supported in the Python 3.10 version used by the repository. Instead of using PLATFORMS.keys(), we use the sha256 keys in TOOL_VERSIONS dict based on the full Python version. This change now returns only the platforms supported in the Python version. Fixes: #1326
1 parent fabb65f commit 8fdd983

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

python/private/toolchains_repo.bzl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ load(
2727
"//python:versions.bzl",
2828
"LINUX_NAME",
2929
"MACOS_NAME",
30+
"MINOR_MAPPING",
3031
"PLATFORMS",
32+
"TOOL_VERSIONS",
3133
"WINDOWS_NAME",
3234
)
3335

@@ -150,27 +152,35 @@ def _toolchain_aliases_impl(rctx):
150152
is_windows = (os_name == WINDOWS_NAME)
151153
python3_binary_path = "python.exe" if is_windows else "bin/python3"
152154

155+
# uncertain if we need to do this check or not
156+
# TODO use the code that is inbound on #1340
157+
full_python_version = rctx.attr.python_version
158+
if TOOL_VERSIONS.get(full_python_version) == None:
159+
full_python_version = MINOR_MAPPING[full_python_version]
160+
153161
# Base BUILD file for this repository.
154162
build_contents = """\
155163
# Generated by python/private/toolchains_repo.bzl
156164
package(default_visibility = ["//visibility:public"])
157-
load("@rules_python//python:versions.bzl", "PLATFORMS", "gen_python_config_settings")
165+
load("@rules_python//python:versions.bzl", "TOOL_VERSIONS", "gen_python_config_settings")
158166
gen_python_config_settings()
159167
exports_files(["defs.bzl"])
160-
alias(name = "files", actual = select({{":" + item: "@{py_repository}_" + item + "//:files" for item in PLATFORMS.keys()}}))
161-
alias(name = "includes", actual = select({{":" + item: "@{py_repository}_" + item + "//:includes" for item in PLATFORMS.keys()}}))
162-
alias(name = "libpython", actual = select({{":" + item: "@{py_repository}_" + item + "//:libpython" for item in PLATFORMS.keys()}}))
163-
alias(name = "py3_runtime", actual = select({{":" + item: "@{py_repository}_" + item + "//:py3_runtime" for item in PLATFORMS.keys()}}))
164-
alias(name = "python_headers", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_headers" for item in PLATFORMS.keys()}}))
165-
alias(name = "python_runtimes", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS.keys()}}))
166-
alias(name = "python3", actual = select({{":" + item: "@{py_repository}_" + item + "//:" + ("python.exe" if "windows" in item else "bin/python3") for item in PLATFORMS.keys()}}))
168+
alias(name = "files", actual = select({{":" + item: "@{py_repository}_" + item + "//:files" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
169+
alias(name = "includes", actual = select({{":" + item: "@{py_repository}_" + item + "//:includes" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
170+
alias(name = "libpython", actual = select({{":" + item: "@{py_repository}_" + item + "//:libpython" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
171+
alias(name = "py3_runtime", actual = select({{":" + item: "@{py_repository}_" + item + "//:py3_runtime" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
172+
alias(name = "python_headers", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_headers" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
173+
alias(name = "python_runtimes", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
174+
alias(name = "python3", actual = select({{":" + item: "@{py_repository}_" + item + "//:" + ("python.exe" if "windows" in item else "bin/python3") for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
167175
""".format(
176+
full_python_version = full_python_version,
168177
py_repository = rctx.attr.user_repository_name,
169178
)
170179
if not is_windows:
171180
build_contents += """\
172-
alias(name = "pip", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS.keys() if "windows" not in item}}))
181+
alias(name = "pip", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys() if "windows" not in item}}))
173182
""".format(
183+
full_python_version = full_python_version,
174184
py_repository = rctx.attr.user_repository_name,
175185
host_platform = host_platform,
176186
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy