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/.bazelrc b/.bazelrc
index d7e1771..801b963 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -16,6 +16,7 @@
# creating (possibly empty) __init__.py files and adding them to the srcs of
# Python targets as required.
build --incompatible_default_to_explicit_init_py
+build --//python/config_settings:incompatible_default_to_explicit_init_py=True
# Ensure ongoing compatibility with this flag.
common --incompatible_disallow_struct_provider_syntax
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d7c4805..4f9ac02 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -85,6 +85,8 @@
evaluated, see [our docs](/pypi/download.html#customizing-requires-dist-resolution) on customizing `Requires-Dist` resolution.
* (toolchains) Added Python versions 3.14.0, 3.13.8, 3.12.12, 3.11.14, 3.10.19, and 3.9.24
from the [20251010] release.
+* (deps) (bzlmod) Upgraded to `bazel-skylib` version
+ [1.8.2](https://github.com/bazelbuild/bazel-skylib/releases/tag/1.8.2)
[20251010]: https://github.com/astral-sh/python-build-standalone/releases/tag/20251010
diff --git a/MODULE.bazel b/MODULE.bazel
index 36135bb..5854595 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -5,7 +5,7 @@
)
bazel_dep(name = "bazel_features", version = "1.21.0")
-bazel_dep(name = "bazel_skylib", version = "1.8.1")
+bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_cc", version = "0.1.5")
bazel_dep(name = "platforms", version = "0.0.11")
diff --git a/docs/api/rules_python/python/config_settings/index.md b/docs/api/rules_python/python/config_settings/index.md
index 989ebf1..78a74c3 100644
--- a/docs/api/rules_python/python/config_settings/index.md
+++ b/docs/api/rules_python/python/config_settings/index.md
@@ -24,6 +24,65 @@
::::
:::
+::::{bzl:flag} build_python_zip
+Controls if a `py_binary/py_test` output is a self-executable zipapp.
+
+When enabled, the output of `py_binary` or `py_test` targets will be a
+self-executable zipapp.
+
+:::{note}
+This affects _all_ `py_binary` and `py_test` targets in the build, not
+only the target(s) specified on the command line.
+:::
+
+Values:
+* `true`
+* `false`
+
+This flag replaces the Bazel builtin `--build_python_zip` flag.
+
+:::{versionadded} VERSION_NEXT_FEATURE
+:::
+::::
+
+::::{bzl:flag} experimental_python_import_all_repositories
+Controls whether repository directories are added to the import path.
+
+When enabled, the top-level directories in the runfiles root directory (which
+are presumbed to be repository directories) are added to the Python import
+search path.
+
+It's recommended to set this to **`false`** to avoid external dependencies
+unexpectedly interferring with import searching.
+
+Values;
+* `true` (default)
+* `false`
+
+This flag replaces the Bazel builtin
+`--experimental_python_import_all_repositories` flag.
+
+:::{versionadded} VERSION_NEXT_FEATURE
+:::
+::::
+
+::::{bzl:flag} python_path
+A fallback path to use for Python for particular legacy Windows-specific code paths.
+
+Deprecated, do not use. This flag is largely a no-op and was replaced by
+toolchains. It only remains for some legacy Windows code-paths that will
+be removed.
+
+This flag replaces the Bazel builtin `--python_path` flag.
+
+:::{deprecated} VERSION_NEXT_FEATURE
+Use toolchains instead.
+:::
+
+:::{versionadded} VERSION_NEXT_FEATURE
+:::
+::::
+
:::{bzl:flag} python_version
Determines the default hermetic Python toolchain version. This can be set to
one of the values that `rules_python` maintains.
@@ -33,6 +92,29 @@
Parses the value of the `python_version` and transforms it into a `X.Y` value.
:::
+::::{bzl:flag} incompatible_default_to_explicit_init_py
+Controls if missing `__init__.py` files are generated or not.
+
+If false, `py_binary` and `py_test` will, for every `*.py` and `*.so` file,
+create `__init__.py` files for the containing directory, and all parent
+directories, that do not already have an `__init__.py` file. If true, this
+behavior is disabled.
+
+It's recommended to disable this behavior to avoid surprising import effects
+from directories being importable when they otherwise wouldn't be, and for
+how it can interfere with implicit namespace packages.
+
+Values:
+* `true`: do not generate missing `__init__.py` files
+* `false` (default): generate missing `__init__.py` files
+
+This flag replaces the Bazel builtin
+`--incompatible_default_to_explicit_init_py` flag.
+
+:::{versionadded} VERSION_NEXT_FEATURE
+:::
+::::
+
:::{bzl:target} is_python_*
config_settings to match Python versions
diff --git a/examples/build_file_generation/WORKSPACE b/examples/build_file_generation/WORKSPACE
index 27f6ec0..27d0d13 100644
--- a/examples/build_file_generation/WORKSPACE
+++ b/examples/build_file_generation/WORKSPACE
@@ -7,54 +7,7 @@
# file. When the symbol is loaded you can use the rule.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-######################################################################
-# We need rules_go and bazel_gazelle, to build the gazelle plugin from source.
-# Setup instructions for this section are at
-# https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel
-# You may need to update the version of the rule, which is listed in the above
-# documentation.
-######################################################################
-
-# Define an http_archive rule that will download the below ruleset,
-# test the sha, and extract the ruleset to you local bazel cache.
-
-http_archive(
- name = "io_bazel_rules_go",
- sha256 = "9d72f7b8904128afb98d46bbef82ad7223ec9ff3718d419afb355fddd9f9484a",
- urls = [
- "https://mirror.bazel.build/github.com/bazel-contrib/rules_go/releases/download/v0.55.1/rules_go-v0.55.1.zip",
- "https://github.com/bazel-contrib/rules_go/releases/download/v0.55.1/rules_go-v0.55.1.zip",
- ],
-)
-
-# Download the bazel_gazelle ruleset.
-http_archive(
- name = "bazel_gazelle",
- sha256 = "75df288c4b31c81eb50f51e2e14f4763cb7548daae126817247064637fd9ea62",
- urls = [
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.36.0/bazel-gazelle-v0.36.0.tar.gz",
- "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.36.0/bazel-gazelle-v0.36.0.tar.gz",
- ],
-)
-
-# Load rules_go ruleset and expose the toolchain and dep rules.
-load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
-load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
-
-# go_rules_dependencies is a function that registers external dependencies
-# needed by the Go rules.
-# See: https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#go_rules_dependencies
-go_rules_dependencies()
-
-# go_rules_dependencies is a function that registers external dependencies
-# needed by the Go rules.
-# See: https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#go_rules_dependencies
-go_register_toolchains(version = "1.21.13")
-
-# The following call configured the gazelle dependencies, Go environment and Go SDK.
-gazelle_dependencies()
-
-# Remaining setup is for rules_python.
+# Setup rules_python.
# DON'T COPY_PASTE THIS.
# Our example uses `local_repository` to point to the HEAD version of rules_python.
@@ -124,6 +77,53 @@
# Initialize repositories for all packages in requirements_lock.txt.
install_deps()
+######################################################################
+# We need rules_go and bazel_gazelle, to build the gazelle plugin from source.
+# Setup instructions for this section are at
+# https://github.com/bazelbuild/bazel-gazelle#running-gazelle-with-bazel
+# You may need to update the version of the rule, which is listed in the above
+# documentation.
+######################################################################
+
+# Define an http_archive rule that will download the below ruleset,
+# test the sha, and extract the ruleset to you local bazel cache.
+
+http_archive(
+ name = "io_bazel_rules_go",
+ sha256 = "9d72f7b8904128afb98d46bbef82ad7223ec9ff3718d419afb355fddd9f9484a",
+ urls = [
+ "https://mirror.bazel.build/github.com/bazel-contrib/rules_go/releases/download/v0.55.1/rules_go-v0.55.1.zip",
+ "https://github.com/bazel-contrib/rules_go/releases/download/v0.55.1/rules_go-v0.55.1.zip",
+ ],
+)
+
+# Download the bazel_gazelle ruleset.
+http_archive(
+ name = "bazel_gazelle",
+ sha256 = "75df288c4b31c81eb50f51e2e14f4763cb7548daae126817247064637fd9ea62",
+ urls = [
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.36.0/bazel-gazelle-v0.36.0.tar.gz",
+ "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.36.0/bazel-gazelle-v0.36.0.tar.gz",
+ ],
+)
+
+# Load rules_go ruleset and expose the toolchain and dep rules.
+load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
+load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
+
+# go_rules_dependencies is a function that registers external dependencies
+# needed by the Go rules.
+# See: https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#go_rules_dependencies
+go_rules_dependencies()
+
+# go_rules_dependencies is a function that registers external dependencies
+# needed by the Go rules.
+# See: https://github.com/bazelbuild/rules_go/blob/master/go/dependencies.rst#go_rules_dependencies
+go_register_toolchains(version = "1.21.13")
+
+# The following call configured the gazelle dependencies, Go environment and Go SDK.
+gazelle_dependencies()
+
# The rules_python gazelle extension has some third-party go dependencies
# which we need to fetch in order to compile it.
load("@rules_python_gazelle_plugin//:deps.bzl", _py_gazelle_deps = "gazelle_deps")
diff --git a/gazelle/.bazelrc b/gazelle/.bazelrc
index 9704090..791b939 100644
--- a/gazelle/.bazelrc
+++ b/gazelle/.bazelrc
@@ -7,6 +7,7 @@
# creating (possibly empty) __init__.py files and adding them to the srcs of
# Python targets as required.
build --incompatible_default_to_explicit_init_py
+build --@rules_python//python/config_settings:incompatible_default_to_explicit_init_py=True
# Windows makes use of runfiles for some rules
build --enable_runfiles
diff --git a/gazelle/MODULE.bazel b/gazelle/MODULE.bazel
index 1560e73..add5986 100644
--- a/gazelle/MODULE.bazel
+++ b/gazelle/MODULE.bazel
@@ -4,7 +4,7 @@
compatibility_level = 1,
)
-bazel_dep(name = "bazel_skylib", version = "1.6.1")
+bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_python", version = "0.18.0")
bazel_dep(name = "rules_go", version = "0.55.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.36.0", repo_name = "bazel_gazelle")
diff --git a/gazelle/WORKSPACE b/gazelle/WORKSPACE
index ec0532c..f4a3abf 100644
--- a/gazelle/WORKSPACE
+++ b/gazelle/WORKSPACE
@@ -3,6 +3,19 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
+ name = "bazel_skylib",
+ sha256 = "6e78f0e57de26801f6f564fa7c4a48dc8b36873e416257a92bbb0937eeac8446",
+ urls = [
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz",
+ "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz",
+ ],
+)
+
+load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
+
+bazel_skylib_workspace()
+
+http_archive(
name = "io_bazel_rules_go",
sha256 = "9d72f7b8904128afb98d46bbef82ad7223ec9ff3718d419afb355fddd9f9484a",
urls = [
diff --git a/internal_dev_deps.bzl b/internal_dev_deps.bzl
index 91f5def..811240a 100644
--- a/internal_dev_deps.bzl
+++ b/internal_dev_deps.bzl
@@ -60,10 +60,10 @@
http_archive(
name = "bazel_skylib",
- sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
+ sha256 = "6e78f0e57de26801f6f564fa7c4a48dc8b36873e416257a92bbb0937eeac8446",
urls = [
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz",
+ "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz",
],
)
diff --git a/python/config_settings/BUILD.bazel b/python/config_settings/BUILD.bazel
index cc5c472..369989e 100644
--- a/python/config_settings/BUILD.bazel
+++ b/python/config_settings/BUILD.bazel
@@ -1,5 +1,6 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("@pythons_hub//:versions.bzl", "DEFAULT_PYTHON_VERSION", "MINOR_MAPPING", "PYTHON_VERSIONS")
+load("@rules_python_internal//:rules_python_config.bzl", "config")
load(
"//python/private:flags.bzl",
"AddSrcsToRunfilesFlag",
@@ -244,5 +245,28 @@
bool_flag(
name = "experimental_python_import_all_repositories",
build_setting_default = True,
+ scope = "universal",
+ visibility = ["//visibility:public"],
+)
+
+bool_flag(
+ name = "build_python_zip",
+ build_setting_default = config.build_python_zip_default,
+ help = "Build python executable zip. Defaults to on on Windows, off on other platforms",
+ scope = "universal",
+ visibility = ["//visibility:public"],
+)
+
+bool_flag(
+ name = "incompatible_default_to_explicit_init_py",
+ build_setting_default = False,
+ scope = "universal",
+ visibility = ["//visibility:public"],
+)
+
+string_flag(
+ name = "python_path",
+ build_setting_default = "python",
+ scope = "universal",
visibility = ["//visibility:public"],
)
diff --git a/python/private/common_labels.bzl b/python/private/common_labels.bzl
index 4a6f6d3..e90679e 100644
--- a/python/private/common_labels.bzl
+++ b/python/private/common_labels.bzl
@@ -7,6 +7,7 @@
# keep sorted
ADD_SRCS_TO_RUNFILES = str(Label("//python/config_settings:add_srcs_to_runfiles")),
BOOTSTRAP_IMPL = str(Label("//python/config_settings:bootstrap_impl")),
+ BUILD_PYTHON_ZIP = str(Label("//python/config_settings:build_python_zip")),
EXEC_TOOLS_TOOLCHAIN = str(Label("//python/config_settings:exec_tools_toolchain")),
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config")),
NONE = str(Label("//python:none")),
@@ -18,6 +19,7 @@
PRECOMPILE = str(Label("//python/config_settings:precompile")),
PRECOMPILE_SOURCE_RETENTION = str(Label("//python/config_settings:precompile_source_retention")),
PYC_COLLECTION = str(Label("//python/config_settings:pyc_collection")),
+ PYTHON_IMPORT_ALL_REPOSITORIES = str(Label("//python/config_settings:experimental_python_import_all_repositories")),
PYTHON_SRC = str(Label("//python/bin:python_src")),
PYTHON_VERSION = str(Label("//python/config_settings:python_version")),
PYTHON_VERSION_MAJOR_MINOR = str(Label("//python/config_settings:python_version_major_minor")),
diff --git a/python/private/flags.bzl b/python/private/flags.bzl
index 35181e9..d9e3aa4 100644
--- a/python/private/flags.bzl
+++ b/python/private/flags.bzl
@@ -71,7 +71,7 @@
return _POSSIBLY_NATIVE_FLAGS[flag_name][0](ctx)
else:
# Starlark definition of "--foo" is assumed to be a label dependency named "_foo".
- return getattr(ctx.attr, "_" + flag_name)[BuildSettingInfo].value
+ return getattr(ctx.attr, "_" + flag_name + "_flag")[BuildSettingInfo].value
def _AddSrcsToRunfilesFlag_is_enabled(ctx):
value = ctx.attr._add_srcs_to_runfiles_flag[BuildSettingInfo].value
diff --git a/python/private/internal_config_repo.bzl b/python/private/internal_config_repo.bzl
index 0c62106..dac6d74 100644
--- a/python/private/internal_config_repo.bzl
+++ b/python/private/internal_config_repo.bzl
@@ -28,6 +28,7 @@
_CONFIG_TEMPLATE = """
config = struct(
+ build_python_zip_default = {build_python_zip_default},
enable_pystar = True,
enable_pipstar = {enable_pipstar},
enable_deprecation_warnings = {enable_deprecation_warnings},
@@ -96,6 +97,7 @@
builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider"
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
+ build_python_zip_default = repo_utils.get_platforms_os_name(rctx) == "windows",
enable_pipstar = _bool_from_environ(rctx, _ENABLE_PIPSTAR_ENVVAR_NAME, _ENABLE_PIPSTAR_DEFAULT),
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
builtin_py_info_symbol = builtin_py_info_symbol,
diff --git a/python/private/py_executable.bzl b/python/private/py_executable.bzl
index ad1afa9..1a5ad4c 100644
--- a/python/private/py_executable.bzl
+++ b/python/private/py_executable.bzl
@@ -77,6 +77,13 @@
AGNOSTIC_EXECUTABLE_ATTRS,
PY_SRCS_ATTRS,
IMPORTS_ATTRS,
+ # starlark flags attributes
+ {
+ "_build_python_zip_flag": attr.label(default = "//python/config_settings:build_python_zip"),
+ "_default_to_explicit_init_py_flag": attr.label(default = "//python/config_settings:incompatible_default_to_explicit_init_py"),
+ "_python_import_all_repositories_flag": attr.label(default = "//python/config_settings:experimental_python_import_all_repositories"),
+ "_python_path_flag": attr.label(default = "//python/config_settings:python_path"),
+ },
{
"interpreter_args": lambda: attrb.StringList(
doc = """
@@ -1136,6 +1143,9 @@
# TOOD(bazelbuild/bazel#7901): Remove this once --python_path flag is removed.
flag_interpreter_path = read_possibly_native_flag(ctx, "python_path")
+ if not flag_interpreter_path.startswith("python") and not paths.is_absolute(flag_interpreter_path):
+ fail("'python_path' must be an absolute path or a name to be resolved from the system PATH (e.g., 'python', 'python3').")
+
toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
if not effective_runtime:
# Clear these just in case
diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl
index 3ad2a97..e3ab11c 100644
--- a/python/private/py_repositories.bzl
+++ b/python/private/py_repositories.bzl
@@ -60,10 +60,10 @@
)
http_archive(
name = "bazel_skylib",
- sha256 = "d00f1389ee20b60018e92644e0948e16e350a7707219e7a390fb0a99b6ec9262",
+ sha256 = "6e78f0e57de26801f6f564fa7c4a48dc8b36873e416257a92bbb0937eeac8446",
urls = [
- "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.0/bazel-skylib-1.7.0.tar.gz",
- "https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.0/bazel-skylib-1.7.0.tar.gz",
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz",
+ "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz",
],
)
http_archive(
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 = """