Skip to content

Commit 46b8f89

Browse files
committed
Merge remote-tracking branch 'upstream/main' into HEAD
2 parents cfd96c8 + 2e6f8ad commit 46b8f89

36 files changed

+695
-165
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,30 @@ Unreleased changes template.
5757
* (rules) deprecation warnings for deprecated symbols have been turned off by
5858
default for now and can be enabled with `RULES_PYTHON_DEPRECATION_WARNINGS`
5959
env var.
60+
* (pypi) Downgraded versions of packages: `pip` from `24.3.2` to `24.0.0` and
61+
`packaging` from `24.2` to `24.0`.
6062

6163
{#v0-0-0-fixed}
6264
### Fixed
65+
* (rules) `python_zip_file` output with `--bootstrap_impl=script` works again
66+
([#2596](https://github.com/bazelbuild/rules_python/issues/2596)).
67+
* (docs) Using `python_version` attribute for specifying python versions introduced in `v1.1.0`
6368
* (gazelle) Providing multiple input requirements files to `gazelle_python_manifest` now works correctly.
6469
* (pypi) Handle trailing slashes in pip index URLs in environment variables,
6570
fixes [#2554](https://github.com/bazelbuild/rules_python/issues/2554).
6671
* (runfiles) Runfile manifest and repository mapping files are now interpreted
6772
as UTF-8 on all platforms.
6873
* (coverage) Coverage with `--bootstrap_impl=script` is fixed
6974
([#2572](https://github.com/bazelbuild/rules_python/issues/2572)).
75+
* (pypi) Non deterministic behaviour in requirement file usage has been fixed
76+
by reverting [#2514](https://github.com/bazelbuild/rules_python/pull/2514).
77+
The related issue is [#908](https://github.com/bazelbuild/rules_python/issue/908).
78+
* (sphinxdocs) Do not crash when `tag_class` does not have a populated `doc` value.
79+
Fixes ([#2579](https://github.com/bazelbuild/rules_python/issues/2579)).
80+
* (binaries/tests) Fix packaging when using `--bootstrap_impl=script`: set
81+
{obj}`--venvs_use_declare_symlink=no` to have it not create symlinks at
82+
build time (they will be created at runtime instead).
83+
(Fixes [#2489](https://github.com/bazelbuild/rules_python/issues/2489))
7084

7185
{#v0-0-0-added}
7286
### Added

MODULE.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
8484
bazel_dep(name = "rules_shell", version = "0.3.0", dev_dependency = True)
8585
bazel_dep(name = "rules_multirun", version = "0.9.0", dev_dependency = True)
8686
bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True)
87+
bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True)
8788

8889
# Extra gazelle plugin deps so that WORKSPACE.bzlmod can continue including it for e2e tests.
8990
# We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides.
@@ -175,7 +176,7 @@ use_repo(
175176

176177
# EXPERIMENTAL: This is experimental and may be removed without notice
177178
uv = use_extension(
178-
"//python/uv:extensions.bzl",
179+
"//python/uv:uv.bzl",
179180
"uv",
180181
dev_dependency = True,
181182
)

docs/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1616
load("@dev_pip//:requirements.bzl", "requirement")
1717
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
1818
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
19-
load("//python/uv/private:lock.bzl", "lock") # buildifier: disable=bzl-visibility
19+
load("//python/uv:lock.bzl", "lock") # buildifier: disable=bzl-visibility
2020
load("//sphinxdocs:readthedocs.bzl", "readthedocs_install")
2121
load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
2222
load("//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
@@ -105,6 +105,10 @@ sphinx_stardocs(
105105
"//python/private/api:py_common_api_bzl",
106106
"//python/private/pypi:config_settings_bzl",
107107
"//python/private/pypi:pkg_aliases_bzl",
108+
"//python/uv:lock_bzl",
109+
"//python/uv:uv_bzl",
110+
"//python/uv:uv_toolchain_bzl",
111+
"//python/uv:uv_toolchain_info_bzl",
108112
] + ([
109113
# Bazel 6 + Stardoc isn't able to parse something about the python bzlmod extension
110114
"//python/extensions:python_bzl",

docs/_includes/py_console_script_binary.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ py_console_script_binary(
1212
)
1313
```
1414

15-
Or for more advanced setups you can also specify extra dependencies and the
15+
#### Specifying extra dependencies
16+
You can also specify extra dependencies and the
1617
exact script name you want to call. It is useful for tools like `flake8`, `pylint`,
1718
`pytest`, which have plugin discovery methods and discover dependencies from the
1819
PyPI packages available in the `PYTHONPATH`.
@@ -34,17 +35,26 @@ py_console_script_binary(
3435
)
3536
```
3637

37-
A specific Python version can be forced by using the generated version-aware
38-
wrappers, e.g. to force Python 3.9:
38+
#### Using a specific Python version
39+
40+
A specific Python version can be forced by passing the desired Python version, e.g. to force Python 3.9:
3941
```starlark
40-
load("@python_versions//3.9:defs.bzl", "py_console_script_binary")
42+
load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
4143

4244
py_console_script_binary(
4345
name = "yamllint",
4446
pkg = "@pip//yamllint",
47+
python_version = "3.9"
4548
)
4649
```
4750

51+
#### Using a specific Python Version directly from a Toolchain
52+
:::{deprecated} 1.1.0
53+
The toolchain specific `py_binary` and `py_test` symbols are aliases to the regular rules.
54+
i.e. Deprecated `load("@python_versions//3.11:defs.bzl", "py_binary")` and `load("@python_versions//3.11:defs.bzl", "py_test")`
55+
56+
You should instead specify the desired python version with `python_version`; see above example.
57+
:::
4858
Alternatively, the [`py_console_script_binary.binary_rule`] arg can be passed
4959
the version-bound `py_binary` symbol, or any other `py_binary`-compatible rule
5060
of your choosing:
@@ -60,5 +70,4 @@ py_console_script_binary(
6070
```
6171

6272
[specification]: https://packaging.python.org/en/latest/specifications/entry-points/
63-
[`py_console_script_binary.binary_rule`]: #py_console_script_binary_binary_rule
64-
73+
[`py_console_script_binary.binary_rule`]: #py_console_script_binary_binary_rule

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Values:
212212
:::
213213
::::
214214

215+
215216
::::{bzl:flag} bootstrap_impl
216217
Determine how programs implement their startup process.
217218

@@ -258,3 +259,26 @@ Values:
258259
:::
259260

260261
::::
262+
263+
::::{bzl:flag} venvs_use_declare_symlink
264+
265+
Determines if relative symlinks are created using `declare_symlink()` at build
266+
time.
267+
268+
This is only intended to work around
269+
[#2489](https://github.com/bazelbuild/rules_python/issues/2489), where some
270+
packaging rules don't support `declare_symlink()` artifacts.
271+
272+
Values:
273+
* `yes`: Use `declare_symlink()` and create relative symlinks at build time.
274+
* `no`: Do not use `declare_symlink()`. Instead, the venv will be created at
275+
runtime.
276+
277+
:::{seealso}
278+
{envvar}`RULES_PYTHON_EXTRACT_ROOT` for customizing where the runtime venv
279+
is created.
280+
:::
281+
282+
:::{versionadded} VERSION_NEXT_PATCH
283+
:::
284+
::::

docs/environment-variables.md

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,56 @@
11
# Environment Variables
22

3-
:::{envvar} RULES_PYTHON_REPO_DEBUG
3+
:::{envvar} RULES_PYTHON_BOOTSTRAP_VERBOSE
44

5-
When `1`, repository rules will print debug information about what they're
5+
When `1`, debug information about bootstrapping of a program is printed to
6+
stderr.
7+
:::
8+
9+
:::{envvar} RULES_PYTHON_BZLMOD_DEBUG
10+
11+
When `1`, bzlmod extensions will print debug information about what they're
612
doing. This is mostly useful for development to debug errors.
713
:::
814

9-
:::{envvar} RULES_PYTHON_REPO_DEBUG_VERBOSITY
15+
:::{envvar} RULES_PYTHON_DEPRECATION_WARNINGS
1016

11-
Determines the verbosity of logging output for repo rules. Valid values:
17+
When `1`, the rules_python will warn users about deprecated functionality that will
18+
be removed in a subsequent major `rules_python` version. Defaults to `0` if unset.
19+
:::
1220

13-
* `DEBUG`
14-
* `INFO`
15-
* `TRACE`
21+
:::{envvar} RULES_PYTHON_ENABLE_PYSTAR
22+
23+
When `1`, the rules_python Starlark implementation of the core rules is used
24+
instead of the Bazel-builtin rules. Note this requires Bazel 7+.
1625
:::
1726

18-
:::{envvar} RULES_PYTHON_REPO_TOOLCHAIN_VERSION_OS_ARCH
27+
::::{envvar} RULES_PYTHON_EXTRACT_ROOT
1928

20-
Determines the python interpreter platform to be used for a particular
21-
interpreter `(version, os, arch)` triple to be used in repository rules.
22-
Replace the `VERSION_OS_ARCH` part with actual values when using, e.g.
23-
`3_13_0_linux_x86_64`. The version values must have `_` instead of `.` and the
24-
os, arch values are the same as the ones mentioned in the
25-
`//python:versions.bzl` file.
29+
Directory to use as the root for creating files necessary for bootstrapping so
30+
that a binary can run.
31+
32+
Only applicable when {bzl:flag}`--venvs_use_declare_symlink=no` is used.
33+
34+
When set, a binary will attempt to find a unique, reusable, location within this
35+
directory for the files it needs to create to aid startup. The files may not be
36+
deleted upon program exit; it is the responsibility of the caller to ensure
37+
cleanup.
38+
39+
Manually specifying the directory is useful to lower the overhead of
40+
extracting/creating files on every program execution. By using a location
41+
outside /tmp, longer lived programs don't have to worry about files in /tmp
42+
being cleaned up by the OS.
43+
44+
If not set, then a temporary directory will be created and deleted upon program
45+
exit.
46+
47+
:::{versionadded} VERSION_NEXT_PATCH
48+
:::
49+
::::
50+
51+
:::{envvar} RULES_PYTHON_GAZELLE_VERBOSE
52+
53+
When `1`, debug information from gazelle is printed to stderr.
2654
:::
2755

2856
:::{envvar} RULES_PYTHON_PIP_ISOLATED
@@ -34,37 +62,32 @@ Valid values:
3462
* Other non-empty values mean to use isolated mode.
3563
:::
3664

37-
:::{envvar} RULES_PYTHON_BZLMOD_DEBUG
65+
:::{envvar} RULES_PYTHON_REPO_DEBUG
3866

39-
When `1`, bzlmod extensions will print debug information about what they're
67+
When `1`, repository rules will print debug information about what they're
4068
doing. This is mostly useful for development to debug errors.
4169
:::
4270

43-
:::{envvar} RULES_PYTHON_DEPRECATION_WARNINGS
44-
45-
When `1`, the rules_python will warn users about deprecated functionality that will
46-
be removed in a subsequent major `rules_python` version. Defaults to `0` if unset.
47-
:::
71+
:::{envvar} RULES_PYTHON_REPO_DEBUG_VERBOSITY
4872

49-
:::{envvar} RULES_PYTHON_ENABLE_PYSTAR
73+
Determines the verbosity of logging output for repo rules. Valid values:
5074

51-
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+.
75+
* `DEBUG`
76+
* `INFO`
77+
* `TRACE`
5378
:::
5479

55-
:::{envvar} RULES_PYTHON_BOOTSTRAP_VERBOSE
80+
:::{envvar} RULES_PYTHON_REPO_TOOLCHAIN_VERSION_OS_ARCH
5681

57-
When `1`, debug information about bootstrapping of a program is printed to
58-
stderr.
82+
Determines the python interpreter platform to be used for a particular
83+
interpreter `(version, os, arch)` triple to be used in repository rules.
84+
Replace the `VERSION_OS_ARCH` part with actual values when using, e.g.
85+
`3_13_0_linux_x86_64`. The version values must have `_` instead of `.` and the
86+
os, arch values are the same as the ones mentioned in the
87+
`//python:versions.bzl` file.
5988
:::
6089

6190
:::{envvar} VERBOSE_COVERAGE
6291

6392
When `1`, debug information about coverage behavior is printed to stderr.
6493
:::
65-
66-
67-
:::{envvar} RULES_PYTHON_GAZELLE_VERBOSE
68-
69-
When `1`, debug information from gazelle is printed to stderr.
70-
:::

docs/toolchains.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ python = use_extension("@rules_python//python/extensions:python.bzl", "python")
116116
python.toolchain(python_version = "3.12")
117117
118118
# BUILD.bazel
119-
load("@python_versions//3.12:defs.bzl", "py_binary")
119+
load("@rules_python//python:py_binary.bzl", "py_binary")
120120
121-
py_binary(...)
121+
py_binary(..., python_version="3.12")
122122
```
123123

124124
### Pinning to a Python version
@@ -132,21 +132,59 @@ is most useful for two cases:
132132
typically in a mono-repo situation.
133133

134134
To configure a submodule with the version-aware rules, request the particular
135-
version you need, then use the `@python_versions` repo to use the rules that
136-
force specific versions:
135+
version you need when defining the toolchain:
137136

138137
```starlark
138+
# MODULE.bazel
139139
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
140140

141141
python.toolchain(
142142
python_version = "3.11",
143143
)
144-
use_repo(python, "python_versions")
144+
use_repo(python)
145+
```
146+
147+
Then use the `@rules_python` repo in your BUILD file to explicity pin the Python version when calling the rule:
148+
149+
```starlark
150+
# BUILD.bazel
151+
load("@rules_python//python:py_binary.bzl", "py_binary")
152+
153+
py_binary(..., python_version = "3.11")
154+
py_test(..., python_version = "3.11")
145155
```
146156

147-
Then use e.g. `load("@python_versions//3.11:defs.bzl", "py_binary")` to use
148-
the rules that force that particular version. Multiple versions can be specified
149-
and use within a single build.
157+
Multiple versions can be specified and used within a single build.
158+
159+
```starlark
160+
# MODULE.bazel
161+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
162+
163+
python.toolchain(
164+
python_version = "3.11",
165+
is_default = True,
166+
)
167+
168+
python.toolchain(
169+
python_version = "3.12",
170+
)
171+
172+
# BUILD.bazel
173+
load("@rules_python//python:py_binary.bzl", "py_binary")
174+
load("@rules_python//python:py_test.bzl", "py_test")
175+
176+
# Defaults to 3.11
177+
py_binary(...)
178+
py_test(...)
179+
180+
# Explicitly use Python 3.11
181+
py_binary(..., python_version = "3.11")
182+
py_test(..., python_version = "3.11")
183+
184+
# Explicitly use Python 3.12
185+
py_binary(..., python_version = "3.12")
186+
py_test(..., python_version = "3.12")
187+
```
150188

151189
For more documentation, see the bzlmod examples under the {gh-path}`examples`
152190
folder. Look for the examples that contain a `MODULE.bazel` file.
@@ -159,6 +197,16 @@ The `python.toolchain()` call makes its contents available under a repo named
159197
Remember to call `use_repo()` to make repos visible to your module:
160198
`use_repo(python, "python_3_11")`
161199

200+
201+
:::{deprecated} 1.1.0
202+
The toolchain specific `py_binary` and `py_test` symbols are aliases to the regular rules.
203+
i.e. Deprecated `load("@python_versions//3.11:defs.bzl", "py_binary")` & `load("@python_versions//3.11:defs.bzl", "py_test")`
204+
205+
Usages of them should be changed to load the regular rules directly;
206+
i.e. Use `load("@rules_python//python:py_binary.bzl", "py_binary")` & `load("@rules_python//python:py_test.bzl", "py_test")` and then specify the `python_version` when using the rules corresponding to the python version you defined in your toolchain. {ref}`Library modules with version constraints`
207+
:::
208+
209+
162210
#### Toolchain usage in other rules
163211

164212
Python toolchains can be utilized in other bazel rules, such as `genrule()`, by

examples/bzlmod/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ python.single_version_platform_override(
105105
use_repo(python, "python_3_10", "python_3_9", "python_versions", "pythons_hub")
106106

107107
# EXPERIMENTAL: This is experimental and may be removed without notice
108-
uv = use_extension("@rules_python//python/uv:extensions.bzl", "uv")
108+
uv = use_extension("@rules_python//python/uv:uv.bzl", "uv")
109109
uv.toolchain(uv_version = "0.4.25")
110110
use_repo(uv, "uv_toolchains")
111111

python/config_settings/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ load(
99
"LibcFlag",
1010
"PrecompileFlag",
1111
"PrecompileSourceRetentionFlag",
12+
"VenvsUseDeclareSymlinkFlag",
1213
)
1314
load(
1415
"//python/private/pypi:flags.bzl",
@@ -121,6 +122,13 @@ config_setting(
121122
visibility = ["//visibility:public"],
122123
)
123124

125+
string_flag(
126+
name = "venvs_use_declare_symlink",
127+
build_setting_default = VenvsUseDeclareSymlinkFlag.YES,
128+
values = VenvsUseDeclareSymlinkFlag.flag_values(),
129+
visibility = ["//visibility:public"],
130+
)
131+
124132
# pip.parse related flags
125133

126134
string_flag(

0 commit comments

Comments
 (0)