Skip to content

Commit 0228b9d

Browse files
committed
Merge branch 'main' into default_version_file
2 parents 86d17aa + b499560 commit 0228b9d

File tree

98 files changed

+1793
-885
lines changed

Some content is hidden

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

98 files changed

+1793
-885
lines changed

.github/workflows/mypy.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ jobs:
2222
- uses: jpetrucciani/mypy-check@master
2323
with:
2424
requirements: 1.6.0
25-
python_version: 3.8
25+
python_version: 3.9
2626
path: 'python/runfiles'
2727
- uses: jpetrucciani/mypy-check@master
2828
with:
2929
requirements: 1.6.0
30-
python_version: 3.8
30+
python_version: 3.9
3131
path: 'tests/runfiles'
32-

CHANGELOG.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,46 @@ Unreleased changes template.
5252

5353
{#v0-0-0-changed}
5454
### Changed
55+
* (deps) platforms 0.0.4 -> 0.0.11
56+
* (py_wheel) Package `py_library.pyi_srcs` (`.pyi` files) in the wheel.
57+
* (py_package) Package `py_library.pyi_srcs` (`.pyi` files) in `py_package`.
58+
59+
{#v0-0-0-fixed}
60+
### Fixed
61+
* (pypi) The `ppc64le` is now pointing to the right target in the `platforms` package.
62+
* (gazelle) No longer incorrectly merge `py_binary` targets during partial updates in
63+
`file` generation mode. Fixed in [#2619](https://github.com/bazelbuild/rules_python/pull/2619).
64+
* (bzlmod) Running as root is no longer an error. `ignore_root_user_error=True`
65+
is now the default. Note that running as root may still cause spurious
66+
Bazel cache invalidation
67+
([#1169](https://github.com/bazelbuild/rules_python/issues/1169)).
68+
* (gazelle) Don't collapse depsets to a list or into args when generating the modules mapping file.
69+
Support spilling modules mapping args into a params file.
70+
* (pypi) From now on `python` invocations in repository and module extension
71+
evaluation contexts will invoke Python interpreter with `-B` to avoid
72+
creating `.pyc` files.
73+
* (deps) doublestar 4.7.1 (required for recent Gazelle versions)
74+
75+
{#v0-0-0-added}
76+
### Added
77+
* {obj}`//python/bin:python`: convenience target for directly running an
78+
interpreter. {obj}`--//python/bin:python_src` can be used to specify a
79+
binary whose interpreter to use.
80+
81+
{#v0-0-0-removed}
82+
### Removed
83+
* Nothing removed.
84+
85+
{#v1-2-0}
86+
## [1.2.0] - 2025-02-21
87+
88+
[1.2.0]: https://github.com/bazelbuild/rules_python/releases/tag/1.2.0
89+
90+
{#v1-2-0-changed}
91+
### Changed
92+
* (rules) `py_proto_library` is deprecated in favour of the
93+
implementation in https://github.com/protocolbuffers/protobuf. It will be
94+
removed in the future release.
5595
* (pypi) {obj}`pip.override` will now be ignored instead of raising an error,
5696
fixes [#2550](https://github.com/bazelbuild/rules_python/issues/2550).
5797
* (rules) deprecation warnings for deprecated symbols have been turned off by
@@ -60,8 +100,11 @@ Unreleased changes template.
60100
* (pypi) Downgraded versions of packages: `pip` from `24.3.2` to `24.0.0` and
61101
`packaging` from `24.2` to `24.0`.
62102

63-
{#v0-0-0-fixed}
103+
{#v1-2-0-fixed}
64104
### Fixed
105+
* (rules) `python_zip_file` output with `--bootstrap_impl=script` works again
106+
([#2596](https://github.com/bazelbuild/rules_python/issues/2596)).
107+
* (docs) Using `python_version` attribute for specifying python versions introduced in `v1.1.0`
65108
* (gazelle) Providing multiple input requirements files to `gazelle_python_manifest` now works correctly.
66109
* (pypi) Handle trailing slashes in pip index URLs in environment variables,
67110
fixes [#2554](https://github.com/bazelbuild/rules_python/issues/2554).
@@ -74,14 +117,18 @@ Unreleased changes template.
74117
The related issue is [#908](https://github.com/bazelbuild/rules_python/issue/908).
75118
* (sphinxdocs) Do not crash when `tag_class` does not have a populated `doc` value.
76119
Fixes ([#2579](https://github.com/bazelbuild/rules_python/issues/2579)).
120+
* (binaries/tests) Fix packaging when using `--bootstrap_impl=script`: set
121+
{obj}`--venvs_use_declare_symlink=no` to have it not create symlinks at
122+
build time (they will be created at runtime instead).
123+
(Fixes [#2489](https://github.com/bazelbuild/rules_python/issues/2489))
77124

78-
{#v0-0-0-added}
125+
{#v1-2-0-added}
79126
### Added
80127
* (python) {attr}`python.toolchain.default_version_file` has been added to
81128
allow users to set the default python version in the root module by reading
82129
the default version number from a file.
83130

84-
{#v0-0-0-removed}
131+
{#v1-2-0-removed}
85132
### Removed
86133
* Nothing removed.
87134

CONTRIBUTING.md

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
We'd love to accept your patches and contributions to this project. There are
44
just a few small guidelines you need to follow.
55

6+
## Contributor License Agreement
7+
8+
First, the most important step: signing the Contributor License Agreement. We
9+
cannot look at any of your code unless one is signed.
10+
11+
Contributions to this project must be accompanied by a Contributor License
12+
Agreement. You (or your employer) retain the copyright to your contribution,
13+
this simply gives us permission to use and redistribute your contributions as
14+
part of the project. Head over to <https://cla.developers.google.com/> to see
15+
your current agreements on file or to sign a new one.
16+
17+
You generally only need to submit a CLA once, so if you've already submitted one
18+
(even if it was for a different project), you probably don't need to do it
19+
again.
20+
621
## Getting started
722

823
Before we can work on the code, we need to get a copy of it and setup some
@@ -50,29 +65,10 @@ git push origin my-feature
5065
Once the code is in your github repo, you can then turn it into a Pull Request
5166
to the actual rules_python project and begin the code review process.
5267

68+
## Developer guide
5369

54-
## Running tests
55-
56-
Running tests is particularly easy thanks to Bazel, simply run:
57-
58-
```
59-
bazel test //...
60-
```
61-
62-
And it will run all the tests it can find. The first time you do this, it will
63-
probably take long time because various dependencies will need to be downloaded
64-
and setup. Subsequent runs will be faster, but there are many tests, and some of
65-
them are slow. If you're working on a particular area of code, you can run just
66-
the tests in those directories instead, which can speed up your edit-run cycle.
67-
68-
## Updating tool dependencies
69-
70-
It's suggested to routinely update the tool versions within our repo - some of the
71-
tools are using requirement files compiled by `uv` and others use other means. In order
72-
to have everything self-documented, we have a special target -
73-
`//private:requirements.update`, which uses `rules_multirun` to run in sequence all
74-
of the requirement updating scripts in one go. This can be done once per release as
75-
we prepare for releases.
70+
For more more details, guidance, and tips for working with the code base,
71+
see [DEVELOPING.md](DEVELOPING.md)
7672

7773
## Formatting
7874

@@ -99,18 +95,6 @@ $ buildifier --lint=fix --warnings=native-py -warnings=all WORKSPACE
9995

10096
Replace the argument "WORKSPACE" with the file that you are linting.
10197

102-
## Contributor License Agreement
103-
104-
Contributions to this project must be accompanied by a Contributor License
105-
Agreement. You (or your employer) retain the copyright to your contribution,
106-
this simply gives us permission to use and redistribute your contributions as
107-
part of the project. Head over to <https://cla.developers.google.com/> to see
108-
your current agreements on file or to sign a new one.
109-
110-
You generally only need to submit a CLA once, so if you've already submitted one
111-
(even if it was for a different project), you probably don't need to do it
112-
again.
113-
11498
## Code reviews
11599

116100
All submissions, including submissions by project members, require review. We
@@ -198,30 +182,14 @@ merged:
198182
`compile_pip_requirements` update target, which is usually in the same directory.
199183
e.g. `bazel run //docs:requirements.update`
200184

201-
## Core rules
202-
203-
The bulk of this repo is owned and maintained by the Bazel Python community.
204-
However, since the core Python rules (`py_binary` and friends) are still
205-
bundled with Bazel itself, the Bazel team retains ownership of their stubs in
206-
this repository. This will be the case at least until the Python rules are
207-
fully migrated to Starlark code.
208-
209-
Practically, this means that a Bazel team member should approve any PR
210-
concerning the core Python logic. This includes everything under the `python/`
211-
directory except for `pip.bzl` and `requirements.txt`.
212-
213-
Issues should be triaged as follows:
185+
## Binary artifacts
214186

215-
- Anything concerning the way Bazel implements the core Python rules should be
216-
filed under [bazelbuild/bazel](https://github.com/bazelbuild/bazel), using
217-
the label `team-Rules-python`.
187+
Checking in binary artifacts is not allowed. This is because they are extremely
188+
problematic to verify and ensure they're safe
218189

219-
- If the issue specifically concerns the rules_python stubs, it should be filed
220-
here in this repository and use the label `core-rules`.
190+
Examples include, but aren't limited to: prebuilt binaries, shared libraries,
191+
zip files, or wheels.
221192

222-
- Anything else, such as feature requests not related to existing core rules
223-
functionality, should also be filed in this repository but without the
224-
`core-rules` label.
225193

226194
(breaking-changes)=
227195
## Breaking Changes

DEVELOPING.md

Lines changed: 82 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,104 @@
11
# For Developers
22

3-
## Updating internal dependencies
3+
This document covers tips and guidance for working on the rules_python code
4+
base. A primary audience for it is first time contributors.
45

5-
1. Modify the `./python/private/pypi/requirements.txt` file and run:
6-
```
7-
bazel run //private:whl_library_requirements.update
8-
```
9-
1. Run the following target to update `twine` dependencies:
10-
```
11-
bazel run //private:requirements.update
12-
```
13-
1. Bump the coverage dependencies using the script using:
14-
```
15-
bazel run //tools/private/update_deps:update_coverage_deps <VERSION>
16-
# for example:
17-
# bazel run //tools/private/update_deps:update_coverage_deps 7.6.1
18-
```
6+
## Running tests
7+
8+
Running tests is particularly easy thanks to Bazel, simply run:
9+
10+
```
11+
bazel test //...
12+
```
1913

20-
## Releasing
14+
And it will run all the tests it can find. The first time you do this, it will
15+
probably take long time because various dependencies will need to be downloaded
16+
and setup. Subsequent runs will be faster, but there are many tests, and some of
17+
them are slow. If you're working on a particular area of code, you can run just
18+
the tests in those directories instead, which can speed up your edit-run cycle.
2119

22-
Start from a clean checkout at `main`.
20+
## Writing Tests
2321

24-
Before running through the release it's good to run the build and the tests locally, and make sure CI is passing. You can
25-
also test-drive the commit in an existing Bazel workspace to sanity check functionality.
22+
Most code should have tests of some sort. This helps us have confidence that
23+
refactors didn't break anything and that releases won't have regressions.
2624

27-
### Releasing from HEAD
25+
We don't require 100% test coverage, testing certain Bazel functionality is
26+
difficult, and some edge cases are simply too hard to test or not worth the
27+
extra complexity. We try to judiciously decide when not having tests is a good
28+
idea.
2829

29-
#### Steps
30-
1. [Determine the next semantic version number](#determining-semantic-version)
31-
1. Create a tag and push, e.g. `git tag 0.5.0 upstream/main && git push upstream --tags`
32-
NOTE: Pushing the tag will trigger release automation.
33-
1. Watch the release automation run on https://github.com/bazelbuild/rules_python/actions
34-
1. Add missing information to the release notes. The automatic release note
35-
generation only includes commits associated with issues.
30+
Tests go under `tests/`. They are loosely organized into directories for the
31+
particular subsystem or functionality they are testing. If an existing directory
32+
doesn't seem like a good match for the functionality being testing, then it's
33+
fine to create a new directory.
3634

37-
#### Determining Semantic Version
35+
Re-usable test helpers and support code go in `tests/support`. Tests don't need
36+
to be perfectly factored and not every common thing a test does needs to be
37+
factored into a more generally reusable piece. Copying and pasting is fine. It's
38+
more important for tests to balance understandability and maintainability.
3839

39-
**rules_python** is currently using [Zero-based versioning](https://0ver.org/) and thus backwards-incompatible API
40-
changes still come under the minor-version digit. So releases with API changes and new features bump the minor, and
41-
those with only bug fixes and other minor changes bump the patch digit.
40+
### sh_py_run_test
4241

43-
To find if there were any features added or incompatible changes made, review
44-
the commit history. This can be done using github by going to the url:
45-
`https://github.com/bazelbuild/rules_python/compare/<VERSION>...main`.
42+
The [`sh_py_run_test`](tests/support/sh_py_run_test.bzl) rule is a helper to
43+
make it easy to run a Python program with custom build settings using a shell
44+
script to perform setup and verification. This is best to use when verifying
45+
behavior needs certain environment variables or directory structures to
46+
correctly and reliably verify behavior.
4647

47-
### Patch release with cherry picks
48+
When adding a test, you may find the flag you need to set isn't supported by
49+
the rule. To have it support setting a new flag, see the py_reconfig_test docs
50+
below.
4851

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+
### py_reconfig_test
5253

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`.
54+
The `py_reconfig_test` and `py_reconfig_binary` rules are helpers for running
55+
Python binaries and tests with custom build flags. This is best to use when
56+
verifying behavior that requires specific flags to be set and when the program
57+
itself can verify the desired state.
5558

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.
60-
1. `git cherry-pick --continue` (if applicable)
61-
1. `git push upstream`
59+
When adding a test, you may find the flag you need to set isn't supported by
60+
the rule. To have it support setting a new flag:
6261

63-
If multiple commits need to be applied, repeat the `git cherry-pick` step for
64-
each.
62+
* Add an attribute to the rule. It should have the same name as the flag
63+
it's for. It should be a string, string_list, or label attribute -- this
64+
allows distinguishing between if the value was specified or not.
65+
* Modify the transition and add the flag to both the inputs and outputs
66+
list, then modify the transition's logic to check the attribute and set
67+
the flag value if the attribute is set.
6568

66-
Once the release branch is in the desired state, use `git tag` to tag it, as
67-
done with a release from head. Release automation will do the rest.
69+
### Integration tests
6870

69-
#### After release creation in Github
71+
An integration test is one that runs a separate Bazel instance inside the test.
72+
These tests are discouraged unless absolutely necessary because they are slow,
73+
require much memory and CPU, and are generally harder to debug. Integration
74+
tests are reserved for things that simple can't be tested otherwise, or for
75+
simple high level verification tests.
7076

71-
1. Announce the release in the #python channel in the Bazel slack (bazelbuild.slack.com).
77+
Integration tests live in `tests/integration`. When possible, add to an existing
78+
integration test.
7279

73-
## Secrets
80+
## Updating internal dependencies
81+
82+
1. Modify the `./python/private/pypi/requirements.txt` file and run:
83+
```
84+
bazel run //private:whl_library_requirements.update
85+
```
86+
1. Run the following target to update `twine` dependencies:
87+
```
88+
bazel run //private:requirements.update
89+
```
90+
1. Bump the coverage dependencies using the script using:
91+
```
92+
bazel run //tools/private/update_deps:update_coverage_deps <VERSION>
93+
# for example:
94+
# bazel run //tools/private/update_deps:update_coverage_deps 7.6.1
95+
```
7496

75-
### PyPI user rules-python
97+
## Updating tool dependencies
7698

77-
Part of the release process uploads packages to PyPI as the user `rules-python`.
78-
This account is managed by Google; contact [email protected] if
79-
something needs to be done with the PyPI account.
99+
It's suggested to routinely update the tool versions within our repo - some of the
100+
tools are using requirement files compiled by `uv` and others use other means. In order
101+
to have everything self-documented, we have a special target -
102+
`//private:requirements.update`, which uses `rules_multirun` to run in sequence all
103+
of the requirement updating scripts in one go. This can be done once per release as
104+
we prepare for releases.

MODULE.bazel

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ module(
77
bazel_dep(name = "bazel_features", version = "1.21.0")
88
bazel_dep(name = "bazel_skylib", version = "1.7.1")
99
bazel_dep(name = "rules_cc", version = "0.0.16")
10-
bazel_dep(name = "platforms", version = "0.0.4")
10+
bazel_dep(name = "platforms", version = "0.0.11")
1111

1212
# Those are loaded only when using py_proto_library
13-
bazel_dep(name = "rules_proto", version = "7.0.2")
13+
# Use py_proto_library directly from protobuf repository
1414
bazel_dep(name = "protobuf", version = "29.0-rc2", repo_name = "com_google_protobuf")
1515

1616
internal_deps = use_extension("//python/private:internal_deps.bzl", "internal_deps")
@@ -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.

0 commit comments

Comments
 (0)