Skip to content

Commit 8a00d32

Browse files
committed
Merge remote-tracking branch 'upstream/main' into HEAD
2 parents 8635890 + 61c91fe commit 8a00d32

File tree

79 files changed

+2145
-250
lines changed

Some content is hidden

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

79 files changed

+2145
-250
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

.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: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,32 @@ END_UNRELEASED_TEMPLATE
5454

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

5964
{#v0-0-0-fixed}
6065
### Fixed
66+
6167
* (rules) PyInfo provider is now advertised by py_test, py_binary, and py_library;
6268
this allows aspects using required_providers to function correctly.
6369
([#2506](https://github.com/bazel-contrib/rules_python/issues/2506)).
70+
* Fixes when using {obj}`--bootstrap_impl=script`:
71+
* `compile_pip_requirements` now works with it
72+
* The `sys._base_executable` value will reflect the underlying interpreter,
73+
not venv interpreter.
74+
* The {obj}`//python/runtime_env_toolchains:all` toolchain now works with it.
75+
* (rules) Better handle flakey platform.win32_ver() calls by calling them
76+
multiple times.
6477

6578
{#v0-0-0-added}
6679
### Added
67-
* Nothing added.
80+
* Repo utilities `execute_unchecked`, `execute_checked`, and `execute_checked_stdout` now
81+
support `log_stdout` and `log_stderr` keyword arg booleans. When these are `True`
82+
(the default), the subprocess's stdout/stderr will be logged.
6883

6984
{#v0-0-0-removed}
7085
### Removed
@@ -133,6 +148,13 @@ END_UNRELEASED_TEMPLATE
133148
* (packaging) An empty `requires_file` is treated as if it were omitted, resulting in a valid `METADATA` file.
134149
* (rules) py_wheel and sphinxdocs rules now propagate `target_compatible_with` to all targets they create.
135150
[PR #2788](https://github.com/bazel-contrib/rules_python/pull/2788).
151+
* (pypi) Correctly handle `METADATA` entries when `python_full_version` is used in
152+
the environment marker.
153+
Fixes [#2319](https://github.com/bazel-contrib/rules_python/issues/2319).
154+
* (pypi) Correctly handle `python_version` parameter and transition the requirement
155+
locking to the right interpreter version when using
156+
{obj}`compile_pip_requirements` rule.
157+
See [#2819](https://github.com/bazel-contrib/rules_python/pull/2819).
136158

137159
{#1-4-0-added}
138160
### Added

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)

examples/bzlmod/entry_points/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
load("@python_versions//3.9:defs.bzl", py_console_script_binary_3_9 = "py_console_script_binary")
21
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
32

43
# This is how you can define a `pylint` entrypoint which uses the default python version.
@@ -24,10 +23,11 @@ py_console_script_binary(
2423
],
2524
)
2625

27-
# A specific Python version can be forced by using the generated version-aware
28-
# wrappers, e.g. to force Python 3.9:
29-
py_console_script_binary_3_9(
26+
# A specific Python version can be forced by passing `python_version`
27+
# attribute, e.g. to force Python 3.9:
28+
py_console_script_binary(
3029
name = "yamllint",
3130
pkg = "@pip//yamllint:pkg",
31+
python_version = "3.9",
3232
visibility = ["//entry_points:__subpackages__"],
3333
)

examples/bzlmod/py_proto_library/foo_external/py_binary_with_proto.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
if __name__ == "__main__":
44
import my_proto_pb2
5+
56
sys.exit(0)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
websockets
1+
websockets ; python_full_version > "3.9.1"

examples/multi_python_versions/requirements/requirements_lock_3_10.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# bazel run //requirements:requirements_3_10.update
66
#
7-
websockets==11.0.3 \
7+
websockets==11.0.3 ; python_full_version > "3.9.1" \
88
--hash=sha256:01f5567d9cf6f502d655151645d4e8b72b453413d3819d2b6f1185abc23e82dd \
99
--hash=sha256:03aae4edc0b1c68498f41a6772d80ac7c1e33c06c6ffa2ac1c27a07653e79d6f \
1010
--hash=sha256:0ac56b661e60edd453585f4bd68eb6a29ae25b5184fd5ba51e97652580458998 \

0 commit comments

Comments
 (0)