Skip to content

Commit e32a034

Browse files
committed
Merge remote-tracking branch 'upstream/main' into remove-builtinpyinfo
2 parents 852da78 + d85a392 commit e32a034

37 files changed

+558
-380
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ A brief description of the categories of changes:
2525
[x.x.x]: https://github.com/bazelbuild/rules_python/releases/tag/x.x.x
2626

2727
### Changed
28-
* Nothing yet
28+
* (toolchains) `py_runtime.implementation_name` now defaults to `cpython`
29+
(previously it defaulted to None).
2930

3031
### Fixed
32+
* (bzlmod) The `python.override(minor_mapping)` now merges the default and the
33+
overridden versions ensuring that the resultant `minor_mapping` will always
34+
have all of the python versions.
35+
* (bzlmod) The default value for the {obj}`--python_version` flag will now be
36+
always set to the default python toolchain version value.
3137
* (bzlmod) correctly wire the {attr}`pip.parse.extra_pip_args` all the
3238
way to {obj}`whl_library`. What is more we will pass the `extra_pip_args` to
3339
{obj}`whl_library` for `sdist` distributions when using
@@ -38,6 +44,11 @@ A brief description of the categories of changes:
3844
### Added
3945
* (py_wheel) Now supports `compress = (True|False)` to allow disabling
4046
compression to speed up development.
47+
* (toolchains): A public `//python/config_settings:python_version_major_minor` has
48+
been exposed for users to be able to match on the `X.Y` version of a Python
49+
interpreter.
50+
* (api) Added {obj}`merge_py_infos()` so user rules can merge and propagate
51+
`PyInfo` without losing information.
4152

4253
### Removed
4354
* Nothing yet

WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ load("//:internal_setup.bzl", "rules_python_internal_setup")
4141

4242
rules_python_internal_setup()
4343

44+
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING", "PYTHON_VERSIONS")
4445
load("//python:repositories.bzl", "python_register_multi_toolchains")
45-
load("//python:versions.bzl", "MINOR_MAPPING", "TOOL_VERSIONS")
4646

4747
python_register_multi_toolchains(
4848
name = "python",
4949
default_version = MINOR_MAPPING.values()[-2],
5050
# Integration tests verify each version, so register all of them.
51-
python_versions = TOOL_VERSIONS.keys(),
51+
python_versions = PYTHON_VERSIONS,
5252
)
5353

5454
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

