Skip to content

fix: Fixing select when we don't have specific platforms #1364

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

Closed
Closed
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
28 changes: 19 additions & 9 deletions python/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ load(
"//python:versions.bzl",
"LINUX_NAME",
"MACOS_NAME",
"MINOR_MAPPING",
"PLATFORMS",
"TOOL_VERSIONS",
"WINDOWS_NAME",
)

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

# uncertain if we need to do this check or not
# TODO use the code that is inbound on #1340
full_python_version = rctx.attr.python_version
if TOOL_VERSIONS.get(full_python_version) == None:
full_python_version = MINOR_MAPPING[full_python_version]
Comment on lines +157 to +159
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had code in #1294 that was similar to this, it was called full_version, which would always ensure that the python version is in X.Y.Z format. I think we could cherry pick it from there. I did the cherry pick in #1340, but that has not been reviewed yet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And a nit: this could be changed to be full_python_version = MINOR_MAPPING.get(rctx.attr.python_version, rctx.attr.python_version) as we should have an entry in MINOR_MAPPING for each entry in TOOL_VERSIONS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will wait for #1340 to get in and use that.


# Base BUILD file for this repository.
build_contents = """\
# Generated by python/private/toolchains_repo.bzl
package(default_visibility = ["//visibility:public"])
load("@rules_python//python:versions.bzl", "PLATFORMS", "gen_python_config_settings")
load("@rules_python//python:versions.bzl", "TOOL_VERSIONS", "gen_python_config_settings")
gen_python_config_settings()
exports_files(["defs.bzl"])
alias(name = "files", actual = select({{":" + item: "@{py_repository}_" + item + "//:files" for item in PLATFORMS.keys()}}))
alias(name = "includes", actual = select({{":" + item: "@{py_repository}_" + item + "//:includes" for item in PLATFORMS.keys()}}))
alias(name = "libpython", actual = select({{":" + item: "@{py_repository}_" + item + "//:libpython" for item in PLATFORMS.keys()}}))
alias(name = "py3_runtime", actual = select({{":" + item: "@{py_repository}_" + item + "//:py3_runtime" for item in PLATFORMS.keys()}}))
alias(name = "python_headers", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_headers" for item in PLATFORMS.keys()}}))
alias(name = "python_runtimes", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS.keys()}}))
alias(name = "python3", actual = select({{":" + item: "@{py_repository}_" + item + "//:" + ("python.exe" if "windows" in item else "bin/python3") for item in PLATFORMS.keys()}}))
alias(name = "files", actual = select({{":" + item: "@{py_repository}_" + item + "//:files" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
alias(name = "includes", actual = select({{":" + item: "@{py_repository}_" + item + "//:includes" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
alias(name = "libpython", actual = select({{":" + item: "@{py_repository}_" + item + "//:libpython" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
alias(name = "py3_runtime", actual = select({{":" + item: "@{py_repository}_" + item + "//:py3_runtime" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
alias(name = "python_headers", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_headers" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
alias(name = "python_runtimes", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in TOOL_VERSIONS['{full_python_version}']['sha256'].keys()}}))
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()}}))
""".format(
full_python_version = full_python_version,
py_repository = rctx.attr.user_repository_name,
)
if not is_windows:
build_contents += """\
alias(name = "pip", actual = select({{":" + item: "@{py_repository}_" + item + "//:python_runtimes" for item in PLATFORMS.keys() if "windows" not in item}}))
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}}))
""".format(
full_python_version = full_python_version,
py_repository = rctx.attr.user_repository_name,
host_platform = host_platform,
)
Expand Down
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