8000 fix: treat ignore_root_user_error either ignored or warning (#2739) · keith/rules_python@6854dc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6854dc3

Browse files
mattemrickeylev
andauthored
fix: treat ignore_root_user_error either ignored or warning (bazel-contrib#2739)
Previously [bazel-contrib#2636](bazel-contrib#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`. This does also change the semantics of what bazel-contrib#2636 did by flipping the attribute, as now there is no warning, and the user would have to explicitly set it to `False` (they don't want to ignore the error) to see the warning. Co-authored-by: Richard Levasseur <rlevasseur@google.com>
1 parent e5fa023 commit 6854dc3

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ 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:obj}`python.toolchain` or {bzl:obj}`python_register_toolchains` calls.
72+
* (toolchains) Previously [#2636](https://github.com/bazel-contrib/rules_python/pull/2636)
73+
changed the semantics of `ignore_root_user_error` from "ignore" to "warning". This is now
74+
flipped back to ignoring the issue, and will only emit a warning when the attribute is set
75+
`False`.
7276
* (pypi) The PyPI extension will no longer write the lock file entries as the
7377
extension has been marked reproducible.
7478
Fixes [#2434](https://github.com/bazel-contrib/rules_python/issues/2434).

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)
0