Skip to content

Commit 6dcef51

Browse files
committed
fix: treat ignore_root_user_error either ignored or warning
1 parent f685fe9 commit 6dcef51

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Unreleased changes template.
6969
* (toolchains) Remove all but `3.8.20` versions of the Python `3.8` interpreter who has
7070
reached EOL. If users still need other versions of the `3.8` interpreter, please supply
7171
the URLs manually {bzl:ob}`python.toolchain` or {bzl:obj}`python_register_toolchains` calls.
72+
* (toolchains) Previously [#2636](https://github.com/bazel-contrib/rules_python/pull/2636) changed the semantics of `ignore_root_user_error` from "ignore" to "warning". This is now flipped back to ignoring the issue, and will only emit a warning when the attribute is set `False`.
7273

7374
[20250317]: https://github.com/astral-sh/python-build-standalone/releases/tag/20250317
7475

python/private/python.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ to spurious cache misses or build failures).
803803
However, if the user is running Bazel as root, this read-onlyness is not
804804
respected. Bazel will print a warning message when it detects that the runtime
805805
installation is writable despite being made read only (i.e. it's running with
806-
root access). If this attribute is set to `False`, Bazel will make it a hard
807-
error to run with root access instead.
806+
root access) while this attribute is set `False`, however this messaging can be ignored by setting
807+
this to `False`.
808808
""",
809809
mandatory = False,
810810
),

python/private/python_repository.bzl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,28 +137,30 @@ def _python_repository_impl(rctx):
137137
logger = logger,
138138
)
139139

140-
fail_or_warn = logger.warn if rctx.attr.ignore_root_user_error else logger.fail
141-
exec_result = repo_utils.execute_unchecked(
142-
rctx,
143-
op = "python_repository.TestReadOnly",
144-
arguments = [repo_utils.which_checked(rctx, "touch"), "lib/.test"],
145-
logger = logger,
146-
)
147-
148-
# The issue with running as root is the installation is no longer
149-
# read-only, so the problems due to pyc can resurface.
150-
if exec_result.return_code == 0:
151-
stdout = repo_utils.execute_checked_stdout(
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(
152144
rctx,
153-
op = "python_repository.GetUserId",
154-
arguments = [repo_utils.which_checked(rctx, "id"), "-u"],
145+
op = "python_repository.TestReadOnly",
146+
arguments = [repo_utils.which_checked(rctx, "touch"), "lib/.test"],
155147
logger = logger,
156148
)
157-
uid = int(stdout.strip())
158-
if uid == 0:
159-
fail_or_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.")
160-
else:
161-
fail_or_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.")
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.")
162164

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

0 commit comments

Comments
 (0)