docs/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ sphinx_stardocs(
9393
"//python:py_runtime_info_bzl",
9494
"//python:py_test_bzl",
9595
"//python:repositories_bzl",
96+
"//python/api:api_bzl",
9697
"//python/cc:py_cc_toolchain_bzl",
9798
"//python/cc:py_cc_toolchain_info_bzl",
9899
"//python/entry_points:py_console_script_binary_bzl",
99100
"//python/private:py_cc_toolchain_rule_bzl",
101+
"//python/private/api:py_common_api_bzl",
100102
"//python/private/common:py_binary_rule_bazel_bzl",
101103
"//python/private/common:py_library_rule_bazel_bzl",
102104
"//python/private/common:py_runtime_rule_bzl",

docs/api/rules_python/python/config_settings/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Determines the default hermetic Python toolchain version. This can be set to
1010
one of the values that `rules_python` maintains.
1111
:::
1212

13+
:::{bzl:target} python_version_major_minor
14+
Parses the value of the `python_version` and transforms it into a `X.Y` value.
15+
:::
16+
1317
::::{bzl:flag} exec_tools_toolchain
1418
Determines if the {obj}`exec_tools_toolchain_type` toolchain is enabled.
1519

examples/bzlmod/MODULE.bazel

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ python.toolchain(
4242
python.override(
4343
available_python_versions = [
4444
"3.10.9",
45+
"3.9.18",
4546
"3.9.19",
4647
# The following is used by the `other_module` and we need to include it here
4748
# as well.
4849
"3.11.8",
4950
],
5051
# Also override the `minor_mapping` so that the root module,
51-
# instead of rules_python's defaults, controls what full version
52-
# is used when `3.x` is requested.
52+
# instead of rules_python's defaulting to the latest available version,
53+
# controls what full version is used when `3.x` is requested.
5354
minor_mapping = {
54-
"3.10": "3.10.9",
55-
"3.11": "3.11.8",
5655
"3.9": "3.9.19",
5756
},
5857
)
@@ -90,7 +89,7 @@ python.single_version_platform_override(
9089
# See the tests folder for various examples on using multiple Python versions.
9190
# The names "python_3_9" and "python_3_10" are autmatically created by the repo
9291
# rules based on the `python_version` arg values.
93-
use_repo(python, "python_3_10", "python_3_9", "python_versions")
92+
use_repo(python, "python_3_10", "python_3_9", "python_versions", "pythons_hub")
9493

9594
# EXPERIMENTAL: This is experimental and may be removed without notice
9695
uv = use_extension("@rules_python//python/uv:extensions.bzl", "uv")

examples/bzlmod/MODULE.bazel.lock

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bzlmod/tests/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
load("@python_versions//3.10:defs.bzl", py_binary_3_10 = "py_binary", py_test_3_10 = "py_test")
22
load("@python_versions//3.11:defs.bzl", py_binary_3_11 = "py_binary", py_test_3_11 = "py_test")
33
load("@python_versions//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9 = "py_test")
4+
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING")
45
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
5-
load("@rules_python//python:versions.bzl", "MINOR_MAPPING")
66
load("@rules_python//python/config_settings:transition.bzl", py_versioned_binary = "py_binary", py_versioned_test = "py_test")
77

88
py_binary(

internal_setup.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@ load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_in
2222
load("@rules_bazel_integration_test//bazel_integration_test:repo_defs.bzl", "bazel_binaries")
2323
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
2424
load("//:version.bzl", "SUPPORTED_BAZEL_VERSIONS")
25+
load("//python:versions.bzl", "MINOR_MAPPING", "TOOL_VERSIONS")
2526
load("//python/private:internal_config_repo.bzl", "internal_config_repo") # buildifier: disable=bzl-visibility
27+
load("//python/private:pythons_hub.bzl", "hub_repo") # buildifier: disable=bzl-visibility
2628
load("//python/private/pypi:deps.bzl", "pypi_deps") # buildifier: disable=bzl-visibility
2729

2830
def rules_python_internal_setup():
2931
"""Setup for rules_python tests and tools."""
3032

3133
internal_config_repo(name = "rules_python_internal")
34+
hub_repo(
35+
name = "pythons_hub",
36+
minor_mapping = MINOR_MAPPING,
37+
default_python_version = "",
38+
toolchain_prefixes = [],
39+
toolchain_python_versions = [],
40+
toolchain_set_python_version_constraints = [],
41+
toolchain_user_repository_names = [],
42+
python_versions = sorted(TOOL_VERSIONS.keys()),
43+
)
3244

3345
# Because we don't use the pip_install rule, we have to call this to fetch its deps
3446
pypi_deps()

python/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ licenses(["notice"])
3434
filegroup(
3535
name = "distribution",
3636
srcs = glob(["**"]) + [
37+
"//python/api:distribution",
3738
"//python/cc:distribution",
3839
"//python/config_settings:distribution",
3940
"//python/constraints:distribution",

python/api/BUILD.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16+
17+
package(
18+
default_visibility = ["//:__subpackages__"],
19+
)
20+
21+
bzl_library(
22+
name = "api_bzl",
23+
srcs = ["api.bzl"],
24+
visibility = ["//visibility:public"],
25+
deps = ["//python/private/api:api_bzl"],
26+
)
27+
28+
filegroup(
29+
name = "distribution",
30+
srcs = glob(["**"]),
31+
)

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