Skip to content

Commit f94c195

Browse files
authored
python_repository: Exclude pycache files (bazel-contrib#907)
python_repository: Exclude pycache files when root Some of these are missing from the upstream python distributions, and when they are, if running as root, this causes the files to be generated the first time their associated .py file is evaluated, causing analysis and execution cache misses due to extra files matching the repository glob.
1 parent ba45af0 commit f94c195

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

python/repositories.bzl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,20 @@ def _python_repository_impl(rctx):
196196

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

199+
glob_include = []
200+
201+
if rctx.attr.ignore_root_user_error:
202+
glob_include += [
203+
"# These pycache files are created on first use of the associated python files.",
204+
"# Exclude them from the glob because otherwise between the first time and second time a python toolchain is used,",
205+
"# the definition of this filegroup will change, and depending rules will get invalidated.",
206+
"# See https://github.com/bazelbuild/rules_python/issues/1008 for unconditionally adding these to toolchains so we can stop ignoring them.",
207+
"**/__pycache__/*.pyc",
208+
"**/__pycache__/*.pyo",
209+
]
210+
199211
if "windows" in platform:
200-
glob_include = [
212+
glob_include += [
201213
"*.exe",
202214
"*.dll",
203215
"bin/**",
@@ -210,7 +222,7 @@ def _python_repository_impl(rctx):
210222
"share/**",
211223
]
212224
else:
213-
glob_include = [
225+
glob_include += [
214226
"bin/**",
215227
"extensions/**",
216228
"include/**",

0 commit comments

Comments
 (0)