-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bzlmod)!: Move each bzlmod extension into its own file (#1226)
This commit refactors the files that contain the bzlmod extensions. - All extensions are moved under the new extensions folder - Private extensions are moved under extensions/private - All extension files are renamed to remove the _extension suffix - pip and internal_deps extensions are moved to their own file This commit organizes the extensions better and also follows the best practice of having a single extension per file. Having each extension in its own file allows them to use some additional features while helping avoid backwards incompatible changes. ## BREAKING CHANGES This splits `//python:extensions.bzl`, which previously held the `python` and `pip` extensions, into separate files (`python.bzl` and `pip.bzl`, respectively). Unfortunately, moving the location of the extensions is a breaking change due to how bzlmod extension identity works (see https://bazel.build/external/extension#extension_identity). Fortunately, by moving to one extension per file, we shouldn't have to ever do this again. Users must update the file path in their `use_repo()` statements as follows: * `use_extension("@rules_python//python:extensions.bzl", "python")` -> `use_extension("@rules_python//python/extensions:python.bzl", "python")` * `use_extension("@rules_python//python:extensions.bzl", "pip")` -> `use_extension("@rules_python//python/extensions:pip.bzl", "pip")` The following `sed` commands should approximate the necessary changes: ``` sed 'sXuse_extension("@rules_python//python:extensions.bzl", "python")Xuse_extension("@rules_python//python/extensions:python.bzl", "python")X'` sed 'sXuse_extension("@rules_python//python:extensions.bzl", "pip")Xuse_extension("@rules_python//python/extensions:pip.bzl", "pip")X'` ``` See `examples/bzlmod_build_file_generation/MODULE.bazel` for an example of the new paths.
- Loading branch information
1 parent
ccea92a
commit 46537cf
Showing
11 changed files
with
148 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2017 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. | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
name = "distribution", | ||
srcs = glob(["**"]), | ||
visibility = ["//extensions:__pkg__"], | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2022 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. | ||
|
||
package(default_visibility = ["//visibility:private"]) | ||
|
||
licenses(["notice"]) | ||
|
||
filegroup( | ||
name = "distribution", | ||
srcs = glob(["**"]), | ||
visibility = ["//python/extensions/private:__pkg__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 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. | ||
|
||
"Python toolchain module extension for internal rule use" | ||
|
||
load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies") | ||
load("@rules_python//python/private:coverage_deps.bzl", "install_coverage_deps") | ||
|
||
# buildifier: disable=unused-variable | ||
def _internal_deps_impl(module_ctx): | ||
pip_install_dependencies() | ||
install_coverage_deps() | ||
|
||
internal_deps = module_extension( | ||
doc = "This extension to register internal rules_python dependecies.", | ||
implementation = _internal_deps_impl, | ||
tag_classes = { | ||
"install": tag_class(attrs = dict()), | ||
}, | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2023 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. | ||
|
||
"Python toolchain module extensions for use with bzlmod" | ||
|
||
load("@rules_python//python:repositories.bzl", "python_register_toolchains") | ||
load("@rules_python//python/extensions/private:interpreter_hub.bzl", "hub_repo") | ||
|
||
def _python_impl(module_ctx): | ||
toolchains = [] | ||
for mod in module_ctx.modules: | ||
for toolchain_attr in mod.tags.toolchain: | ||
python_register_toolchains( | ||
name = toolchain_attr.name, | ||
python_version = toolchain_attr.python_version, | ||
bzlmod = True, | ||
# Toolchain registration in bzlmod is done in MODULE file | ||
register_toolchains = False, | ||
register_coverage_tool = toolchain_attr.configure_coverage_tool, | ||
ignore_root_user_error = toolchain_attr.ignore_root_user_error, | ||
) | ||
|
||
# We collect all of the toolchain names to create | ||
# the INTERPRETER_LABELS map. This is used | ||
# by interpreter_extensions.bzl | ||
toolchains.append(toolchain_attr.name) | ||
|
||
hub_repo( | ||
name = "pythons_hub", | ||
toolchains = toolchains, | ||
) | ||
|
||
python = module_extension( | ||
doc = "Bzlmod extension that is used to register a Python toolchain.", | ||
implementation = _python_impl, | ||
tag_classes = { | ||
"toolchain": tag_class( | ||
attrs = { | ||
"configure_coverage_tool": attr.bool( | ||
mandatory = False, | ||
doc = "Whether or not to configure the default coverage tool for the toolchains.", | ||
), | ||
"ignore_root_user_error": attr.bool( | ||
default = False, | ||
doc = "Whether the check for root should be ignored or not. This causes cache misses with .pyc files.", | ||
mandatory = False, | ||
), | ||
"name": attr.string(mandatory = True), | ||
"python_version": attr.string(mandatory = True), | ||
}, | ||
), | ||
}, | ||
) |