Skip to content

Commit bd0114f

Browse files
authored
Merge branch 'main' into main
2 parents 134750a + 8e76bd4 commit bd0114f

File tree

101 files changed

+3257
-720
lines changed

Some content is hidden

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

101 files changed

+3257
-720
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ examples/pip_parse/bazel-pip_parse
2525
examples/pip_parse_vendored/bazel-pip_parse_vendored
2626
examples/pip_repository_annotations/bazel-pip_repository_annotations
2727
examples/py_proto_library/bazel-py_proto_library
28+
gazelle/bazel-gazelle
2829
tests/integration/compile_pip_requirements/bazel-compile_pip_requirements
2930
tests/integration/ignore_root_user_error/bazel-ignore_root_user_error
3031
tests/integration/local_toolchains/bazel-local_toolchains

.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,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

Lines changed: 17 additions & 0 deletions
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

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ repos:
3838
- --profile
3939
- black
4040
- repo: https://github.com/psf/black
41-
rev: 23.1.0
41+
rev: 25.1.0
4242
hooks:
4343
- id: black
4444
- repo: local

CHANGELOG.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,36 @@ END_UNRELEASED_TEMPLATE
5454

5555
{#v0-0-0-changed}
5656
### Changed
57+
58+
* (rules) On Windows, {obj}`--bootstrap_impl=system_python` is forced. This
59+
allows setting `--bootstrap_impl=script` in bazelrc for mixed-platform
60+
environments.
61+
* (rules) {obj}`pip_compile` now generates a `.test` target. The `_test` target is deprecated
62+
and will be removed in the next major release.
63+
([#2794](https://github.com/bazel-contrib/rules_python/issues/2794)
5764
* (py_wheel) py_wheel always creates zip64-capable wheel zips
5865

5966
{#v0-0-0-fixed}
6067
### Fixed
68+
6169
* (rules) PyInfo provider is now advertised by py_test, py_binary, and py_library;
6270
this allows aspects using required_providers to function correctly.
6371
([#2506](https://github.com/bazel-contrib/rules_python/issues/2506)).
72+
* Fixes when using {obj}`--bootstrap_impl=script`:
73+
* `compile_pip_requirements` now works with it
74+
* The `sys._base_executable` value will reflect the underlying interpreter,
75+
not venv interpreter.
76+
* The {obj}`//python/runtime_env_toolchains:all` toolchain now works with it.
77+
* (rules) Better handle flakey platform.win32_ver() calls by calling them
78+
multiple times.
79+
* (tools/wheelmaker.py) Extras are now preserved in Requires-Dist metadata when using requires_file
80+
to specify the requirements.
6481

6582
{#v0-0-0-added}
6683
### Added
67-
* Nothing added.
84+
* Repo utilities `execute_unchecked`, `execute_checked`, and `execute_checked_stdout` now
85+
support `log_stdout` and `log_stderr` keyword arg booleans. When these are `True`
86+
(the default), the subprocess's stdout/stderr will be logged.
6887

6988
{#v0-0-0-removed}
7089
### Removed
@@ -88,8 +107,6 @@ END_UNRELEASED_TEMPLATE
88107
* 3.12.9
89108
* 3.13.2
90109
* (pypi) Use `xcrun xcodebuild --showsdks` to find XCode root.
91-
* (pypi) The `bzlmod` extension will now generate smaller lock files for when
92-
using `experimental_index_url`.
93110
* (toolchains) Remove all but `3.8.20` versions of the Python `3.8` interpreter who has
94111
reached EOL. If users still need other versions of the `3.8` interpreter, please supply
95112
the URLs manually {bzl:obj}`python.toolchain` or {bzl:obj}`python_register_toolchains` calls.
@@ -126,6 +143,13 @@ END_UNRELEASED_TEMPLATE
126143
* (packaging) An empty `requires_file` is treated as if it were omitted, resulting in a valid `METADATA` file.
127144
* (rules) py_wheel and sphinxdocs rules now propagate `target_compatible_with` to all targets they create.
128145
[PR #2788](https://github.com/bazel-contrib/rules_python/pull/2788).
146+
* (pypi) Correctly handle `METADATA` entries when `python_full_version` is used in
147+
the environment marker.
148+
Fixes [#2319](https://github.com/bazel-contrib/rules_python/issues/2319).
149+
* (pypi) Correctly handle `python_version` parameter and transition the requirement
150+
locking to the right interpreter version when using
151+
{obj}`compile_pip_requirements` rule.
152+
See [#2819](https://github.com/bazel-contrib/rules_python/pull/2819).
129153

130154
{#1-4-0-added}
131155
### Added

CONTRIBUTING.md

Lines changed: 49 additions & 0 deletions
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

docs/environment-variables.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,19 @@ 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
5360
:::
61+
::::
5462

5563
::::{envvar} RULES_PYTHON_EXTRACT_ROOT
5664

docs/pypi-dependencies.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,40 @@
55

66
Using PyPI packages (aka "pip install") involves two main steps.
77

8-
1. [Installing third party packages](#installing-third-party-packages)
9-
2. [Using third party packages as dependencies](#using-third-party-packages)
8+
1. [Generating requirements file](#generating-requirements-file)
9+
2. [Installing third party packages](#installing-third-party-packages)
10+
3. [Using third party packages as dependencies](#using-third-party-packages)
11+
12+
{#generating-requirements-file}
13+
## Generating requirements file
14+
15+
Generally, when working on a Python project, you'll have some dependencies that themselves have other dependencies. You might also specify dependency bounds instead of specific versions. So you'll need to generate a full list of all transitive dependencies and pinned versions for every dependency.
16+
17+
Typically, you'd have your dependencies specified in `pyproject.toml` or `requirements.in` and generate the full pinned list of dependencies in `requirements_lock.txt`, which you can manage with the `compile_pip_requirements` Bazel rule:
18+
19+
```starlark
20+
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
21+
22+
compile_pip_requirements(
23+
name = "requirements",
24+
src = "requirements.in",
25+
requirements_txt = "requirements_lock.txt",
26+
)
27+
```
28+
29+
This rule generates two targets:
30+
- `bazel run [name].update` will regenerate the `requirements_txt` file
31+
- `bazel test [name]_test` will test that the `requirements_txt` file is up to date
32+
33+
For more documentation, see the API docs under {obj}`@rules_python//python:pip.bzl`.
34+
35+
Once you generate this fully specified list of requirements, you can install the requirements with the instructions in [Installing third party packages](#installing-third-party-packages).
36+
37+
:::{warning}
38+
If you're specifying dependencies in `pyproject.toml`, make sure to include the `[build-system]` configuration, with pinned dependencies. `compile_pip_requirements` will use the build system specified to read your project's metadata, and you might see non-hermetic behavior if you don't pin the build system.
39+
40+
Not specifying `[build-system]` at all will result in using a default `[build-system]` configuration, which uses unpinned versions ([ref](https://peps.python.org/pep-0518/#build-system-table)).
41+
:::
1042

1143
{#installing-third-party-packages}
1244
## Installing third party packages
@@ -27,8 +59,7 @@ pip.parse(
2759
)
2860
use_repo(pip, "my_deps")
2961
```
30-
For more documentation, including how the rules can update/create a requirements
31-
file, see the bzlmod examples under the {gh-path}`examples` folder or the documentation
62+
For more documentation, see the bzlmod examples under the {gh-path}`examples` folder or the documentation
3263
for the {obj}`@rules_python//python/extensions:pip.bzl` extension.
3364

3465
```{note}

docs/requirements.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ alabaster==1.0.0 \
1010
--hash=sha256:c00dca57bca26fa62a6d7d0a9fcce65f3e026e9bfe33e9c538fd3fbb2144fd9e \
1111
--hash=sha256:fc6786402dc3fcb2de3cabd5fe455a2db534b371124f1f21de8731783dec828b
1212
# via sphinx
13-
astroid==3.3.6 \
14-
--hash=sha256:6aaea045f938c735ead292204afdb977a36e989522b7833ef6fea94de743f442 \
15-
--hash=sha256:db676dc4f3ae6bfe31cda227dc60e03438378d7a896aec57422c95634e8d722f
13+
astroid==3.3.9 \
14+
--hash=sha256:622cc8e3048684aa42c820d9d218978021c3c3d174fb03a9f0d615921744f550 \
15+
--hash=sha256:d05bfd0acba96a7bd43e222828b7d9bc1e138aaeb0649707908d3702a9831248
1616
# via sphinx-autodoc2
1717
babel==2.17.0 \
1818
--hash=sha256:0c54cffb19f690cdcc52a3b50bcbf71e07a808d1c80d549f2459b9d2cf0afb9d \
@@ -223,9 +223,9 @@ myst-parser==4.0.0 \
223223
--hash=sha256:851c9dfb44e36e56d15d05e72f02b80da21a9e0d07cba96baf5e2d476bb91531 \
224224
--hash=sha256:b9317997552424448c6096c2558872fdb6f81d3ecb3a40ce84a7518798f3f28d
225225
# via rules-python-docs (docs/pyproject.toml)
226-
packaging==24.2 \
227-
--hash=sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759 \
228-
--hash=sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f
226+
packaging==25.0 \
227+
--hash=sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484 \
228+
--hash=sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f
229229
# via
230230
# readthedocs-sphinx-ext
231231
# sphinx
@@ -319,9 +319,9 @@ sphinx-reredirects==0.1.6 \
319319
--hash=sha256:c491cba545f67be9697508727818d8626626366245ae64456fe29f37e9bbea64 \
320320
--hash=sha256:efd50c766fbc5bf40cd5148e10c00f2c00d143027de5c5e48beece93cc40eeea
321321
# via rules-python-docs (docs/pyproject.toml)
322-
sphinx-rtd-theme==3.0.1 \
323-
--hash=sha256:921c0ece75e90633ee876bd7b148cfaad136b481907ad154ac3669b6fc957916 \
324-
--hash=sha256:a4c5745d1b06dfcb80b7704fe532eb765b44065a8fad9851e4258c8804140703
322+
sphinx-rtd-theme==3.0.2 \
323+
--hash=sha256:422ccc750c3a3a311de4ae327e82affdaf59eb695ba4936538552f3b00f4ee13 \
324+
--hash=sha256:b7457bc25dda723b20b086a670b9953c859eab60a2a03ee8eb2bb23e176e5f85
325325
# via rules-python-docs (docs/pyproject.toml)
326326
sphinxcontrib-applehelp==2.0.0 \
327327
--hash=sha256:2f29ef331735ce958efa4734873f084941970894c6090408b079c61b2e1c06d1 \

docs/toolchains.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,10 @@ runtime metadata (Python version, headers, ABI flags, etc) that the regular
339339
remotely downloaded runtimes contain, which makes it possible to build e.g. C
340340
extensions (unlike the autodetecting and runtime environment toolchains).
341341

342-
For simple cases, some rules are provided that will introspect
343-
a Python installation and create an appropriate Bazel definition from
344-
it. To do this, three pieces need to be wired together:
342+
For simple cases, the {obj}`local_runtime_repo` and
343+
{obj}`local_runtime_toolchains_repo` rules are provided that will introspect a
344+
Python installation and create an appropriate Bazel definition from it. To do
345+
this, three pieces need to be wired together:
345346

346347
1. Specify a path or command to a Python interpreter (multiple can be defined).
347348
2. Create toolchains for the runtimes in (1)

0 commit comments

Comments
 (0)