Skip to content

Commit 5025f90

Browse files
committed
Merge branch 'main' into fix/lockfile-inconsistency
2 parents de98a02 + b6fc2a0 commit 5025f90

Some content is hidden

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

42 files changed

+1070
-1040
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/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
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
99

1010
test --test_output=errors
1111

.bcr/metadata.template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"name": "Thulio Ferraz Assis",
1111
"email": "[email protected]",
1212
"github": "f0rmiga"
13+
},
14+
{
15+
"name": "Ignas Anikevicius",
16+
"email": "[email protected]",
17+
"github": "aignas"
1318
}
1419
],
1520
"repository": [

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
python/features.bzl export-subst
12
tools/publish/*.txt linguist-generated=true

CHANGELOG.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@ A brief description of the categories of changes:
3333
([2310](https://github.com/bazelbuild/rules_python/issues/2310)).
3434
* (publish) The dependencies have been updated to the latest available versions
3535
for the `twine` publishing rule.
36-
- (bzlmod) `pip.parse` spoke repository naming has changed in places where the
36+
* (bzlmod) `pip.parse` spoke repository naming has changed in places where the
3737
users specify different package versions per platform in the same hub repository.
3838
We advise the users to use the `hub` repository directly to avoid such breakage in
3939
the future.
4040

4141
{#v0-0-0-fixed}
4242
### Fixed
43-
- (bzlmod) The extension evaluation has been adjusted to always generate the
43+
* (bzlmod) Generate `config_setting` values for all available toolchains instead
44+
of only the registered toolchains, which restores the previous behaviour that
45+
`bzlmod` users would have observed.
46+
* (pypi) (Bazel 7.4+) Allow spaces in filenames included in `whl_library`s
47+
([617](https://github.com/bazelbuild/rules_python/issues/617)).
48+
* (whl_library) Remove `--no-build-isolation` to allow non-hermetic sdist builds
49+
by default. Users wishing to keep this argument and to enforce more hermetic
50+
builds can do so by passing the argument in
51+
[`pip.parse#extra_pip_args`](https://rules-python.readthedocs.io/en/latest/api/rules_python/python/extensions/pip.html#pip.parse.extra_pip_args)
52+
* (bzlmod) The extension evaluation has been adjusted to always generate the
4453
same lock file irrespective if `experimental_index_url` is set by any module
4554
or not. Fixes
4655
[#2268](https://github.com/bazelbuild/rules_python/issues/2268). A known
@@ -54,11 +63,12 @@ A brief description of the categories of changes:
5463
`requirements_linux.txt`, `requirements_windows.txt` for each respective OS
5564
and one extra file `requirements_universal.txt` if you prefer a single file.
5665
The `requirements.txt` file may be removed in the future.
57-
- (bzlmod) `pip.parse` now supports `whl-only` setup using
66+
* (bzlmod) `pip.parse` now supports `whl-only` setup using
5867
`download_only = True` where users can specify multiple requirements files
5968
and use the `pip` backend to do the downloading. This was only available for
6069
users setting {bzl:obj}`pip.parse.experimental_index_url`, but now users have
6170
more options whilst we continue to work on stabilizing the experimental feature.
71+
* The rules_python version is now reported in `//python/features.bzl#features.version`
6272

6373
{#v0-0-0-removed}
6474
### Removed

DEVELOPING.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Start from a clean checkout at `main`.
2424
Before running through the release it's good to run the build and the tests locally, and make sure CI is passing. You can
2525
also test-drive the commit in an existing Bazel workspace to sanity check functionality.
2626

27+
### Releasing from HEAD
28+
2729
#### Steps
2830
1. [Determine the next semantic version number](#determining-semantic-version)
2931
1. Create a tag and push, e.g. `git tag 0.5.0 upstream/main && git push upstream --tags`
@@ -42,9 +44,31 @@ To find if there were any features added or incompatible changes made, review
4244
the commit history. This can be done using github by going to the url:
4345
`https://github.com/bazelbuild/rules_python/compare/<VERSION>...main`.
4446

47+
### Patch release with cherry picks
48+
49+
If a patch release from head would contain changes that aren't appropriate for
50+
a patch release, then the patch release needs to be based on the original
51+
release tag and the patch changes cherry-picked into it.
52+
53+
In this example, release `0.37.0` is being patched to create release `0.37.1`.
54+
The fix being included is commit `deadbeef`.
55+
56+
1. `git checkout -b release/0.37 0.37.0`
57+
1. `git push upstream release/0.37`
58+
1. `git cherry-pick -x deadbeef`
59+
1. Fix merge conflicts, if any. If `MODULE.bazel.lock` conflicts occur, then
60+
run `pre-commit run update-bzlmod-lockfiles -a`
61+
1. `git cherry-pick --continue` (if applicable)
62+
1. `git push upstream`
63+
64+
If multiple commits need to be applied, repeat the `git cherry-pick` step for
65+
each.
66+
67+
Once the release branch is in the desired state, use `git tag` to tag it, as
68+
done with a release from head. Release automation will do the rest.
69+
4570
#### After release creation in Github
4671

47-
1. Ping @philwo to get the new release added to mirror.bazel.build. See [this comment on issue #400](https://github.com/bazelbuild/rules_python/issues/400#issuecomment-779159530) for more context.
4872
1. Announce the release in the #python channel in the Bazel slack (bazelbuild.slack.com).
4973

5074
## Secrets

docs/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ sphinx_stardocs(
9797
"//python/cc:py_cc_toolchain_bzl",
9898
"//python/cc:py_cc_toolchain_info_bzl",
9999
"//python/entry_points:py_console_script_binary_bzl",
100-
"//python/private:py_binary_rule_bazel_bzl",
100+
"//python/private:py_binary_rule_bzl",
101101
"//python/private:py_cc_toolchain_rule_bzl",
102-
"//python/private:py_library_rule_bazel_bzl",
102+
"//python/private:py_library_rule_bzl",
103103
"//python/private:py_runtime_rule_bzl",
104-
"//python/private:py_test_rule_bazel_bzl",
104+
"//python/private:py_test_rule_bzl",
105105
"//python/private/api:py_common_api_bzl",
106106
] + ([
107107
# Bazel 6 + Stardoc isn't able to parse something about the python bzlmod extension

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,44 @@ one of the values that `rules_python` maintains.
3333
Parses the value of the `python_version` and transforms it into a `X.Y` value.
3434
:::
3535

36+
:::{bzl:target} is_python_*
37+
config_settings to match Python versions
38+
39+
The name pattern is `is_python_X.Y` (to match major.minor) and `is_python_X.Y.Z`
40+
(to match major.minor.patch).
41+
42+
Note that the set of available targets depends on the configured
43+
`TOOL_VERSIONS`. Versions may not always be available if the root module has
44+
customized them, or as older Python versions are removed from rules_python's set
45+
of builtin, known versions.
46+
47+
If you need to match a version that isn't present, then you have two options:
48+
1. Manually define a `config_setting` and have it match {obj}`--python_version`
49+
or {ob}`python_version_major_minor`. This works best when you don't control the
50+
root module, or don't want to rely on the MODULE.bazel configuration. Such
51+
a config settings would look like:
52+
```
53+
# Match any 3.5 version
54+
config_setting(
55+
name = "is_python_3.5",
56+
flag_values = {
57+
"@rules_python//python/config_settings:python_version_major_minor": "3.5",
58+
}
59+
)
60+
# Match exactly 3.5.1
61+
config_setting(
62+
name = "is_python_3.5.1",
63+
flag_values = {
64+
"@rules_python//python/config_settings:python_version": "3.5.1",
65+
}
66+
)
67+
```
68+
69+
2. Use {obj}`python.single_override` to re-introduce the desired version so
70+
that the corresponding `//python/config_setting:is_python_XXX` target is
71+
generated.
72+
:::
73+
3674
::::{bzl:flag} exec_tools_toolchain
3775
Determines if the {obj}`exec_tools_toolchain_type` toolchain is enabled.
3876

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@
6969
"api/python/defs": "/api/rules_python/python/defs.html",
7070
"api/python/index": "/api/rules_python/python/index.html",
7171
"api/python/py_runtime_info": "/api/rules_python/python/py_runtime_info.html",
72-
"api/python/private/common/py_library_rule_bazel": "/api/rules_python/python/private/py_library_rule_bazel.html",
72+
"api/python/private/common/py_library_rule_bazel": "/api/rules_python/python/private/py_library_rule.html",
7373
"api/python/private/common/py_test_rule_bazel": "/api/rules_python/python/private/py_test_rule_bazel.html",
74-
"api/python/private/common/py_binary_rule_bazel": "/api/rules_python/python/private/py_binary_rule_bazel.html",
74+
"api/python/private/common/py_binary_rule_bazel": "/api/rules_python/python/private/py_binary_rule.html",
7575
"api/python/private/common/py_runtime_rule": "/api/rules_python/python/private/py_runtime_rule.html",
7676
"api/python/extensions/pip": "/api/rules_python/python/extensions/pip.html",
7777
"api/python/extensions/python": "/api/rules_python/python/extensions/python.html",

examples/bzlmod/MODULE.bazel

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ python.toolchain(
4040
# One can override the actual toolchain versions that are available, which can be useful
4141
# when optimizing what gets downloaded and when.
4242
python.override(
43-
available_python_versions = [
44-
"3.10.9",
45-
"3.9.18",
46-
"3.9.19",
47-
# The following is used by the `other_module` and we need to include it here
48-
# as well.
49-
"3.11.8",
50-
],
43+
# NOTE: These are disabled in the example because transitive dependencies
44+
# require versions not listed here.
45+
# available_python_versions = [
46+
# "3.10.9",
47+
# "3.9.18",
48+
# "3.9.19",
49+
# # The following is used by the `other_module` and we need to include it here
50+
# # as well.
51+
# "3.11.8",
52+
# ],
5153
# Also override the `minor_mapping` so that the root module,
5254
# instead of rules_python's defaulting to the latest available version,
5355
# controls what full version is used when `3.x` is requested.

examples/bzlmod/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/multi_python_versions/MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ python.toolchain(
3030
)
3131
use_repo(
3232
python,
33+
"pythons_hub",
3334
python = "python_versions",
3435
)
3536

examples/multi_python_versions/tests/BUILD.bazel

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
2+
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
3+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
24
load("@python//3.10:defs.bzl", py_binary_3_10 = "py_binary", py_test_3_10 = "py_test")
35
load("@python//3.11:defs.bzl", py_binary_3_11 = "py_binary", py_test_3_11 = "py_test")
46
load("@python//3.8:defs.bzl", py_binary_3_8 = "py_binary", py_test_3_8 = "py_test")
57
load("@python//3.9:defs.bzl", py_binary_3_9 = "py_binary", py_test_3_9 = "py_test")
8+
load("@pythons_hub//:versions.bzl", "MINOR_MAPPING", "PYTHON_VERSIONS")
69
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
10+
load("@rules_python//python:versions.bzl", DEFAULT_MINOR_MAPPING = "MINOR_MAPPING", DEFAULT_TOOL_VERSIONS = "TOOL_VERSIONS")
11+
load("@rules_python//python/private:text_util.bzl", "render") # buildifier: disable=bzl-visibility
712
load("@rules_shell//shell:sh_test.bzl", "sh_test")
813

914
copy_file(
@@ -183,3 +188,37 @@ sh_test(
183188
"VERSION_PY_BINARY": "$(rootpath :version_3_10)",
184189
},
185190
)
191+
192+
# The following test ensures that default toolchain versions are the same as in
193+
# the TOOL_VERSIONS array.
194+
195+
# NOTE @aignas 2024-10-26: This test here is to do a sanity check and not
196+
# include extra dependencies - if rules_testing is included here, we can
197+
# potentially uses `rules_testing` for a more lightweight test.
198+
write_file(
199+
name = "default_python_versions",
200+
out = "default_python_versions.txt",
201+
content = [
202+
"MINOR_MAPPING:",
203+
render.dict(dict(sorted(DEFAULT_MINOR_MAPPING.items()))),
204+
"PYTHON_VERSIONS:",
205+
render.list(sorted(DEFAULT_TOOL_VERSIONS)),
206+
],
207+
)
208+
209+
write_file(
210+
name = "pythons_hub_versions",
211+
out = "pythons_hub_versions.txt",
212+
content = [
213+
"MINOR_MAPPING:",
214+
render.dict(dict(sorted(MINOR_MAPPING.items()))),
215+
"PYTHON_VERSIONS:",
216+
render.list(sorted(PYTHON_VERSIONS)),
217+
],
218+
)
219+
220+
diff_test(
221+
name = "test_versions",
222+
file1 = "default_python_versions",
223+
file2 = "pythons_hub_versions",
224+
)

0 commit comments

Comments
 (0)