Skip to content

Commit 23397d5

Browse files
authored
chore(toolchain): remove chmod and disable ignore_root_error (#3421)
As discussed in the #2024 messaged we decided to remove the chmoding and simplify the setup for all of our users. This in effect unifies how the toolchains are created across all of the platforms reducing the need for some of the integration tests. Summary: - `python_repository`: stop chmoding - `python_repository`: make `ignore_root_user_error` noop - `python(bzlmod)`: stop using `ignore_root_user_error`. - `tests`: remove `ignore_root_user_error` tests. Fixes #2016 Fixes #2053 Closes #2024
1 parent 8775555 commit 23397d5

File tree

19 files changed

+20
-330
lines changed

19 files changed

+20
-330
lines changed

.bazelci/presubmit.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -615,19 +615,6 @@ tasks:
615615
- "git diff --exit-code"
616616

617617

618-
integration_test_ignore_root_user_error_macos_workspace:
619-
<<: *reusable_build_test_all
620-
<<: *common_workspace_flags
621-
name: "ignore_root_user_error: macOS, workspace"
622-
working_directory: tests/integration/ignore_root_user_error
623-
platform: macos
624-
integration_test_ignore_root_user_error_windows_workspace:
625-
<<: *reusable_build_test_all
626-
<<: *common_workspace_flags
627-
name: "ignore_root_user_error: Windows, workspace"
628-
working_directory: tests/integration/ignore_root_user_error
629-
platform: windows
630-
631618
integration_compile_pip_requirements_test_from_external_repo_ubuntu_min_workspace:
632619
<<: *minimum_supported_version
633620
<<: *common_workspace_flags_min_bazel

.bazelignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ gazelle/examples/bzlmod_build_file_generation/bazel-bzlmod_build_file_generation
3131
gazelle/examples/bzlmod_build_file_generation/bazel-out
3232
gazelle/examples/bzlmod_build_file_generation/bazel-testlog
3333
tests/integration/compile_pip_requirements/bazel-compile_pip_requirements
34-
tests/integration/ignore_root_user_error/bazel-ignore_root_user_error
3534
tests/integration/local_toolchains/bazel-local_toolchains
3635
tests/integration/py_cc_toolchain_registered/bazel-py_cc_toolchain_registered

.bazelrc.deleted_packages

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ common --deleted_packages=gazelle/python/private
4040
common --deleted_packages=tests/integration/compile_pip_requirements
4141
common --deleted_packages=tests/integration/compile_pip_requirements_test_from_external_repo
4242
common --deleted_packages=tests/integration/custom_commands
43-
common --deleted_packages=tests/integration/ignore_root_user_error
44-
common --deleted_packages=tests/integration/ignore_root_user_error/submodule
4543
common --deleted_packages=tests/integration/local_toolchains
4644
common --deleted_packages=tests/integration/pip_parse
4745
common --deleted_packages=tests/integration/pip_parse/empty

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ END_UNRELEASED_TEMPLATE
6262
* (toolchain) Remove all of the python 3.9 toolchain versions except for the `3.9.25`.
6363
This version has reached EOL and will no longer receive any security fixes, please update to
6464
`3.10` or above. ([#2704](https://github.com/bazel-contrib/rules_python/issues/2704))
65+
* (toolchain) `ignore_root_user_error` has now been flipped to be always enabled and
66+
the `chmod` of the python toolchain directories have been removed. From now on `rules_python`
67+
always adds the `pyc` files to the glob excludes and in order to avoid any problems when using
68+
the toolchains in the repository phase, ensure that you pass `-B` to the python interpreter.
69+
([#2016](https://github.com/bazel-contrib/rules_python/issues/2016))
6570

6671
{#v0-0-0-changed}
6772
### Changed

python/private/python.bzl

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ def parse_modules(*, module_ctx, logger, _fail = fail):
7676
# Map of string Major.Minor or Major.Minor.Patch to the toolchain_info struct
7777
global_toolchain_versions = {}
7878

79-
ignore_root_user_error = None
80-
81-
# if the root module does not register any toolchain then the
82-
# ignore_root_user_error takes its default value: True
83-
if not module_ctx.modules[0].tags.toolchain:
84-
ignore_root_user_error = True
85-
8679
config = _get_toolchain_config(modules = module_ctx.modules, _fail = _fail)
8780

8881
default_python_version = _compute_default_python_version(module_ctx)
@@ -115,15 +108,6 @@ def parse_modules(*, module_ctx, logger, _fail = fail):
115108
# * The root module is allowed to override the rules_python default.
116109
is_default = default_python_version == toolchain_version
117110

118-
# Also only the root module should be able to decide ignore_root_user_error.
119-
# Modules being depended upon don't know the final environment, so they aren't
120-
# in the right position to know or decide what the correct setting is.
121-
122-
# If an inconsistency in the ignore_root_user_error among multiple toolchains is detected, fail.
123-
if ignore_root_user_error != None and toolchain_attr.ignore_root_user_error != ignore_root_user_error:
124-
fail("Toolchains in the root module must have consistent 'ignore_root_user_error' attributes")
125-
126-
ignore_root_user_error = toolchain_attr.ignore_root_user_error
127111
elif mod.name == "rules_python" and not default_toolchain:
128112
# This branch handles when the root module doesn't declare a
129113
# Python toolchain
@@ -166,7 +150,6 @@ def parse_modules(*, module_ctx, logger, _fail = fail):
166150
global_toolchain_versions[toolchain_version] = toolchain_info
167151
if debug_info:
168152
debug_info["toolchains_registered"].append({
169-
"ignore_root_user_error": ignore_root_user_error,
170153
"module": {"is_root": mod.is_root, "name": mod.name},
171154
"name": toolchain_name,
172155
})
@@ -185,8 +168,6 @@ def parse_modules(*, module_ctx, logger, _fail = fail):
185168
elif toolchain_info:
186169
toolchains.append(toolchain_info)
187170

188-
config.default.setdefault("ignore_root_user_error", ignore_root_user_error)
189-
190171
# A default toolchain is required so that the non-version-specific rules
191172
# are able to match a toolchain.
192173
if default_toolchain == None:
@@ -722,7 +703,6 @@ def _process_global_overrides(*, tag, default, _fail = fail):
722703
default["minor_mapping"] = tag.minor_mapping
723704

724705
forwarded_attrs = sorted(AUTH_ATTRS) + [
725-
"ignore_root_user_error",
726706
"base_url",
727707
"register_all_versions",
728708
]
@@ -974,7 +954,6 @@ def _create_toolchain_attrs_struct(
974954
is_default = is_default,
975955
python_version = python_version if python_version else tag.python_version,
976956
configure_coverage_tool = getattr(tag, "configure_coverage_tool", False),
977-
ignore_root_user_error = getattr(tag, "ignore_root_user_error", True),
978957
)
979958

980959
_defaults = tag_class(
@@ -1086,16 +1065,9 @@ Then the python interpreter will be available as `my_python_name`.
10861065
"ignore_root_user_error": attr.bool(
10871066
default = True,
10881067
doc = """\
1089-
The Python runtime installation is made read only. This improves the ability for
1090-
Bazel to cache it by preventing the interpreter from creating `.pyc` files for
1091-
the standard library dynamically at runtime as they are loaded (this often leads
1092-
to spurious cache misses or build failures).
1093-
1094-
However, if the user is running Bazel as root, this read-onlyness is not
1095-
respected. Bazel will print a warning message when it detects that the runtime
1096-
installation is writable despite being made read only (i.e. it's running with
1097-
root access) while this attribute is set `False`, however this messaging can be ignored by setting
1098-
this to `False`.
1068+
:::{versionchanged} VERSION_NEXT_FEATURE
1069+
Noop, will be removed in the next major release.
1070+
:::
10991071
""",
11001072
mandatory = False,
11011073
),

python/private/python_repository.bzl

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -123,45 +123,6 @@ def _python_repository_impl(rctx):
123123
logger = logger,
124124
)
125125

126-
# Make the Python installation read-only. This is to prevent issues due to
127-
# pycs being generated at runtime:
128-
# * The pycs are not deterministic (they contain timestamps)
129-
# * Multiple processes trying to write the same pycs can result in errors.
130-
#
131-
# Note, when on Windows the `chmod` may not work
132-
if "windows" not in platform and "windows" != repo_utils.get_platforms_os_name(rctx):
133-
repo_utils.execute_checked(
134-
rctx,
135-
op = "python_repository.MakeReadOnly",
136-
arguments = [repo_utils.which_checked(rctx, "chmod"), "-R", "ugo-w", "lib"],
137-
logger = logger,
138-
)
139-
140-
# If the user is not ignoring the warnings, then proceed to run a check,
141-
# otherwise these steps can be skipped, as they both result in some warning.
142-
if not rctx.attr.ignore_root_user_error:
143-
exec_result = repo_utils.execute_unchecked(
144-
rctx,
145-
op = "python_repository.TestReadOnly",
146-
arguments = [repo_utils.which_checked(rctx, "touch"), "lib/.test"],
147-
logger = logger,
148-
)
149-
150-
# The issue with running as root is the installation is no longer
151-
# read-only, so the problems due to pyc can resurface.
152-
if exec_result.return_code == 0:
153-
stdout = repo_utils.execute_checked_stdout(
154-
rctx,
155-
op = "python_repository.GetUserId",
156-
arguments = [repo_utils.which_checked(rctx, "id"), "-u"],
157-
logger = logger,
158-
)
159-
uid = int(stdout.strip())
160-
if uid == 0:
161-
logger.warn("The current user is root, which can cause spurious cache misses or build failures with the hermetic Python interpreter. See https://github.com/bazel-contrib/rules_python/pull/713.")
162-
else:
163-
logger.warn("The current user has CAP_DAC_OVERRIDE set, which can cause spurious cache misses or build failures with the hermetic Python interpreter. See https://github.com/bazel-contrib/rules_python/pull/713.")
164-
165126
python_bin = "python.exe" if ("windows" in platform) else "bin/python3"
166127

167128
if "linux" in platform:
@@ -186,17 +147,15 @@ def _python_repository_impl(rctx):
186147
break
187148

188149
glob_include = []
189-
glob_exclude = []
190-
if rctx.attr.ignore_root_user_error or "windows" in platform:
191-
glob_exclude += [
192-
# These pycache files are created on first use of the associated python files.
193-
# Exclude them from the glob because otherwise between the first time and second time a python toolchain is used,"
194-
# the definition of this filegroup will change, and depending rules will get invalidated."
195-
# See https://github.com/bazel-contrib/rules_python/issues/1008 for unconditionally adding these to toolchains so we can stop ignoring them."
196-
# pyc* is ignored because pyc creation creates temporary .pyc.NNNN files
197-
"**/__pycache__/*.pyc*",
198-
"**/__pycache__/*.pyo*",
199-
]
150+
glob_exclude = [
151+
# These pycache files are created on first use of the associated python files.
152+
# Exclude them from the glob because otherwise between the first time and second time a python toolchain is used,"
153+
# the definition of this filegroup will change, and depending rules will get invalidated."
154+
# See https://github.com/bazel-contrib/rules_python/issues/1008 for unconditionally adding these to toolchains so we can stop ignoring them."
155+
# pyc* is ignored because pyc creation creates temporary .pyc.NNNN files
156+
"**/__pycache__/*.pyc*",
157+
"**/__pycache__/*.pyo*",
158+
]
200159

201160
if "windows" in platform:
202161
glob_include += [
@@ -249,7 +208,6 @@ define_hermetic_runtime_toolchain_impl(
249208
"coverage_tool": rctx.attr.coverage_tool,
250209
"distutils": rctx.attr.distutils,
251210
"distutils_content": rctx.attr.distutils_content,
252-
"ignore_root_user_error": rctx.attr.ignore_root_user_error,
253211
"name": rctx.attr.name,
254212
"netrc": rctx.attr.netrc,
255213
"patch_strip": rctx.attr.patch_strip,
@@ -299,7 +257,7 @@ For more information see {attr}`py_runtime.coverage_tool`.
299257
),
300258
"ignore_root_user_error": attr.bool(
301259
default = True,
302-
doc = "Whether the check for root should be ignored or not. This causes cache misses with .pyc files.",
260+
doc = "Noop, will be removed in the next major release",
303261
mandatory = False,
304262
),
305263
"netrc": attr.string(

tests/integration/BUILD.bazel

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,6 @@ rules_python_integration_test(
7575
workspace_path = "compile_pip_requirements",
7676
)
7777

78-
rules_python_integration_test(
79-
name = "ignore_root_user_error_test",
80-
env = {
81-
"RULES_PYTHON_BZLMOD_DEBUG": "1",
82-
},
83-
)
84-
85-
rules_python_integration_test(
86-
name = "ignore_root_user_error_workspace_test",
87-
bzlmod = False,
88-
env = {
89-
"RULES_PYTHON_BZLMOD_DEBUG": "1",
90-
},
91-
workspace_path = "ignore_root_user_error",
92-
)
93-
9478
rules_python_integration_test(
9579
name = "local_toolchains_test",
9680
env = {

tests/integration/ignore_root_user_error/.bazelrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/integration/ignore_root_user_error/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/integration/ignore_root_user_error/BUILD.bazel

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)