build: Starlarkify python flags (#3334)

Add starlark flags for `--python_path`, `--build_python_zip` and
`--incompatible_default_to_explicit_init_py`.

- The transitions logic is updated to set both the native and starlark
versions of the flags to allow alternating between them until the native
ones are removed.
- `--build_python_zip` is changed to `boolean` instead of `Tristate`
with default value set to `True` on `windows` and `False` otherwise.
- `scope = universal` attribute is added to the starlark flags so they
can be propagated to exec config on Bazel 9. This required upgrading
`bazel_skylib` version to have `scope` attribute defined.

Work towards: https://github.com/bazel-contrib/rules_python/issues/3252

cc @gregestren

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Richard Levasseur <rlevasseur@google.com>
diff --git a/tests/base_rules/py_executable_base_tests.bzl b/tests/base_rules/py_executable_base_tests.bzl
index e86a949..e41bc2c 100644
--- a/tests/base_rules/py_executable_base_tests.bzl
+++ b/tests/base_rules/py_executable_base_tests.bzl
@@ -44,7 +44,10 @@
             # the target platform. For windows, it defaults to true, so force
             # it to that to match behavior when this test runs on other
             # platforms.
+            # Pass value to both native and starlark versions of the flag until
+            # the native one is removed.
             "//command_line_option:build_python_zip": "true",
+            labels.BUILD_PYTHON_ZIP: True,
             "//command_line_option:cpu": "windows_x86_64",
             "//command_line_option:crosstool_top": CROSSTOOL_TOP,
             "//command_line_option:extra_execution_platforms": [platform_targets.WINDOWS_X86_64],
@@ -87,7 +90,10 @@
             # the target platform. For windows, it defaults to true, so force
             # it to that to match behavior when this test runs on other
             # platforms.
+            # Pass value to both native and starlark versions of the flag until
+            # the native one is removed.
             "//command_line_option:build_python_zip": "true",
+            labels.BUILD_PYTHON_ZIP: True,
             "//command_line_option:cpu": "linux_x86_64",
             "//command_line_option:crosstool_top": CROSSTOOL_TOP,
             "//command_line_option:extra_execution_platforms": [platform_targets.LINUX_X86_64],
diff --git a/tests/bootstrap_impls/BUILD.bazel b/tests/bootstrap_impls/BUILD.bazel
index c3d44df..dcc2751 100644
--- a/tests/bootstrap_impls/BUILD.bazel
+++ b/tests/bootstrap_impls/BUILD.bazel
@@ -23,7 +23,7 @@
     srcs = ["bin.py"],
     bootstrap_impl = "script",
     # Force it to not be self-executable
-    build_python_zip = "no",
+    build_python_zip = False,
     main = "bin.py",
     target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT,
 )
@@ -50,14 +50,14 @@
 
 sh_py_run_test(
     name = "run_binary_zip_no_test",
-    build_python_zip = "no",
+    build_python_zip = False,
     py_src = "bin.py",
     sh_src = "run_binary_zip_no_test.sh",
 )
 
 sh_py_run_test(
     name = "run_binary_zip_yes_test",
-    build_python_zip = "yes",
+    build_python_zip = True,
     py_src = "bin.py",
     sh_src = "run_binary_zip_yes_test.sh",
 )
