Skip to content

Commit 7cd6fbe

Browse files
committed
Merge branch 'main' of https://github.com/bazelbuild/rules_python into refactor.nothing.in.common
2 parents 83bf7af + 5978390 commit 7cd6fbe

33 files changed

+999
-543
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, execute
66
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
7-
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
8-
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
7+
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
8+
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered
99

1010
test --test_output=errors
1111

CHANGELOG.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ 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+
* **BREAKING** `py_library` no longer puts its source files or generated pyc
29+
files in runfiles; it's the responsibility of consumers (e.g. binaries) to
30+
populate runfiles with the necessary files. Adding source files to runfiles
31+
can be temporarily restored by setting {obj}`--add_srcs_to_runfiles=enabled`,
32+
but this flag will be removed in a subsequent releases.
33+
* {obj}`PyInfo.transitive_sources` is now added to runfiles. These files are
34+
`.py` files that are required to be added to runfiles by downstream binaries
35+
(or equivalent).
2836
* (toolchains) `py_runtime.implementation_name` now defaults to `cpython`
2937
(previously it defaulted to None).
38+
* (deps) stardoc 0.6.2 added as dependency.
3039

3140
### Fixed
3241
* (bzlmod) The `python.override(minor_mapping)` now merges the default and the
@@ -47,6 +56,13 @@ A brief description of the categories of changes:
4756
* (rules) `compile_pip_requirements` passes `env` to the `X.update` target (and
4857
not only to the `X_test` target, a bug introduced in
4958
[#1067](https://github.com/bazelbuild/rules_python/pull/1067)).
59+
* (bzlmod) In hybrid bzlmod with WORKSPACE builds,
60+
`python_register_toolchains(register_toolchains=True)` is respected
61+
([#1675](https://github.com/bazelbuild/rules_python/issues/1675)).
62+
* (precompiling) The {obj}`pyc_collection` attribute now correctly
63+
enables (or disables) using pyc files from targets transitively
64+
* (pip) Skip patching wheels not matching `pip.override`'s `file`
65+
([#2294](https://github.com/bazelbuild/rules_python/pull/2294)).
5066

5167
### Added
5268
* (py_wheel) Now supports `compress = (True|False)` to allow disabling
@@ -63,12 +79,20 @@ A brief description of the categories of changes:
6379
* `3.10 -> 3.10.15`
6480
* `3.11 -> 3.11.10`
6581
* `3.12 -> 3.12.7`
66-
[20241008]: https://github.com/indygreg/python-build-standalone/releases/tag/20241008
6782
* (coverage) Add support for python 3.13 and bump `coverage.py` to 7.6.1.
83+
* (bzlmod) Add support for `download_only` flag to disable usage of `sdists`
84+
when {bzl:attr}`pip.parse.experimental_index_url` is set.
85+
* (api) PyInfo fields: {obj}`PyInfo.transitive_implicit_pyc_files`,
86+
{obj}`PyInfo.transitive_implicit_pyc_source_files`.
6887

88+
[20241008]: https://github.com/indygreg/python-build-standalone/releases/tag/20241008
6989

7090
### Removed
71-
* Nothing yet
91+
* (precompiling) {obj}`--precompile_add_to_runfiles` has been removed.
92+
* (precompiling) {obj}`--pyc_collection` has been removed. The `pyc_collection`
93+
attribute now bases its default on {obj}`--precompile`.
94+
* (precompiling) The {obj}`precompile=if_generated_source` value has been removed.
95+
* (precompiling) The {obj}`precompile_source_retention=omit_if_generated_source` value has been removed.
7296

7397
## [0.36.0] - 2024-09-24
7498

MODULE.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ pip.parse(
6666
)
6767
use_repo(pip, "rules_python_publish_deps")
6868

69+
# Not a dev dependency to allow usage of //sphinxdocs code, which refers to stardoc repos.
70+
bazel_dep(name = "stardoc", version = "0.6.2", repo_name = "io_bazel_stardoc")
71+
6972
# ===== DEV ONLY DEPS AND SETUP BELOW HERE =====
70-
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
7173
bazel_dep(name = "rules_bazel_integration_test", version = "0.20.0", dev_dependency = True)
7274
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
7375

@@ -91,6 +93,7 @@ dev_pip = use_extension(
9193
dev_dependency = True,
9294
)
9395
dev_pip.parse(
96+
download_only = True, # this will not add the `sdist` values to the transitive closures at all.
9497
hub_name = "dev_pip",
9598
python_version = "3.11",
9699
requirements_lock = "//docs:requirements.txt",

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

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55

66
# //python/config_settings
77

8+
:::{bzl:flag} add_srcs_to_runfiles
9+
Determines if the `srcs` of targets are added to their runfiles.
10+
11+
More specifically, the sources added to runfiles are the `.py` files in `srcs`.
12+
If precompiling is performed, it is the `.py` files that are kept according
13+
to {obj}`precompile_source_retention`.
14+
15+
Values:
16+
* `auto`: (default) Automatically decide the effective value; the current
17+
behavior is `disabled`.
18+
* `disabled`: Don't add `srcs` to a target's runfiles.
19+
* `enabled`: Add `srcs` to a target's runfiles.
20+
::::{versionadded} 0.37.0
21+
::::
22+
::::{deprecated} 0.37.0
23+
This is a transition flag and will be removed in a subsequent release.
24+
::::
25+
:::
26+
827
:::{bzl:flag} python_version
928
Determines the default hermetic Python toolchain version. This can be set to
1029
one of the values that `rules_python` maintains.
@@ -42,12 +61,8 @@ Values:
4261

4362
* `auto`: (default) Automatically decide the effective value based on environment,
4463
target platform, etc.
45-
* `enabled`: Compile Python source files at build time. Note that
46-
{bzl:obj}`--precompile_add_to_runfiles` affects how the compiled files are included into
47-
a downstream binary.
64+
* `enabled`: Compile Python source files at build time.
4865
* `disabled`: Don't compile Python source files at build time.
49-
* `if_generated_source`: Compile Python source files, but only if they're a
50-
generated file.
5166
* `force_enabled`: Like `enabled`, except overrides target-level setting. This
5267
is mostly useful for development, testing enabling precompilation more
5368
broadly, or as an escape hatch if build-time compiling is not available.
@@ -56,6 +71,9 @@ Values:
5671
broadly, or as an escape hatch if build-time compiling is not available.
5772
:::{versionadded} 0.33.0
5873
:::
74+
:::{versionchanged} 0.37.0
75+
The `if_generated_source` value was removed
76+
:::
5977
::::
6078

6179
::::{bzl:flag} precompile_source_retention
@@ -73,45 +91,14 @@ Values:
7391
target platform, etc.
7492
* `keep_source`: Include the original Python source.
7593
* `omit_source`: Don't include the orignal py source.
76-
* `omit_if_generated_source`: Keep the original source if it's a regular source
77-
file, but omit it if it's a generated file.
7894

7995
:::{versionadded} 0.33.0
8096
:::
8197
:::{versionadded} 0.36.0
8298
The `auto` value
8399
:::
84-
::::
85-
86-
::::{bzl:flag} precompile_add_to_runfiles
87-
Determines if a target adds its compiled files to its runfiles.
88-
89-
When a target compiles its files, but doesn't add them to its own runfiles, it
90-
relies on a downstream target to retrieve them from
91-
{bzl:obj}`PyInfo.transitive_pyc_files`
92-
93-
Values:
94-
* `always`: Always include the compiled files in the target's runfiles.
95-
* `decided_elsewhere`: Don't include the compiled files in the target's
96-
runfiles; they are still added to {bzl:obj}`PyInfo.transitive_pyc_files`. See
97-
also: {bzl:obj}`py_binary.pyc_collection` attribute. This is useful for allowing
98-
incrementally enabling precompilation on a per-binary basis.
99-
:::{versionadded} 0.33.0
100-
:::
101-
::::
102-
103-
::::{bzl:flag} pyc_collection
104-
Determine if `py_binary` collects transitive pyc files.
105-
106-
:::{note}
107-
This flag is overridden by the target level `pyc_collection` attribute.
108-
:::
109-
110-
Values:
111-
* `include_pyc`: Include `PyInfo.transitive_pyc_files` as part of the binary.
112-
* `disabled`: Don't include `PyInfo.transitive_pyc_files` as part of the binary.
113-
:::{versionadded} 0.33.0
114-
:::
100+
:::{versionchanged} 0.37.0
101+
The `omit_if_generated_source` value was removed
115102
::::
116103

117104
::::{bzl:flag} py_linux_libc

docs/precompiling.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ While precompiling helps runtime performance, it has two main costs:
2020

2121
## Binary-level opt-in
2222

23-
Because of the costs of precompiling, it may not be feasible to globally enable it
24-
for your repo for everything. For example, some binaries may be
25-
particularly large, and doubling the number of runfiles isn't doable.
23+
Binary-level opt-in allows enabling precompiling on a per-target basic. This is
24+
useful for situations such as:
2625

27-
If this is the case, there's an alternative way to more selectively and
28-
incrementally control precompiling on a per-binry basis.
26+
* Globally enabling precompiling in your `.bazelrc` isn't feasible. This may
27+
be because some targets don't work with precompiling, e.g. because they're too
28+
big.
29+
* Enabling precompiling for build tools (exec config targets) separately from
30+
target-config programs.
2931

30-
To use this approach, the two basic steps are:
31-
1. Disable pyc files from being automatically added to runfiles:
32-
{bzl:obj}`--@rules_python//python/config_settings:precompile_add_to_runfiles=decided_elsewhere`,
33-
2. Set the `pyc_collection` attribute on the binaries/tests that should or should
34-
not use precompiling.
32+
To use this approach, set the {bzl:attr}`pyc_collection` attribute on the
33+
binaries/tests that should or should not use precompiling. Then change the
34+
{bzl:flag}`--precompile` default.
3535

36-
The default for the `pyc_collection` attribute is controlled by the flag
37-
{bzl:obj}`--@rules_python//python/config_settings:pyc_collection`, so you
36+
The default for the {bzl:attr}`pyc_collection` attribute is controlled by the flag
37+
{bzl:obj}`--@rules_python//python/config_settings:precompile`, so you
3838
can use an opt-in or opt-out approach by setting its value:
39-
* targets must opt-out: `--@rules_python//python/config_settings:pyc_collection=include_pyc`
40-
* targets must opt-in: `--@rules_python//python/config_settings:pyc_collection=disabled`
39+
* targets must opt-out: `--@rules_python//python/config_settings:precompile=enabled`
40+
* targets must opt-in: `--@rules_python//python/config_settings:precompile=disabled`
4141

4242
## Advanced precompiler customization
4343

@@ -48,7 +48,7 @@ not work as well for remote execution builds. To customize the precompiler, two
4848
mechanisms are available:
4949

5050
* The exec tools toolchain allows customizing the precompiler binary used with
51-
the `precompiler` attribute. Arbitrary binaries are supported.
51+
the {bzl:attr}`precompiler` attribute. Arbitrary binaries are supported.
5252
* The execution requirements can be customized using
5353
`--@rules_python//tools/precompiler:execution_requirements`. This is a list
5454
flag that can be repeated. Each entry is a key=value that is added to the
@@ -92,3 +92,9 @@ Note that any execution requirements values can be specified in the flag.
9292
`foo.cpython-39.opt-2.pyc`). This works fine (it's all byte code), but also
9393
means the interpreter `-O` argument can't be used -- doing so will cause the
9494
interpreter to look for the non-existent `opt-N` named files.
95+
* Targets with the same source files and different exec properites will result
96+
in action conflicts. This most commonly occurs when a `py_binary` and
97+
`py_library` have the same source files. To fix, modify both targets so
98+
they have the same exec properties. If this is difficult because unsupported
99+
exec groups end up being passed to the Python rules, please file an issue
100+
to have those exec groups added to the Python rules.

0 commit comments

Comments
 (0)