Skip to content

Commit 37c9386

Browse files
authored
Merge branch 'main' into resolve-rel-imports
2 parents 2d771df + 9f3512f commit 37c9386

File tree

70 files changed

+2773
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2773
-185
lines changed

.bazelci/presubmit.yml

+2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ buildifier:
5151
test_flags:
5252
- "--noenable_bzlmod"
5353
- "--enable_workspace"
54+
- "--test_tag_filters=-integration-test"
5455
build_flags:
5556
- "--noenable_bzlmod"
5657
- "--enable_workspace"
58+
- "--build_tag_filters=-integration-test"
5759
bazel: 7.x
5860
.common_bazelinbazel_config: &common_bazelinbazel_config
5961
build_flags:

.bazelrc

+2-2
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,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
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,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
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,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
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,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
99

1010
test --test_output=errors
1111

.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Unix-style newlines with a newline ending every file
2+
[*]
3+
end_of_line = lf
4+
insert_final_newline = true
5+
6+
# Set default charset
7+
[*]
8+
charset = utf-8
9+
10+
# Line width
11+
[*]
12+
max_line_length = 100
13+
14+
# 4 space indentation
15+
[*.{py,bzl}]
16+
indent_style = space
17+
indent_size = 4

CHANGELOG.md

+21-9
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,22 @@ END_UNRELEASED_TEMPLATE
5454