@@ -81,7 +81,7 @@
 sh_py_run_test(
     name = "run_binary_bootstrap_script_zip_yes_test",
     bootstrap_impl = "script",
-    build_python_zip = "yes",
+    build_python_zip = True,
     py_src = "bin.py",
     sh_src = "run_binary_zip_yes_test.sh",
     target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT,
@@ -90,7 +90,7 @@
 sh_py_run_test(
     name = "run_binary_bootstrap_script_zip_no_test",
     bootstrap_impl = "script",
-    build_python_zip = "no",
+    build_python_zip = False,
     py_src = "bin.py",
     sh_src = "run_binary_zip_no_test.sh",
     target_compatible_with = SUPPORTS_BOOTSTRAP_SCRIPT,
diff --git a/tests/config_settings/transition/multi_version_tests.bzl b/tests/config_settings/transition/multi_version_tests.bzl
index dfe2bf9..05f0105 100644
--- a/tests/config_settings/transition/multi_version_tests.bzl
+++ b/tests/config_settings/transition/multi_version_tests.bzl
@@ -20,6 +20,7 @@
 load("//python:py_binary.bzl", "py_binary")
 load("//python:py_info.bzl", "PyInfo")
 load("//python:py_test.bzl", "py_test")
+load("//python/private:common_labels.bzl", "labels")  # buildifier: disable=bzl-visibility
 load("//python/private:reexports.bzl", "BuiltinPyInfo")  # buildifier: disable=bzl-visibility
 load("//tests/support:support.bzl", "CC_TOOLCHAIN")
 load("//tests/support/platforms:platforms.bzl", "platform_targets")
@@ -91,7 +92,8 @@
         target = name + "_subject",
         impl = impl,
         config_settings = {
-            "//command_line_option:build_python_zip": build_python_zip,
+            "//command_line_option:build_python_zip": str(build_python_zip),
+            labels.BUILD_PYTHON_ZIP: build_python_zip,
             "//command_line_option:extra_toolchains": CC_TOOLCHAIN,
             "//command_line_option:platforms": str(platform_targets.WINDOWS_X86_64),
         },
@@ -100,7 +102,7 @@
 def _test_py_binary_windows_build_python_zip_false(name):
     _setup_py_binary_windows(
         name,
-        build_python_zip = "false",
+        build_python_zip = False,
         impl = _test_py_binary_windows_build_python_zip_false_impl,
     )
 
@@ -121,7 +123,7 @@
 def _test_py_binary_windows_build_python_zip_true(name):
     _setup_py_binary_windows(
         name,
-        build_python_zip = "true",
+        build_python_zip = True,
         impl = _test_py_binary_windows_build_python_zip_true_impl,
     )
 
diff --git a/tests/integration/custom_commands_test.py b/tests/integration/custom_commands_test.py
index 2e9cb74..288a4e7 100644
--- a/tests/integration/custom_commands_test.py
+++ b/tests/integration/custom_commands_test.py
@@ -21,7 +21,7 @@
 class CustomCommandsTest(runner.TestCase):
     # Regression test for https://github.com/bazel-contrib/rules_python/issues/1840
     def test_run_build_python_zip_false(self):
-        result = self.run_bazel("run", "--build_python_zip=false", "//:bin")
+        result = self.run_bazel("run", "--build_python_zip=false", "--@rules_python//python/config_settings:build_python_zip=false", "//:bin")
         self.assert_result_matches(result, "bazel-out")
 
 
diff --git a/tests/integration/ignore_root_user_error/WORKSPACE b/tests/integration/ignore_root_user_error/WORKSPACE
index 0a25819..7ac0a60 100644
--- a/tests/integration/ignore_root_user_error/WORKSPACE
+++ b/tests/integration/ignore_root_user_error/WORKSPACE
@@ -1,5 +1,3 @@
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
 local_repository(
     name = "rules_python",
     path = "../../..",
@@ -14,16 +12,3 @@
     ignore_root_user_error = True,
     python_version = "3.9",
 )
-
-http_archive(
-    name = "bazel_skylib",
-    sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
-    urls = [
-        "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
-        "https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
-    ],
-)
-
-load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
-
-bazel_skylib_workspace()
diff --git a/tests/support/py_reconfig.bzl b/tests/support/py_reconfig.bzl
index d52cc5d..efcb0e7 100644
--- a/tests/support/py_reconfig.bzl
+++ b/tests/support/py_reconfig.bzl
@@ -17,6 +17,7 @@
 without the overhead of a bazel-in-bazel integration test.
 """
 
+load("@rules_python_internal//:rules_python_config.bzl", "config")
 load("//python/private:attr_builders.bzl", "attrb")  # buildifier: disable=bzl-visibility
 load("//python/private:common_labels.bzl", "labels")  # buildifier: disable=bzl-visibility
 load("//python/private:py_binary_macro.bzl", "py_binary_macro")  # buildifier: disable=bzl-visibility
@@ -30,7 +31,8 @@
     settings.update(base_impl(input_settings, attr))
 
     settings[labels.VISIBLE_FOR_TESTING] = True
-    settings["//command_line_option:build_python_zip"] = attr.build_python_zip
+    settings["//command_line_option:build_python_zip"] = str(attr.build_python_zip)
+    settings[labels.BUILD_PYTHON_ZIP] = attr.build_python_zip
     if attr.bootstrap_impl:
         settings[labels.BOOTSTRAP_IMPL] = attr.bootstrap_impl
     if attr.extra_toolchains:
@@ -58,13 +60,14 @@
 ]
 _RECONFIG_OUTPUTS = _RECONFIG_INPUTS + [
     "//command_line_option:build_python_zip",
+    labels.BUILD_PYTHON_ZIP,
     labels.VISIBLE_FOR_TESTING,
 ]
 _RECONFIG_INHERITED_OUTPUTS = [v for v in _RECONFIG_OUTPUTS if v in _RECONFIG_INPUTS]
 
 _RECONFIG_ATTRS = {
     "bootstrap_impl": attrb.String(),
-    "build_python_zip": attrb.String(default = "auto"),
+    "build_python_zip": attrb.Bool(default = config.build_python_zip_default),
     "config_settings": attrb.LabelKeyedStringDict(),
     "extra_toolchains": attrb.StringList(
         doc = """