Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test --test_output=errors
# 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
Expand Down
13 changes: 13 additions & 0 deletions examples/build_file_generation/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# 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 = "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",
Expand Down
1 change: 1 addition & 0 deletions gazelle/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test --test_output=errors
# 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
Expand Down
2 changes: 1 addition & 1 deletion gazelle/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
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")
Expand Down
13 changes: 13 additions & 0 deletions gazelle/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ workspace(name = "rules_python_gazelle_plugin")

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",
Expand Down
6 changes: 3 additions & 3 deletions internal_dev_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def rules_python_internal_deps():

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",
],
)

Expand Down
24 changes: 24 additions & 0 deletions python/config_settings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -244,5 +245,28 @@ label_flag(
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"],
)
7 changes: 7 additions & 0 deletions python/private/attributes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ COMMON_ATTRS = dicts.add(
# buildifier: disable=attr-license
"licenses": attr.license() if hasattr(attr, "license") else attr.string_list(),
},
# starlark flags attributes
{
"_build_python_zip": attr.label(default = "//python/config_settings:build_python_zip"),
"_default_to_explicit_init_py": attr.label(default = "//python/config_settings:incompatible_default_to_explicit_init_py"),
"_python_import_all_repositories": attr.label(default = "//python/config_settings:experimental_python_import_all_repositories"),
"_python_path": attr.label(default = "//python/config_settings:python_path"),
},
)

IMPORTS_ATTRS = {
Expand Down
1 change: 1 addition & 0 deletions python/private/common_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ labels = struct(
# 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")),
Expand Down
2 changes: 2 additions & 0 deletions python/private/internal_config_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ _ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"

_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},
Expand Down Expand Up @@ -96,6 +97,7 @@ def _internal_config_repo_impl(rctx):
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,
Expand Down
3 changes: 3 additions & 0 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,9 @@ def _get_runtime_details(ctx, semantics):
# 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 when it is set.")

toolchain_runtime, effective_runtime = _maybe_get_runtime_from_ctx(ctx)
if not effective_runtime:
# Clear these just in case
Expand Down
6 changes: 3 additions & 3 deletions python/private/py_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def py_repositories(transition_settings = []):
)
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(
Expand Down
6 changes: 6 additions & 0 deletions tests/base_rules/py_executable_base_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def _test_basic_windows(name, config):
# 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],
Expand Down Expand Up @@ -87,7 +90,10 @@ def _test_basic_zip(name, config):
# 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],
Expand Down
10 changes: 5 additions & 5 deletions tests/bootstrap_impls/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ py_reconfig_binary(
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,
)
Expand All @@ -50,14 +50,14 @@ sh_test(

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",
)
Expand All @@ -81,7 +81,7 @@ sh_py_run_test(
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,
Expand All @@ -90,7 +90,7 @@ sh_py_run_test(
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,
Expand Down
8 changes: 5 additions & 3 deletions tests/config_settings/transition/multi_version_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load("@rules_testing//lib:util.bzl", rt_util = "util")
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")
Expand Down Expand Up @@ -91,7 +92,8 @@ def _setup_py_binary_windows(name, *, impl, build_python_zip):
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),
},
Expand All @@ -100,7 +102,7 @@ def _setup_py_binary_windows(name, *, impl, build_python_zip):
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,
)

Expand All @@ -121,7 +123,7 @@ _tests.append(_test_py_binary_windows_build_python_zip_false)
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,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/custom_commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
15 changes: 0 additions & 15 deletions tests/integration/ignore_root_user_error/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

local_repository(
name = "rules_python",
path = "../../..",
Expand All @@ -14,16 +12,3 @@ python_register_toolchains(
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()
7 changes: 5 additions & 2 deletions tests/support/py_reconfig.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This facilitates verify running binaries with different configuration settings
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
Expand All @@ -30,7 +31,8 @@ def _perform_transition_impl(input_settings, attr, base_impl):
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:
Expand Down Expand Up @@ -58,13 +60,14 @@ _RECONFIG_INPUTS = [
]
_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 = """
Expand Down