Skip to content

Commit d34cf10

Browse files
authored
Merge branch 'bazelbuild:main' into main
2 parents 3c4c15a + d598085 commit d34cf10

Some content is hidden

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

55 files changed

+1804
-146
lines changed

.bazelci/presubmit.yml

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ platforms:
3636
- "-//gazelle/..."
3737
# The dependencies needed for this test are not cross-platform: https://github.com/bazelbuild/rules_python/issues/260
3838
- "-//tests:pip_repository_entry_points_example"
39+
test_flags:
40+
- "--test_tag_filters=-fix-windows"

.bazelrc

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# This lets us glob() up all the files inside the examples to make them inputs to tests
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, run tools/bazel_integration_test/update_deleted_packages.sh
6-
build --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points
7-
query --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points
6+
build --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points
7+
query --deleted_packages=examples/build_file_generation,examples/pip_install,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_import,examples/relative_requirements,tests/pip_repository_entry_points
88

99
test --test_output=errors
1010

@@ -18,3 +18,5 @@ build --incompatible_default_to_explicit_init_py
1818

1919
# Windows makes use of runfiles for some rules
2020
build --enable_runfiles
21+
# TODO(f0rmiga): remove this so that other features don't start relying on it.
22+
startup --windows_enable_symlinks

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs/*.md linguist-generated=true

.github/CODEOWNERS

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# NB: Last matching rule takes precedence in CODEOWNERS.
22

33
# Fall-through to community maintainers.
4-
* @thundergolfer @andyscott
4+
* @thundergolfer
55

66
# Core Python rules belong to the Bazel team.
77
/python/ @brandjon @lberki
88
# But not everything under python/ is the core Python rules.
9-
/python/pip.bzl @thundergolfer @andyscott
10-
/python/requirements.txt @thundergolfer @andyscott
9+
/python/pip.bzl @thundergolfer
10+
/python/requirements.txt @thundergolfer
1111

1212
# Directory containing the Gazelle extension and Go code.
1313
/gazelle/ @f0rmiga

.github/workflows/workspace_snippet.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -o errexit -o nounset -o pipefail
55
# Set by GH actions, see
66
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
77
TAG=${GITHUB_REF_NAME}
8-
PREFIX="rules_python-${TAG:1}"
8+
PREFIX="rules_python-${TAG}"
99
SHA=$(git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip | shasum -a 256 | awk '{print $1}')
1010

1111
cat << EOF
@@ -17,7 +17,7 @@ http_archive(
1717
name = "rules_python",
1818
sha256 = "${SHA}",
1919
strip_prefix = "${PREFIX}",
20-
url = "https://github.com/bazelbuild/rules_python/archive/${TAG}.tar.gz",
20+
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/${TAG}.tar.gz",
2121
)
2222
\`\`\`
2323
EOF

README.md

+33-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,37 @@ http_archive(
5454
)
5555
```
5656

57+
### Toolchain registration
58+
59+
To register a hermetic Python toolchain rather than rely on a system-installed interpreter for runtime execution, you can add to the `WORKSPACE` file:
60+
61+
```python
62+
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
63+
64+
python_register_toolchains(
65+
name = "python3_9",
66+
# Available versions are listed in @rules_python//python:versions.bzl.
67+
# We recommend using the same version your team is already standardized on.
68+
python_version = "3.9",
69+
)
70+
71+
load("@python3_9//:defs.bzl", "interpreter")
72+
73+
load("@rules_python//python:pip.bzl", "pip_parse")
74+
75+
pip_parse(
76+
...
77+
python_interpreter_target = interpreter,
78+
...
79+
)
80+
```
81+
82+
After registration, your Python targets will use the toolchain's interpreter during execution, but a system-installed interpreter
83+
is still used to 'bootstrap' Python targets (see https://github.com/bazelbuild/rules_python/issues/691).
84+
You may also find some quirks while using this toolchain. Please refer to [python-build-standalone documentation's _Quirks_ section](https://python-build-standalone.readthedocs.io/en/latest/quirks.html) for details.
85+
86+
### "Hello World"
87+
5788
Once you've imported the rule set into your `WORKSPACE` using any of these
5889
methods, you can then load the core rules in your `BUILD` files with:
5990

@@ -109,8 +140,8 @@ one another, and may result in downloading the same wheels multiple times.
109140

110141
As with any repository rule, if you would like to ensure that `pip_install` is
111142
re-executed in order to pick up a non-hermetic change to your environment (e.g.,
112-
updating your system `python` interpreter), you can completely flush out your
113-
repo cache with `bazel clean --expunge`.
143+
updating your system `python` interpreter), you can force it to re-execute by running
144+
`bazel sync --only [pip_install name]`.
114145

115146
### Fetch `pip` dependencies lazily
116147

WORKSPACE

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ load("//:internal_setup.bzl", "rules_python_internal_setup")
2525

2626
rules_python_internal_setup()
2727

28+
load("//python:repositories.bzl", "python_register_toolchains")
29+
load("//python:versions.bzl", "MINOR_MAPPING")
30+
31+
python_register_toolchains(
32+
name = "python",
33+
# We always use the latest Python internally.
34+
python_version = MINOR_MAPPING.values()[-1],
35+
)
36+
2837
load("//gazelle:deps.bzl", "gazelle_deps")
2938

3039
# gazelle:repository_macro gazelle/deps.bzl%gazelle_deps

docs/BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ licenses(["notice"]) # Apache 2.0
2424
_DOCS = {
2525
"packaging": "//docs:packaging-docs",
2626
"pip": "//docs:pip-docs",
27+
"pip_repository": "//docs:pip-repository",
2728
"python": "//docs:core-docs",
2829
}
2930

@@ -104,6 +105,18 @@ stardoc(
104105
],
105106
)
106107

108+
stardoc(
109+
name = "pip-repository",
110+
out = "pip_repository.md_",
111+
input = "//python/pip_install:pip_repository.bzl",
112+
target_compatible_with = _NOT_WINDOWS,
113+
deps = [
114+
":bazel_repo_tools",
115+
":pip_install_bzl",
116+
"//third_party/github.com/bazelbuild/bazel-skylib/lib:versions",
117+
],
118+
)
119+
107120
stardoc(
108121
name = "packaging-docs",
109122
out = "packaging.md_",

docs/pip.md

+26-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)