5555
{#v0-0-0-changed}
5656
### Changed
57+
58+
* If using the (deprecated) autodetecting/runtime_env toolchain, then the Python
59+
version specified at build-time *must* match the Python version used at
60+
runtime (the {obj}`--@rules_python//python/config_settings:python_version`
61+
flag and the {attr}`python_version` attribute control the build-time version
62+
for a target). If they don't match, dependencies won't be importable. (Such a
63+
misconfiguration was unlikely to work to begin with; this is called out as an
64+
FYI).
65+
* (rules) {obj}`--bootstrap_impl=script` is the default for non-Windows.
5766
* (rules) On Windows, {obj}`--bootstrap_impl=system_python` is forced. This
5867
allows setting `--bootstrap_impl=script` in bazelrc for mixed-platform
5968
environments.
6069
* (rules) {obj}`pip_compile` now generates a `.test` target. The `_test` target is deprecated
6170
and will be removed in the next major release.
6271
([#2794](https://github.com/bazel-contrib/rules_python/issues/2794)
72+
* (py_wheel) py_wheel always creates zip64-capable wheel zips
6373

6474
{#v0-0-0-fixed}
6575
### Fixed
@@ -74,12 +84,19 @@ END_UNRELEASED_TEMPLATE
7484
* The {obj}`//python/runtime_env_toolchains:all` toolchain now works with it.
7585
* (rules) Better handle flakey platform.win32_ver() calls by calling them
7686
multiple times.
87+
* (tools/wheelmaker.py) Extras are now preserved in Requires-Dist metadata when using requires_file
88+
to specify the requirements.
7789

7890
{#v0-0-0-added}
7991
### Added
8092
* Repo utilities `execute_unchecked`, `execute_checked`, and `execute_checked_stdout` now
8193
support `log_stdout` and `log_stderr` keyword arg booleans. When these are `True`
8294
(the default), the subprocess's stdout/stderr will be logged.
95+
* (toolchains) Local toolchains can be activated with custom flags. See
96+
[Conditionally using local toolchains] docs for how to configure.
97+
* (pypi) `RULES_PYTHON_ENABLE_PIPSTAR` environment variable: when `1`, the Starlark
98+
implementation of wheel METADATA parsing is used (which has improved multi-platform
99+
build support).
83100

84101
{#v0-0-0-removed}
85102
### Removed
@@ -103,8 +120,6 @@ END_UNRELEASED_TEMPLATE
103120
* 3.12.9
104121
* 3.13.2
105122
* (pypi) Use `xcrun xcodebuild --showsdks` to find XCode root.
106-
* (pypi) The `bzlmod` extension will now generate smaller lock files for when
107-
using `experimental_index_url`.
108123
* (toolchains) Remove all but `3.8.20` versions of the Python `3.8` interpreter who has
109124
reached EOL. If users still need other versions of the `3.8` interpreter, please supply
110125
the URLs manually {bzl:obj}`python.toolchain` or {bzl:obj}`python_register_toolchains` calls.
@@ -120,13 +135,6 @@ END_UNRELEASED_TEMPLATE
120135
[PR #2746](https://github.com/bazel-contrib/rules_python/pull/2746).
121136
* (rules) {attr}`py_binary.srcs` and {attr}`py_test.srcs` is no longer mandatory when
122137
`main_module` is specified (for `--bootstrap_impl=script`)
123-
* (pypi) From now on the `Requires-Dist` from the wheel metadata is analysed in
124-
the loading phase instead of repository rule phase giving better caching
125-
performance when the target platforms are changed (e.g. target python
126-
versions). This is preparatory work for stabilizing the cross-platform wheel
127-
support. From now on the usage of `experimental_target_platforms` should be
128-
avoided and the `requirements_by_platform` values should be instead used to
129-
specify the target platforms for the given dependencies.
130138

131139
[20250317]: https://github.com/astral-sh/python-build-standalone/releases/tag/20250317
132140

@@ -151,6 +159,10 @@ END_UNRELEASED_TEMPLATE
151159
* (pypi) Correctly handle `METADATA` entries when `python_full_version` is used in
152160
the environment marker.
153161
Fixes [#2319](https://github.com/bazel-contrib/rules_python/issues/2319).
162+
* (pypi) Correctly handle `python_version` parameter and transition the requirement
163+
locking to the right interpreter version when using
164+
{obj}`compile_pip_requirements` rule.
165+
See [#2819](https://github.com/bazel-contrib/rules_python/pull/2819).
154166

155167
{#1-4-0-added}
156168
### Added

CONTRIBUTING.md

+49
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,55 @@ The `legacy_foo` arg was removed
173173
:::
174174
```
175175

176+
## Style and idioms
177+
178+
For the most part, we just accept whatever the code formatters do, so there
179+
isn't much style to enforce.
180+
181+
Some miscellanous style, idioms, and conventions we have are:
182+
183+
### Markdown/Sphinx Style
184+
185+
* Use colons for prose sections of text, e.g. `:::{note}`, not backticks.
186+
* Use backticks for code blocks.
187+
* Max line length: 100.
188+
189+
### BUILD/bzl Style
190+
191+
* When a macro generates public targets, use a dot (`.`) to separate the
192+
user-provided name from the generted name. e.g. `foo(name="x")` generates
193+
`x.test`. The `.` is our convention to communicate that it's a generated
194+
target, and thus one should look for `name="x"` when searching for the
195+
definition.
196+
* The different build phases shouldn't load code that defines objects that
197+
aren't valid for their phase. e.g.
198+
* The bzlmod phase shouldn't load code defining regular rules or providers.
199+
* The repository phase shouldn't load code defining module extensions, regular
200+
rules, or providers.
201+
* The loading phase shouldn't load code defining module extensions or
202+
repository rules.
203+
* Loading utility libraries or generic code is OK, but should strive to load
204+
code that is usable for its phase. e.g. loading-phase code shouldn't
205+
load utility code that is predominately only usable to the bzlmod phase.
206+
* Providers should be in their own files. This allows implementing a custom rule
207+
that implements the provider without loading a specific implementation.
208+
* One rule per file is preferred, but not required. The goal is that defining an
209+
e.g. library shouldn't incur loading all the code for binaries, tests,
210+
packaging, etc; things that may be niche or uncommonly used.
211+
* Separate files should be used to expose public APIs. This ensures our public
212+
API is well defined and prevents accidentally exposing a package-private
213+
symbol as a public symbol.
214+
215+
:::{note}
216+
The public API file's docstring becomes part of the user-facing docs. That
217+
file's docstring must be used for module-level API documentation.
218+
:::
219+
* Repository rules should have name ending in `_repo`. This helps distinguish
220+
them from regular rules.
221+
* Each bzlmod extension, the "X" of `use_repo("//foo:foo.bzl", "X")` should be
222+
in its own file. The path given in the `use_repo()` expression is the identity
223+
Bazel uses and cannot be changed.
224+
176225
## Generated files
177226

178227
Some checked-in files are generated and need to be updated when a new PR is

MODULE.bazel

+6-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ internal_dev_deps = use_extension(
9898
"internal_dev_deps",
9999
dev_dependency = True,
100100
)
101-
use_repo(internal_dev_deps, "buildkite_config", "wheel_for_testing")
101+
use_repo(
102+
internal_dev_deps,
103+
"buildkite_config",
104+
"rules_python_runtime_env_tc_info",
105+
"wheel_for_testing",
106+
)
102107

103108
# Add gazelle plugin so that we can run the gazelle example as an e2e integration
104109
# test and include the distribution files.

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

+21
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ Values:
159159
:::
160160
::::
161161

162+
::::{bzl:flag} pip_env_marker_config
163+
The target that provides the values for pip env marker evaluation.
164+
165+
Default: `//python/config_settings:_pip_env_marker_default_config`
166+
167+
This flag points to a target providing {obj}`EnvMarkerInfo`, which determines
168+
the values used when environment markers are resolved at build time.
169+
170+
:::{versionadded} VERSION_NEXT_FEATURE
171+
:::
172+
::::
173+
162174
::::{bzl:flag} pip_whl
163175
Set what distributions are used in the `pip` integration.
164176

@@ -233,6 +245,10 @@ Values:
233245
::::{bzl:flag} bootstrap_impl
234246
Determine how programs implement their startup process.
235247

248+
The default for this depends on the platform:
249+
* Windows: `system_python` (**always** used)
250+
* Other: `script`
251+
236252
Values:
237253
* `system_python`: Use a bootstrap that requires a system Python available
238254
in order to start programs. This requires
@@ -257,6 +273,11 @@ instead.
257273
:::{versionadded} 0.33.0
258274
:::
259275

276+
:::{versionchanged} VERSION_NEXT_FEATURE
277+
* The default for non-Windows changed from `system_python` to `script`.
278+
* On Windows, the value is forced to `system_python`.
279+
:::
280+
260281
::::
261282

262283
::::{bzl:flag} current_config

docs/environment-variables.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,28 @@ When `1`, the rules_python will warn users about deprecated functionality that w
4646
be removed in a subsequent major `rules_python` version. Defaults to `0` if unset.
4747
:::
4848

49-
:::{envvar} RULES_PYTHON_ENABLE_PYSTAR
49+
::::{envvar} RULES_PYTHON_ENABLE_PYSTAR
5050

5151
When `1`, the rules_python Starlark implementation of the core rules is used
52-
instead of the Bazel-builtin rules. Note this requires Bazel 7+.
52+
instead of the Bazel-builtin rules. Note this requires Bazel 7+. Defaults
53+
to `1`.
54+
55+
:::{versionadded} 0.26.0
56+
Defaults to `0` if unspecified.
57+
:::
58+
:::{versionchanged} 0.40.0
59+
The default became `1` if unspecified
60+
:::
61+
::::
62+
63+
::::{envvar} RULES_PYTHON_ENABLE_PIPSTAR
64+
65+
When `1`, the rules_python Starlark implementation of the pypi/pip integration is used
66+
instead of the legacy Python scripts.
67+
68+
:::{versionadded} VERSION_NEXT_FEATURE
5369
:::
70+
::::
5471

5572
::::{envvar} RULES_PYTHON_EXTRACT_ROOT
5673

docs/pypi-dependencies.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ leg of the dependency manually. For instance by making
338338
perhaps `apache-airflow-providers-common-sql`.
339339

340340

341-
(bazel-downloader)=
342341
### Multi-platform support
343342

344343
Multi-platform support of cross-building the wheels can be done in two ways - either
@@ -391,6 +390,31 @@ compatible indexes.
391390
This is only supported on `bzlmd`.
392391
```
393392

393+
<!--
394+
395+
TODO: uncomment this when analysis-phase dependency selection is available
396+
397+
#### Customizing requirements resolution
398+
399+
In Python packaging, packages can express dependencies with conditions
400+
using "environment markers", which represent the Python version, OS, etc.
401+
402+
While the PyPI integration provides reasonable defaults to support most
403+
platforms and environment markers, the values it uses can be customized in case
404+
more esoteric configurations are needed.
405+
406+
To customize the values used, you need to do two things:
407+
1. Define a target that returns {obj}`EnvMarkerInfo`
408+
2. Set the {obj}`//python/config_settings:pip_env_marker_config` flag to
409+
the target defined in (1).
410+
411+
The keys and values should be compatible with the [PyPA dependency specifiers
412+
specification](https://packaging.python.org/en/latest/specifications/dependency-specifiers/).
413+
This is not strictly enforced, however, so you can return a subset of keys or
414+
additional keys, which become available during dependency evalution.
415+
416+
-->
417+
394418
(bazel-downloader)=
395419
### Bazel downloader and multi-platform wheel hub repository.
396420

@@ -487,3 +511,9 @@ Bazel will call this file like `cred_helper.sh get` and use the returned JSON to
487511
into whatever HTTP(S) request it performs against `example.com`.
488512

489513
[rfc7617]: https://datatracker.ietf.org/doc/html/rfc7617
514+
515+
<!--
516+
517+
518+
519+
-->

0 commit comments

Comments
 (0)