Skip to content

Commit 833da00

Browse files
Merge branch 'main' into cross-platform-wheel-download
2 parents 02fafaf + ac5b973 commit 833da00

File tree

6 files changed

+61
-20
lines changed

6 files changed

+61
-20
lines changed

gazelle/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This directory contains a plugin for
44
[Gazelle](https://github.com/bazelbuild/bazel-gazelle)
55
that generates BUILD file content for Python code.
66

7+
It requires Go 1.16+ to compile.
8+
79
## Installation
810

911
First, you'll need to add Gazelle to your `WORKSPACE` file.

gazelle/generate.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package python
22

33
import (
44
"fmt"
5+
"io/fs"
56
"log"
67
"os"
78
"path/filepath"
@@ -29,9 +30,6 @@ const (
2930

3031
var (
3132
buildFilenames = []string{"BUILD", "BUILD.bazel"}
32-
// errHaltDigging is an error that signals whether the generator should halt
33-
// digging the source tree searching for modules in subdirectories.
34-
errHaltDigging = fmt.Errorf("halt digging")
3533
)
3634

3735
// GenerateRules extracts build metadata from source files in a directory.
@@ -106,9 +104,9 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
106104
// boundaryPackages represents child Bazel packages that are used as a
107105
// boundary to stop processing under that tree.
108106
boundaryPackages := make(map[string]struct{})
109-
err := filepath.Walk(
107+
err := filepath.WalkDir(
110108
filepath.Join(args.Dir, d),
111-
func(path string, info os.FileInfo, err error) error {
109+
func(path string, entry fs.DirEntry, err error) error {
112110
if err != nil {
113111
return err
114112
}
@@ -120,7 +118,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
120118
return nil
121119
}
122120
}
123-
if info.IsDir() {
121+
if entry.IsDir() {
124122
// If we are visiting a directory, we determine if we should
125123
// halt digging the tree based on a few criterias:
126124
// 1. The directory has a BUILD or BUILD.bazel files. Then
@@ -135,7 +133,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
135133
}
136134

137135
if !cfg.CoarseGrainedGeneration() && hasEntrypointFile(path) {
138-
return errHaltDigging
136+
return fs.SkipDir
139137
}
140138

141139
return nil
@@ -168,7 +166,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
168166
return nil
169167
},
170168
)
171-
if err != nil && err != errHaltDigging {
169+
if err != nil {
172170
log.Printf("ERROR: %v\n", err)
173171
return language.GenerateResult{}
174172
}

python/pip_install/repositories.bzl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
77
load("//third_party/github.com/bazelbuild/bazel-skylib/lib:versions.bzl", "versions")
88

99
_RULE_DEPS = [
10+
(
11+
"pypi__build",
12+
"https://files.pythonhosted.org/packages/7a/24/ee8271da317b692fcb9d026ff7f344ac6c4ec661a97f0e2a11fa7992544a/build-0.8.0-py3-none-any.whl",
13+
"19b0ed489f92ace6947698c3ca8436cb0556a66e2aa2d34cd70e2a5d27cd0437",
14+
),
1015
(
1116
"pypi__click",
1217
"https://files.pythonhosted.org/packages/76/0a/b6c5f311e32aeb3b406e03c079ade51e905ea630fc19d1262a46249c1c86/click-8.0.1-py3-none-any.whl",
@@ -22,20 +27,30 @@ _RULE_DEPS = [
2227
"https://files.pythonhosted.org/packages/1b/21/3e6ebd12d8dccc55bcb7338db462c75ac86dbd0ac7439ac114616b21667b/installer-0.5.1-py3-none-any.whl",
2328
"1d6c8d916ed82771945b9c813699e6f57424ded970c9d8bf16bbc23e1e826ed3",
2429
),
30+
(
31+
"pypi__packaging",
32+
"https://files.pythonhosted.org/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl",
33+
"ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522",
34+
),
2535
(
2636
"pypi__pep517",
2737
"https://files.pythonhosted.org/packages/f4/67/846c08e18fefb265a66e6fd5a34269d649b779718d9bf59622085dabd370/pep517-0.12.0-py2.py3-none-any.whl",
2838
"dd884c326898e2c6e11f9e0b64940606a93eb10ea022a2e067959f3a110cf161",
2939
),
3040
(
3141
"pypi__pip",
32-
"https://files.pythonhosted.org/packages/96/2f/caec18213f6a67852f6997fb0673ae08d2e93d1b81573edb93ba4ef06970/pip-22.1.2-py3-none-any.whl",
33-
"a3edacb89022ef5258bf61852728bf866632a394da837ca49eb4303635835f17",
42+
"https://files.pythonhosted.org/packages/84/25/5734a44897751d8bac6822efb819acda2d969bcc1b915bbd7d48102952cb/pip-22.2.1-py3-none-any.whl",
43+
"0bbbc87dfbe6eed217beff0021f8b7dea04c8f4a0baa9d31dc4cff281ffc5b2b",
3444
),
3545
(
3646
"pypi__pip_tools",
37-
"https://files.pythonhosted.org/packages/fe/5c/8995799b0ccf832906b4968b4eb2045beb9b3de79e96e6b1a6e4fc4e6974/pip_tools-6.6.2-py3-none-any.whl",
38-
"6b486548e5a139e30e4c4a225b3b7c2d46942a9f6d1a91143c21b1de4d02fd9b",
47+
"https://files.pythonhosted.org/packages/bf/3a/a8b09ca5ea24e4ddfa4d2cdf885e8c6618a4b658b32553f897f948aa0f67/pip_tools-6.8.0-py3-none-any.whl",
48+
"3e5cd4acbf383d19bdfdeab04738b6313ebf4ad22ce49bf529c729061eabfab8",
49+
),
50+
(
51+
"pypi__pyparsing",
52+
"https://files.pythonhosted.org/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl",
53+
"5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc",
3954
),
4055
(
4156
"pypi__setuptools",

python/pip_install/requirements.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def compile_pip_requirements(
6868
] + extra_args
6969

7070
deps = [
71+
requirement("build"),
7172
requirement("click"),
7273
requirement("colorama"),
7374
requirement("pep517"),

python/private/toolchains_repo.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _toolchains_repo_impl(rctx):
4848
# for executing build actions.
4949
toolchain(
5050
name = "{platform}_toolchain",
51-
exec_compatible_with = {compatible_with},
51+
target_compatible_with = {compatible_with},
5252
toolchain = "@{user_repository_name}_{platform}//:python_runtimes",
5353
toolchain_type = "@bazel_tools//tools/python:toolchain_type",
5454
)

python/repositories.bzl

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,26 @@ def _python_repository_impl(rctx):
108108
rctx.file(distutils_path, rctx.attr.distutils_content)
109109

110110
# Make the Python installation read-only.
111-
if "windows" not in rctx.os.name:
112-
exec_result = rctx.execute(["chmod", "-R", "ugo-w", "lib"])
113-
if exec_result.return_code:
114-
fail_msg = "Failed to make interpreter installation read-only. 'chmod' error msg: {}".format(
115-
exec_result.stderr,
116-
)
117-
fail(fail_msg)
111+
if not rctx.attr.ignore_root_user_error:
112+
if "windows" not in rctx.os.name:
113+
exec_result = rctx.execute(["chmod", "-R", "ugo-w", "lib"])
114+
if exec_result.return_code != 0:
115+
fail_msg = "Failed to make interpreter installation read-only. 'chmod' error msg: {}".format(
116+
exec_result.stderr,
117+
)
118+
fail(fail_msg)
119+
exec_result = rctx.execute(["touch", "lib/.test"])
120+
if exec_result.return_code == 0:
121+
exec_result = rctx.execute(["id", "-u"])
122+
if exec_result.return_code != 0:
123+
fail("Could not determine current user ID. 'id -u' error msg: {}".format(
124+
exec_result.stderr,
125+
))
126+
uid = int(exec_result.stdout.strip())
127+
if uid == 0:
128+
fail("The current user is root, please run as non-root when using the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.")
129+
else:
130+
fail("The current user has CAP_DAC_OVERRIDE set, please drop this capability when using the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.")
118131

119132
python_bin = "python.exe" if ("windows" in platform) else "bin/python3"
120133

@@ -140,8 +153,15 @@ filegroup(
140153
"Scripts/**",
141154
"share/**",
142155
],
156+
# Platform-agnostic filegroup can't match on all patterns.
157+
allow_empty = True,
143158
exclude = [
144159
"**/* *", # Bazel does not support spaces in file names.
160+
# static libraries
161+
"lib/**/*.a",
162+
# tests for the standard libraries.
163+
"lib/python{python_version}/**/test/**",
164+
"lib/python{python_version}/**/tests/**",
145165
],
146166
),
147167
)
@@ -219,6 +239,11 @@ python_repository = repository_rule(
219239
"Either distutils or distutils_content can be specified, but not both.",
220240
mandatory = False,
221241
),
242+
"ignore_root_user_error": attr.bool(
243+
default = False,
244+
doc = "Whether the check for root should be ignored or not. This causes cache misses with .pyc files.",
245+
mandatory = False,
246+
),
222247
"platform": attr.string(
223248
doc = "The platform name for the Python interpreter tarball.",
224249
mandatory = True,

0 commit comments

Comments
 (0)