From bc0e3a1e8417db8bba8f8b77810d63c50e9b6a3b Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Tue, 31 Jan 2023 22:00:15 -0800 Subject: [PATCH 1/3] Fixed glob includes for ignore_root_user_error --- .bazelci/presubmit.yml | 21 +++++++++++++++++++++ python/repositories.bzl | 8 ++++---- tests/ignore_root_user_error/.bazelrc | 5 +++++ tests/ignore_root_user_error/.gitignore | 1 + tests/ignore_root_user_error/BUILD.bazel | 7 +++++++ tests/ignore_root_user_error/WORKSPACE | 12 ++++++++++++ tests/ignore_root_user_error/foo_test.py | 13 +++++++++++++ 7 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 tests/ignore_root_user_error/.bazelrc create mode 100644 tests/ignore_root_user_error/.gitignore create mode 100644 tests/ignore_root_user_error/BUILD.bazel create mode 100644 tests/ignore_root_user_error/WORKSPACE create mode 100644 tests/ignore_root_user_error/foo_test.py diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index a4003604d0..76f9d8b5aa 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -273,3 +273,24 @@ tasks: name: pip_repository_entry_points integration tests on Windows working_directory: tests/pip_repository_entry_points platform: windows + + integration_test_ignore_root_user_error_ubuntu: + <<: *reusable_build_test_all + name: ignore_root_user_error integration tests on Ubuntu + working_directory: tests/ignore_root_user_error + platform: ubuntu2004 + integration_test_ignore_root_user_error_debian: + <<: *reusable_build_test_all + name: ignore_root_user_error integration tests on Debian + working_directory: tests/ignore_root_user_error + platform: debian11 + integration_test_ignore_root_user_error_macos: + <<: *reusable_build_test_all + name: ignore_root_user_error integration tests on macOS + working_directory: tests/ignore_root_user_error + platform: macos + integration_test_ignore_root_user_error_windows: + <<: *reusable_build_test_all + name: ignore_root_user_error integration tests on Windows + working_directory: tests/ignore_root_user_error + platform: windows diff --git a/python/repositories.bzl b/python/repositories.bzl index faaec64d95..06d6ca70e8 100644 --- a/python/repositories.bzl +++ b/python/repositories.bzl @@ -200,11 +200,11 @@ def _python_repository_impl(rctx): glob_include = [] if rctx.attr.ignore_root_user_error: + # These pycache files are created on first use of the associated python files. + # Exclude them from the glob because otherwise between the first time and second time a python toolchain is used, + # the definition of this filegroup will change, and depending rules will get invalidated. + # See https://github.com/bazelbuild/rules_python/issues/1008 for unconditionally adding these to toolchains so we can stop ignoring them. glob_include += [ - "# These pycache files are created on first use of the associated python files.", - "# Exclude them from the glob because otherwise between the first time and second time a python toolchain is used,", - "# the definition of this filegroup will change, and depending rules will get invalidated.", - "# See https://github.com/bazelbuild/rules_python/issues/1008 for unconditionally adding these to toolchains so we can stop ignoring them.", "**/__pycache__/*.pyc", "**/__pycache__/*.pyo", ] diff --git a/tests/ignore_root_user_error/.bazelrc b/tests/ignore_root_user_error/.bazelrc new file mode 100644 index 0000000000..f23315a7a1 --- /dev/null +++ b/tests/ignore_root_user_error/.bazelrc @@ -0,0 +1,5 @@ +test --test_output=errors + +# Windows requires these for multi-python support: +build --enable_runfiles +startup --windows_enable_symlinks diff --git a/tests/ignore_root_user_error/.gitignore b/tests/ignore_root_user_error/.gitignore new file mode 100644 index 0000000000..ac51a054d2 --- /dev/null +++ b/tests/ignore_root_user_error/.gitignore @@ -0,0 +1 @@ +bazel-* diff --git a/tests/ignore_root_user_error/BUILD.bazel b/tests/ignore_root_user_error/BUILD.bazel new file mode 100644 index 0000000000..4c64568852 --- /dev/null +++ b/tests/ignore_root_user_error/BUILD.bazel @@ -0,0 +1,7 @@ +load("@rules_python//python:defs.bzl", "py_test") + +py_test( + name = "foo_test", + srcs = ["foo_test.py"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/tests/ignore_root_user_error/WORKSPACE b/tests/ignore_root_user_error/WORKSPACE new file mode 100644 index 0000000000..7978eb77bf --- /dev/null +++ b/tests/ignore_root_user_error/WORKSPACE @@ -0,0 +1,12 @@ +local_repository( + name = "rules_python", + path = "../..", +) + +load("@rules_python//python:repositories.bzl", "python_register_toolchains") + +python_register_toolchains( + name = "python39", + python_version = "3.9", + ignore_root_user_error = True, +) diff --git a/tests/ignore_root_user_error/foo_test.py b/tests/ignore_root_user_error/foo_test.py new file mode 100644 index 0000000000..724cdcb69a --- /dev/null +++ b/tests/ignore_root_user_error/foo_test.py @@ -0,0 +1,13 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. From 5d2b121b3106ef34489bd3abd075f69c0f134de2 Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Tue, 31 Jan 2023 22:07:36 -0800 Subject: [PATCH 2/3] buildifier --- tests/ignore_root_user_error/BUILD.bazel | 2 +- tests/ignore_root_user_error/WORKSPACE | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ignore_root_user_error/BUILD.bazel b/tests/ignore_root_user_error/BUILD.bazel index 4c64568852..f907624767 100644 --- a/tests/ignore_root_user_error/BUILD.bazel +++ b/tests/ignore_root_user_error/BUILD.bazel @@ -4,4 +4,4 @@ py_test( name = "foo_test", srcs = ["foo_test.py"], visibility = ["//visibility:public"], -) \ No newline at end of file +) diff --git a/tests/ignore_root_user_error/WORKSPACE b/tests/ignore_root_user_error/WORKSPACE index 7978eb77bf..d2f4d6ec3a 100644 --- a/tests/ignore_root_user_error/WORKSPACE +++ b/tests/ignore_root_user_error/WORKSPACE @@ -7,6 +7,6 @@ load("@rules_python//python:repositories.bzl", "python_register_toolchains") python_register_toolchains( name = "python39", - python_version = "3.9", ignore_root_user_error = True, + python_version = "3.9", ) From 0f4b6981af5da11c6253b8c6df45c2ce2c8a794a Mon Sep 17 00:00:00 2001 From: Zhongpeng Lin Date: Wed, 1 Feb 2023 18:40:37 -0800 Subject: [PATCH 3/3] adding readme --- tests/ignore_root_user_error/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/ignore_root_user_error/README.md diff --git a/tests/ignore_root_user_error/README.md b/tests/ignore_root_user_error/README.md new file mode 100644 index 0000000000..47da5eb9ad --- /dev/null +++ b/tests/ignore_root_user_error/README.md @@ -0,0 +1,2 @@ +# ignore_root_user_errors +There are cases when we have to run Python targets with root, e.g., in Docker containers, requiring setting `ignore_root_user_error = True` when registering Python toolchain. This test makes sure that rules_python works in this case. \ No newline at end of file