Skip to content

Commit 991907c

Browse files
committed
Merge branch 'main' of https://github.com/bazel-contrib/rules_python into sphinxdocs.special.case.any.object
2 parents f3fd91a + 8e6f73b commit 991907c

File tree

13 files changed

+131
-109
lines changed

13 files changed

+131
-109
lines changed

CHANGELOG.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ END_UNRELEASED_TEMPLATE
6666
* (rules) On Windows, {obj}`--bootstrap_impl=system_python` is forced. This
6767
allows setting `--bootstrap_impl=script` in bazelrc for mixed-platform
6868
environments.
69-
* (rules) {obj}`pip_compile` now generates a `.test` target. The `_test` target is deprecated
70-
and will be removed in the next major release.
69+
* (rules) {obj}`compile_pip_requirements` now generates a `.test` target. The
70+
`_test` target is deprecated and will be removed in the next major release.
7171
([#2794](https://github.com/bazel-contrib/rules_python/issues/2794)
7272
* (py_wheel) py_wheel always creates zip64-capable wheel zips
7373

@@ -190,7 +190,7 @@ END_UNRELEASED_TEMPLATE
190190
packages through SimpleAPI unless they are pulled through direct URL
191191
references. Fixes [#2023](https://github.com/bazel-contrib/rules_python/issues/2023).
192192
In case you see issues with `rules_python` being too eager to fetch the SimpleAPI
193-
metadata, you can use the newly added {attr}`pip.parse.experimental_skip_sources`
193+
metadata, you can use the newly added {attr}`pip.parse.simpleapi_skip`
194194
to skip metadata fetching for those packages.
195195
* (uv) A {obj}`lock` rule that is the replacement for the
196196
{obj}`compile_pip_requirements`. This may still have rough corners
@@ -251,7 +251,7 @@ END_UNRELEASED_TEMPLATE
251251

252252
{#v1-3-0-added}
253253
### Added
254-
* (python) {attr}`python.defaults` has been added to allow users to
254+
* (python) {obj}`python.defaults` has been added to allow users to
255255
set the default python version in the root module by reading the
256256
default version number from a file or an environment variable.
257257
* {obj}`//python/bin:python`: convenience target for directly running an
@@ -271,7 +271,7 @@ END_UNRELEASED_TEMPLATE
271271
and py_library rules
272272
([#1647](https://github.com/bazel-contrib/rules_python/issues/1647))
273273
* (rules) Added env-var to allow additional interpreter args for stage1 bootstrap.
274-
See {obj}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable.
274+
See {any}`RULES_PYTHON_ADDITIONAL_INTERPRETER_ARGS` environment variable.
275275
Only applicable for {obj}`--bootstrap_impl=script`.
276276
* (rules) Added {obj}`interpreter_args` attribute to `py_binary` and `py_test`,
277277
which allows pass arguments to the interpreter before the regular args.
@@ -377,7 +377,7 @@ END_UNRELEASED_TEMPLATE
377377
values. Fixes [#2466](https://github.com/bazel-contrib/rules_python/issues/2466).
378378
* (py_proto_library) Fix import paths in Bazel 8.
379379
* (whl_library) Now the changes to the dependencies are correctly tracked when
380-
PyPI packages used in {bzl:obj}`whl_library` during the `repository_rule` phase
380+
PyPI packages used in `whl_library` during the repository rule phase
381381
change. Fixes [#2468](https://github.com/bazel-contrib/rules_python/issues/2468).
382382
+ (gazelle) Gazelle no longer ignores `setup.py` files by default. To restore
383383
this behavior, apply the `# gazelle:python_ignore_files setup.py` directive.
@@ -396,7 +396,7 @@ END_UNRELEASED_TEMPLATE
396396
* (pypi) Freethreaded packages are now fully supported in the
397397
{obj}`experimental_index_url` usage or the regular `pip.parse` usage.
398398
To select the free-threaded interpreter in the repo phase, please use
399-
the documented [env](/environment-variables.html) variables.
399+
the documented [env](environment-variables) variables.
400400
Fixes [#2386](https://github.com/bazel-contrib/rules_python/issues/2386).
401401
* (toolchains) Use the latest astrahl-sh toolchain release [20241206] for Python versions:
402402
* 3.9.21
@@ -490,7 +490,7 @@ Other changes:
490490
for the latest toolchain versions for each minor Python version. You can control
491491
the toolchain selection by using the
492492
{bzl:obj}`//python/config_settings:py_linux_libc` build flag.
493-
* (providers) Added {obj}`py_runtime_info.site_init_template` and
493+
* (providers) Added {obj}`PyRuntimeInfo.site_init_template` and
494494
{obj}`PyRuntimeInfo.site_init_template` for specifying the template to use to
495495
initialize the interpreter via venv startup hooks.
496496
* (runfiles) (Bazel 7.4+) Added support for spaces and newlines in runfiles paths
@@ -688,8 +688,8 @@ Other changes:
688688
* (bzlmod) The default value for the {obj}`--python_version` flag will now be
689689
always set to the default python toolchain version value.
690690
* (bzlmod) correctly wire the {attr}`pip.parse.extra_pip_args` all the
691-
way to {obj}`whl_library`. What is more we will pass the `extra_pip_args` to
692-
{obj}`whl_library` for `sdist` distributions when using
691+
way to `whl_library`. What is more we will pass the `extra_pip_args` to
692+
`whl_library` for `sdist` distributions when using
693693
{attr}`pip.parse.experimental_index_url`. See
694694
[#2239](https://github.com/bazel-contrib/rules_python/issues/2239).
695695
* (whl_filegroup): Provide per default also the `RECORD` file
@@ -737,8 +737,8 @@ Other changes:
737737

738738
{#v0-37-0-removed}
739739
### Removed
740-
* (precompiling) {obj}`--precompile_add_to_runfiles` has been removed.
741-
* (precompiling) {obj}`--pyc_collection` has been removed. The `pyc_collection`
740+
* (precompiling) `--precompile_add_to_runfiles` has been removed.
741+
* (precompiling) `--pyc_collection` has been removed. The `pyc_collection`
742742
attribute now bases its default on {obj}`--precompile`.
743743
* (precompiling) The {obj}`precompile=if_generated_source` value has been removed.
744744
* (precompiling) The {obj}`precompile_source_retention=omit_if_generated_source` value has been removed.
@@ -790,7 +790,7 @@ Other changes:
790790
in extra_requires in py_wheel rule.
791791
* (rules) Prevent pytest from trying run the generated stage2
792792
bootstrap .py file when using {obj}`--bootstrap_impl=script`
793-
* (toolchain) The {bzl:obj}`gen_python_config_settings` has been fixed to include
793+
* (toolchain) The `gen_python_config_settings` has been fixed to include
794794
the flag_values from the platform definitions.
795795

796796
{#v0-36-0-added}
@@ -1205,9 +1205,9 @@ Other changes:
12051205
depend on legacy labels instead of the hub repo aliases and you use the
12061206
`experimental_requirement_cycles`, now is a good time to migrate.
12071207

1208-
[python_default_visibility]: gazelle/README.md#directive-python_default_visibility
1208+
[python_default_visibility]: https://github.com/bazel-contrib/rules_python/tree/main/gazelle/README.md#directive-python_default_visibility
12091209
[test_file_pattern_issue]: https://github.com/bazel-contrib/rules_python/issues/1816
1210-
[test_file_pattern_docs]: gazelle/README.md#directive-python_test_file_pattern
1210+
[test_file_pattern_docs]: https://github.com/bazel-contrib/rules_python/tree/main/gazelle/README.md#directive-python_test_file_pattern
12111211
[20240224]: https://github.com/indygreg/python-build-standalone/releases/tag/20240224.
12121212
[20240415]: https://github.com/indygreg/python-build-standalone/releases/tag/20240415.
12131213

tests/bootstrap_impls/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ load("@rules_shell//shell:sh_test.bzl", "sh_test")
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_binary", "py_reconfig_test", "sh_py_run_test")
16+
load("//tests/support:py_reconfig.bzl", "py_reconfig_binary", "py_reconfig_test")
17+
load("//tests/support:sh_py_run_test.bzl", "sh_py_run_test")
1718
load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT")
1819
load(":venv_relative_path_tests.bzl", "relative_path_test_suite")
1920

tests/bootstrap_impls/a/b/c/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
2-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
2+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
33

44
_SUPPORTS_BOOTSTRAP_SCRIPT = select({
55
"@platforms//os:windows": ["@platforms//:incompatible"],

tests/interpreter/interpreter_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""This file contains helpers for testing the interpreter rule."""
1616

17-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
17+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
1818

1919
# The versions of Python that we want to run the interpreter tests against.
2020
PYTHON_VERSIONS_TO_TEST = (

tests/no_unsafe_paths/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
14+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
1515
load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT")
1616

1717
py_reconfig_test(

tests/packaging/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
load("@bazel_skylib//rules:build_test.bzl", "build_test")
1616
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
17-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
17+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
1818
load("//tests/support:support.bzl", "SUPPORTS_BOOTSTRAP_SCRIPT")
1919

2020
build_test(

tests/repl/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//python:py_library.bzl", "py_library")
2-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
2+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
33

44
# A library that adds a special import path only when this is specified as a
55
# dependency. This makes it easy for a dependency to have this import path

tests/runtime_env_toolchain/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
load("@rules_python_runtime_env_tc_info//:info.bzl", "PYTHON_VERSION")
16-
load("//tests/support:sh_py_run_test.bzl", "py_reconfig_test")
16+
load("//tests/support:py_reconfig.bzl", "py_reconfig_test")
1717
load("//tests/support:support.bzl", "CC_TOOLCHAIN")
1818
load(":runtime_env_toolchain_tests.bzl", "runtime_env_toolchain_test_suite")
1919

tests/support/py_reconfig.bzl

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
"""Run a py_binary/py_test with altered config settings.
15+
16+
This facilitates verify running binaries with different configuration settings
17+
without the overhead of a bazel-in-bazel integration test.
18+
"""
19+
20+
load("//python/private:attr_builders.bzl", "attrb") # buildifier: disable=bzl-visibility
21+
load("//python/private:py_binary_macro.bzl", "py_binary_macro") # buildifier: disable=bzl-visibility
22+
load("//python/private:py_binary_rule.bzl", "create_py_binary_rule_builder") # buildifier: disable=bzl-visibility
23+
load("//python/private:py_test_macro.bzl", "py_test_macro") # buildifier: disable=bzl-visibility
24+
load("//python/private:py_test_rule.bzl", "create_py_test_rule_builder") # buildifier: disable=bzl-visibility
25+
load("//tests/support:support.bzl", "VISIBLE_FOR_TESTING")
26+
27+
def _perform_transition_impl(input_settings, attr, base_impl):
28+
settings = {k: input_settings[k] for k in _RECONFIG_INHERITED_OUTPUTS if k in input_settings}
29+
settings.update(base_impl(input_settings, attr))
30+
31+
settings[VISIBLE_FOR_TESTING] = True
32+
settings["//command_line_option:build_python_zip"] = attr.build_python_zip
33+
if attr.bootstrap_impl:
34+
settings["//python/config_settings:bootstrap_impl"] = attr.bootstrap_impl
35+
if attr.extra_toolchains:
36+
settings["//command_line_option:extra_toolchains"] = attr.extra_toolchains
37+
if attr.python_src:
38+
settings["//python/bin:python_src"] = attr.python_src
39+
if attr.repl_dep:
40+
settings["//python/bin:repl_dep"] = attr.repl_dep
41+
if attr.venvs_use_declare_symlink:
42+
settings["//python/config_settings:venvs_use_declare_symlink"] = attr.venvs_use_declare_symlink
43+
if attr.venvs_site_packages:
44+
settings["//python/config_settings:venvs_site_packages"] = attr.venvs_site_packages
45+
return settings
46+
47+
_RECONFIG_INPUTS = [
48+
"//python/config_settings:bootstrap_impl",
49+
"//python/bin:python_src",
50+
"//python/bin:repl_dep",
51+
"//command_line_option:extra_toolchains",
52+
"//python/config_settings:venvs_use_declare_symlink",
53+
"//python/config_settings:venvs_site_packages",
54+
]
55+
_RECONFIG_OUTPUTS = _RECONFIG_INPUTS + [
56+
"//command_line_option:build_python_zip",
57+
VISIBLE_FOR_TESTING,
58+
]
59+
_RECONFIG_INHERITED_OUTPUTS = [v for v in _RECONFIG_OUTPUTS if v in _RECONFIG_INPUTS]
60+
61+
_RECONFIG_ATTRS = {
62+
"bootstrap_impl": attrb.String(),
63+
"build_python_zip": attrb.String(default = "auto"),
64+
"extra_toolchains": attrb.StringList(
65+
doc = """
66+
Value for the --extra_toolchains flag.
67+
68+
NOTE: You'll likely have to also specify //tests/support/cc_toolchains:all (or some CC toolchain)
69+
to make the RBE presubmits happy, which disable auto-detection of a CC
70+
toolchain.
71+
""",
72+
),
73+
"python_src": attrb.Label(),
74+
"repl_dep": attrb.Label(),
75+
"venvs_site_packages": attrb.String(),
76+
"venvs_use_declare_symlink": attrb.String(),
77+
}
78+
79+
def _create_reconfig_rule(builder):
80+
builder.attrs.update(_RECONFIG_ATTRS)
81+
82+
base_cfg_impl = builder.cfg.implementation()
83+
builder.cfg.set_implementation(lambda *args: _perform_transition_impl(base_impl = base_cfg_impl, *args))
84+
builder.cfg.update_inputs(_RECONFIG_INPUTS)
85+
builder.cfg.update_outputs(_RECONFIG_OUTPUTS)
86+
return builder.build()
87+
88+
_py_reconfig_binary = _create_reconfig_rule(create_py_binary_rule_builder())
89+
90+
_py_reconfig_test = _create_reconfig_rule(create_py_test_rule_builder())
91+
92+
def py_reconfig_test(**kwargs):
93+
"""Create a py_test with customized build settings for testing.
94+
95+
Args:
96+
**kwargs: kwargs to pass along to _py_reconfig_test.
97+
"""
98+
py_test_macro(_py_reconfig_test, **kwargs)
99+
100+
def py_reconfig_binary(**kwargs):
101+
py_binary_macro(_py_reconfig_binary, **kwargs)

tests/support/sh_py_run_test.bzl

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -13,94 +13,14 @@
1313
# limitations under the License.
1414
"""Run a py_binary with altered config settings in an sh_test.
1515
16-
This facilitates verify running binaries with different configuration settings
17-
without the overhead of a bazel-in-bazel integration test.
16+
This facilitates verify running binaries with different outer environmental
17+
settings and verifying their output without the overhead of a bazel-in-bazel
18+
integration test.
1819
"""
1920

2021
load("@rules_shell//shell:sh_test.bzl", "sh_test")
21-
load("//python/private:attr_builders.bzl", "attrb") # buildifier: disable=bzl-visibility
22-
load("//python/private:py_binary_macro.bzl", "py_binary_macro") # buildifier: disable=bzl-visibility
23-
load("//python/private:py_binary_rule.bzl", "create_py_binary_rule_builder") # buildifier: disable=bzl-visibility
24-
load("//python/private:py_test_macro.bzl", "py_test_macro") # buildifier: disable=bzl-visibility
25-
load("//python/private:py_test_rule.bzl", "create_py_test_rule_builder") # buildifier: disable=bzl-visibility
2622
load("//python/private:toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE") # buildifier: disable=bzl-visibility
27-
load("//tests/support:support.bzl", "VISIBLE_FOR_TESTING")
28-
29-
def _perform_transition_impl(input_settings, attr, base_impl):
30-
settings = {k: input_settings[k] for k in _RECONFIG_INHERITED_OUTPUTS if k in input_settings}
31-
settings.update(base_impl(input_settings, attr))
32-
33-
settings[VISIBLE_FOR_TESTING] = True
34-
settings["//command_line_option:build_python_zip"] = attr.build_python_zip
35-
if attr.bootstrap_impl:
36-
settings["//python/config_settings:bootstrap_impl"] = attr.bootstrap_impl
37-
if attr.extra_toolchains:
38-
settings["//command_line_option:extra_toolchains"] = attr.extra_toolchains
39-
if attr.python_src:
40-
settings["//python/bin:python_src"] = attr.python_src
41-
if attr.repl_dep:
42-
settings["//python/bin:repl_dep"] = attr.repl_dep
43-
if attr.venvs_use_declare_symlink:
44-
settings["//python/config_settings:venvs_use_declare_symlink"] = attr.venvs_use_declare_symlink
45-
if attr.venvs_site_packages:
46-
settings["//python/config_settings:venvs_site_packages"] = attr.venvs_site_packages
47-
return settings
48-
49-
_RECONFIG_INPUTS = [
50-
"//python/config_settings:bootstrap_impl",
51-
"//python/bin:python_src",
52-
"//python/bin:repl_dep",
53-
"//command_line_option:extra_toolchains",
54-
"//python/config_settings:venvs_use_declare_symlink",
55-
"//python/config_settings:venvs_site_packages",
56-
]
57-
_RECONFIG_OUTPUTS = _RECONFIG_INPUTS + [
58-
"//command_line_option:build_python_zip",
59-
VISIBLE_FOR_TESTING,
60-
]
61-
_RECONFIG_INHERITED_OUTPUTS = [v for v in _RECONFIG_OUTPUTS if v in _RECONFIG_INPUTS]
62-
63-
_RECONFIG_ATTRS = {
64-
"bootstrap_impl": attrb.String(),
65-
"build_python_zip": attrb.String(default = "auto"),
66-
"extra_toolchains": attrb.StringList(
67-
doc = """
68-
Value for the --extra_toolchains flag.
69-
70-
NOTE: You'll likely have to also specify //tests/support/cc_toolchains:all (or some CC toolchain)
71-
to make the RBE presubmits happy, which disable auto-detection of a CC
72-
toolchain.
73-
""",
74-
),
75-
"python_src": attrb.Label(),
76-
"repl_dep": attrb.Label(),
77-
"venvs_site_packages": attrb.String(),
78-
"venvs_use_declare_symlink": attrb.String(),
79-
}
80-
81-
def _create_reconfig_rule(builder):
82-
builder.attrs.update(_RECONFIG_ATTRS)
83-
84-
base_cfg_impl = builder.cfg.implementation()
85-
builder.cfg.set_implementation(lambda *args: _perform_transition_impl(base_impl = base_cfg_impl, *args))
86-
builder.cfg.update_inputs(_RECONFIG_INPUTS)
87-
builder.cfg.update_outputs(_RECONFIG_OUTPUTS)
88-
return builder.build()
89-
90-
_py_reconfig_binary = _create_reconfig_rule(create_py_binary_rule_builder())
91-
92-
_py_reconfig_test = _create_reconfig_rule(create_py_test_rule_builder())
93-
94-
def py_reconfig_test(**kwargs):
95-
"""Create a py_test with customized build settings for testing.
96-
97-
Args:
98-
**kwargs: kwargs to pass along to _py_reconfig_test.
99-
"""
100-
py_test_macro(_py_reconfig_test, **kwargs)
101-
102-
def py_reconfig_binary(**kwargs):
103-
py_binary_macro(_py_reconfig_binary, **kwargs)
23+
load(":py_reconfig.bzl", "py_reconfig_binary")
10424

10525
def sh_py_run_test(*, name, sh_src, py_src, **kwargs):
10626
"""Run a py_binary within a sh_test.

0 commit comments

Comments
 (0)