Skip to content

Commit

Permalink
refactor: rename the remaining file
Browse files Browse the repository at this point in the history
  • Loading branch information
aignas committed Sep 19, 2024
1 parent d2c43cd commit 15ca0ea
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 247 deletions.
2 changes: 1 addition & 1 deletion python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ bzl_library(
deps = [
"//python/private:is_standalone_interpreter_bzl",
"//python/private:py_repositories_bzl",
"//python/private:python_register_multi_toolchains_bzl",
"//python/private:python_register_toolchains_bzl",
"//python/private:python_repositories_bzl",
"//python/private:python_repository_bzl",
],
)
Expand Down
13 changes: 3 additions & 10 deletions python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,12 @@ bzl_library(
)

bzl_library(
name = "python_repositories_bzl",
srcs = ["python_repositories.bzl"],
name = "python_register_multi_toolchains_bzl",
srcs = ["python_register_multi_toolchains.bzl"],
deps = [
":auth_bzl",
":bazel_tools_bzl",
":bzlmod_enabled_bzl",
":coverage_deps_bzl",
":full_version_bzl",
":internal_config_repo_bzl",
":python_repository_bzl",
":python_register_toolchains_bzl",
":toolchains_repo_bzl",
"//python:versions_bzl",
"//python/private/pypi:deps_bzl",
],
)

Expand Down
75 changes: 75 additions & 0 deletions python/private/python_register_multi_toolchains.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This file contains repository rules and macros to support toolchain registration.
"""

load("//python:versions.bzl", "MINOR_MAPPING")
load(":python_register_toolchains.bzl", "python_register_toolchains")
load(":toolchains_repo.bzl", "multi_toolchain_aliases")

def python_register_multi_toolchains(
name,
python_versions,
default_version = None,
minor_mapping = None,
**kwargs):
"""Convenience macro for registering multiple Python toolchains.
Args:
name: {type}`str` base name for each name in {obj}`python_register_toolchains` call.
python_versions: {type}`list[str]` the Python versions.
default_version: {type}`str` the default Python version. If not set,
the first version in python_versions is used.
minor_mapping: {type}`dict[str, str]` mapping between `X.Y` to `X.Y.Z`
format. Defaults to the value in `//python:versions.bzl`.
**kwargs: passed to each {obj}`python_register_toolchains` call.
"""
if len(python_versions) == 0:
fail("python_versions must not be empty")

minor_mapping = minor_mapping or MINOR_MAPPING

if not default_version:
default_version = python_versions.pop(0)
for python_version in python_versions:
if python_version == default_version:
# We register the default version lastly so that it's not picked first when --platforms
# is set with a constraint during toolchain resolution. This is due to the fact that
# Bazel will match the unconstrained toolchain if we register it before the constrained
# ones.
continue
python_register_toolchains(
name = name + "_" + python_version.replace(".", "_"),
python_version = python_version,
set_python_version_constraint = True,
minor_mapping = minor_mapping,
**kwargs
)
python_register_toolchains(
name = name + "_" + default_version.replace(".", "_"),
python_version = default_version,
set_python_version_constraint = False,
minor_mapping = minor_mapping,
**kwargs
)

multi_toolchain_aliases(
name = name,
python_versions = {
python_version: name + "_" + python_version.replace(".", "_")
for python_version in (python_versions + [default_version])
},
minor_mapping = minor_mapping,
)
232 changes: 0 additions & 232 deletions python/private/python_repositories.bzl

This file was deleted.

5 changes: 1 addition & 4 deletions python/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ load(
_is_standalone_interpreter = "is_standalone_interpreter",
)
load("//python/private:py_repositories.bzl", _py_repositories = "py_repositories")
load("//python/private:python_register_multi_toolchains.bzl", _python_register_multi_toolchains = "python_register_multi_toolchains")
load("//python/private:python_register_toolchains.bzl", _python_register_toolchains = "python_register_toolchains")
load(
"//python/private:python_repositories.bzl",
_python_register_multi_toolchains = "python_register_multi_toolchains",
)
load("//python/private:python_repository.bzl", _python_repository = "python_repository")

py_repositories = _py_repositories
Expand Down

0 comments on commit 15ca0ea

Please sign in to comment.