Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 2 additions & 4 deletions python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ filegroup(
bzl_library(
name = "current_py_toolchain_bzl",
srcs = ["current_py_toolchain.bzl"],
deps = ["//python/private:toolchain_types_bzl"],
)

bzl_library(
Expand Down Expand Up @@ -91,11 +92,9 @@ bzl_library(
deps = [
":py_binary_bzl",
"//python/private:bzlmod_enabled_bzl",
"//python/private:py_package.bzl",
"//python/private:py_package_bzl",
"//python/private:py_wheel_bzl",
"//python/private:stamp_bzl",
"//python/private:util_bzl",
"//python/private:version.bzl",
"@bazel_skylib//rules:native_binary",
],
)
Expand Down Expand Up @@ -215,7 +214,6 @@ bzl_library(
deps = [
"//python/private:py_runtime_info_bzl",
"//python/private:reexports_bzl",
"//python/private:util_bzl",
"@rules_python_internal//:rules_python_config_bzl",
],
)
Expand Down
1 change: 1 addition & 0 deletions python/extensions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ bzl_library(
visibility = ["//:__subpackages__"],
deps = [
"//python/private:internal_config_repo_bzl",
"//python/private/pypi:deps_bzl",
],
)
11 changes: 10 additions & 1 deletion python/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ bzl_library(
deps = [
":attr_builders_bzl",
":common_bzl",
":common_labels_bzl",
":enum_bzl",
":flags_bzl",
":py_info_bzl",
Expand Down Expand Up @@ -356,6 +357,7 @@ bzl_library(
name = "py_cc_toolchain_rule_bzl",
srcs = ["py_cc_toolchain_rule.bzl"],
deps = [
":common_labels.bzl",
":py_cc_toolchain_info_bzl",
":rules_cc_srcs_bzl",
":util_bzl",
Expand Down Expand Up @@ -390,6 +392,7 @@ bzl_library(
srcs = ["py_exec_tools_toolchain.bzl"],
deps = [
":common_bzl",
":common_labels_bzl",
":py_exec_tools_info_bzl",
":sentinel_bzl",
":toolchain_types_bzl",
Expand All @@ -405,6 +408,7 @@ bzl_library(
":attributes_bzl",
":cc_helper_bzl",
":common_bzl",
":common_labels_bzl",
":flags_bzl",
":precompile_bzl",
":py_cc_link_params_info_bzl",
Expand Down Expand Up @@ -456,6 +460,7 @@ bzl_library(
deps = [
":attributes_bzl",
":common_bzl",
":common_labels_bzl",
":flags_bzl",
":normalize_name_bzl",
":precompile_bzl",
Expand All @@ -479,6 +484,7 @@ bzl_library(
name = "py_library_rule_bzl",
srcs = ["py_library_rule.bzl"],
deps = [
":common_labels_bzl",
":py_library_bzl",
],
)
Expand Down Expand Up @@ -522,6 +528,7 @@ bzl_library(
srcs = ["py_runtime_rule.bzl"],
deps = [
":attributes_bzl",
":common_labels_bzl",
":flags_bzl",
":py_internal_bzl",
":py_runtime_info_bzl",
Expand All @@ -545,6 +552,7 @@ bzl_library(
name = "py_runtime_pair_rule_bzl",
srcs = ["py_runtime_pair_rule.bzl"],
deps = [
":common_labels_bzl",
"//python:py_runtime_bzl",
"//python:py_runtime_info_bzl",
"@bazel_skylib//rules:common_settings",
Expand Down Expand Up @@ -591,6 +599,7 @@ bzl_library(
":py_package_bzl",
":stamp_bzl",
":transition_labels_bzl",
":version_bzl",
],
)

Expand Down Expand Up @@ -661,7 +670,7 @@ bzl_library(
name = "transition_labels_bzl",
srcs = ["transition_labels.bzl"],
deps = [
"common_labels_bzl",
":common_labels_bzl",
"@bazel_skylib//lib:collections",
"@rules_python_internal//:extra_transition_settings_bzl",
],
Expand Down
5 changes: 3 additions & 2 deletions python/private/attributes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load(":attr_builders.bzl", "attrb")
load(":common_labels.bzl", "labels")
load(":enum.bzl", "enum")
load(":flags.bzl", "PrecompileFlag", "PrecompileSourceRetentionFlag")
load(":py_info.bzl", "PyInfo")
Expand Down Expand Up @@ -370,11 +371,11 @@ files that may be needed at run time belong in `data`.
doc = "Defunct, unused, does nothing.",
),
"_precompile_flag": lambda: attrb.Label(
default = "//python/config_settings:precompile",
default = labels.PRECOMPILE,
providers = [BuildSettingInfo],
),
"_precompile_source_retention_flag": lambda: attrb.Label(
default = "//python/config_settings:precompile_source_retention",
default = labels.PRECOMPILE_SOURCE_RETENTION,
providers = [BuildSettingInfo],
),
# Force enabling auto exec groups, see
Expand Down
5 changes: 4 additions & 1 deletion python/private/common_labels.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ labels = struct(
BOOTSTRAP_IMPL = str(Label("//python/config_settings:bootstrap_impl")),
EXEC_TOOLS_TOOLCHAIN = str(Label("//python/config_settings:exec_tools_toolchain")),
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config")),
PIP_WHL_MUSLC_VERSION = str(Label("//python/config_settings:pip_whl_muslc_version")),
NONE = str(Label("//python:none")),
PIP_WHL = str(Label("//python/config_settings:pip_whl")),
PIP_WHL_GLIBC_VERSION = str(Label("//python/config_settings:pip_whl_glibc_version")),
PIP_WHL_MUSLC_VERSION = str(Label("//python/config_settings:pip_whl_muslc_version")),
PIP_WHL_OSX_ARCH = str(Label("//python/config_settings:pip_whl_osx_arch")),
PIP_WHL_OSX_VERSION = str(Label("//python/config_settings:pip_whl_osx_version")),
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_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")),
Expand All @@ -24,4 +26,5 @@ labels = struct(
REPL_DEP = str(Label("//python/bin:repl_dep")),
VENVS_SITE_PACKAGES = str(Label("//python/config_settings:venvs_site_packages")),
VENVS_USE_DECLARE_SYMLINK = str(Label("//python/config_settings:venvs_use_declare_symlink")),
VISIBLE_FOR_TESTING = str(Label("//python/private:visible_for_testing")),
)
3 changes: 2 additions & 1 deletion python/private/py_cc_toolchain_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ https://github.com/bazel-contrib/rules_python/issues/824 is considered done.

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load(":common_labels.bzl", "labels")
load(":py_cc_toolchain_info.bzl", "PyCcToolchainInfo")

def _py_cc_toolchain_impl(ctx):
Expand Down Expand Up @@ -70,7 +71,7 @@ py_cc_toolchain = rule(
mandatory = True,
),
"_visible_for_testing": attr.label(
default = "//python/private:visible_for_testing",
default = labels.VISIBLE_FOR_TESTING,
),
},
doc = """\
Expand Down
3 changes: 2 additions & 1 deletion python/private/py_exec_tools_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(":common_labels.bzl", "labels")
load(":py_exec_tools_info.bzl", "PyExecToolsInfo")
load(":sentinel.bzl", "SentinelInfo")
load(":toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE")
Expand Down Expand Up @@ -89,7 +90,7 @@ so that the toolchain `py_runtime` field can be correctly forwarded.
doc = "See {obj}`PyExecToolsInfo.precompiler`",
),
"_visible_for_testing": attr.label(
default = "//python/private:visible_for_testing",
default = labels.VISIBLE_FOR_TESTING,
),
},
)
Expand Down
21 changes: 8 additions & 13 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ load(
"runfiles_root_path",
"target_platform_has_any_constraint",
)
load(":common_labels.bzl", "labels")
load(":flags.bzl", "BootstrapImplFlag", "VenvsUseDeclareSymlinkFlag")
load(":precompile.bzl", "maybe_precompile")
load(":py_cc_link_params_info.bzl", "PyCcLinkParamsInfo")
Expand All @@ -60,18 +61,12 @@ load(":py_internal.bzl", "py_internal")
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG", "PyRuntimeInfo")
load(":reexports.bzl", "BuiltinPyInfo", "BuiltinPyRuntimeInfo")
load(":rule_builders.bzl", "ruleb")
load(
":toolchain_types.bzl",
"EXEC_TOOLS_TOOLCHAIN_TYPE",
"TARGET_TOOLCHAIN_TYPE",
TOOLCHAIN_TYPE = "TARGET_TOOLCHAIN_TYPE",
)
load(":toolchain_types.bzl", "EXEC_TOOLS_TOOLCHAIN_TYPE", "TARGET_TOOLCHAIN_TYPE", TOOLCHAIN_TYPE = "TARGET_TOOLCHAIN_TYPE")
load(":transition_labels.bzl", "TRANSITION_LABELS")

_py_builtins = py_internal
_EXTERNAL_PATH_PREFIX = "external"
_ZIP_RUNFILES_DIRECTORY_NAME = "runfiles"
_PYTHON_VERSION_FLAG = str(Label("//python/config_settings:python_version"))

# Non-Google-specific attributes for executables
# These attributes are for rules that accept Python sources.
Expand Down Expand Up @@ -192,7 +187,7 @@ accepting arbitrary Python versions.
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
"_bootstrap_impl_flag": lambda: attrb.Label(
default = "//python/config_settings:bootstrap_impl",
default = labels.BOOTSTRAP_IMPL,
providers = [BuildSettingInfo],
),
"_bootstrap_template": lambda: attrb.Label(
Expand Down Expand Up @@ -222,10 +217,10 @@ accepting arbitrary Python versions.
default = TARGET_TOOLCHAIN_TYPE,
),
"_python_version_flag": lambda: attrb.Label(
default = "//python/config_settings:python_version",
default = labels.PYTHON_VERSION,
),
"_venvs_use_declare_symlink_flag": lambda: attrb.Label(
default = "//python/config_settings:venvs_use_declare_symlink",
default = labels.VENVS_USE_DECLARE_SYMLINK,
providers = [BuildSettingInfo],
),
"_windows_constraints": lambda: attrb.LabelList(
Expand Down Expand Up @@ -1910,7 +1905,7 @@ def _transition_executable_impl(settings, attr):
apply_config_settings_attr(settings, attr)

if attr.python_version and attr.python_version not in ("PY2", "PY3"):
settings[_PYTHON_VERSION_FLAG] = attr.python_version
settings[labels.PYTHON_VERSION] = attr.python_version
return settings

def create_executable_rule(*, attrs, **kwargs):
Expand Down Expand Up @@ -1961,8 +1956,8 @@ def create_executable_rule_builder(implementation, **kwargs):
],
cfg = dict(
implementation = _transition_executable_impl,
inputs = TRANSITION_LABELS + [_PYTHON_VERSION_FLAG],
outputs = TRANSITION_LABELS + [_PYTHON_VERSION_FLAG],
inputs = TRANSITION_LABELS + [labels.PYTHON_VERSION],
outputs = TRANSITION_LABELS + [labels.PYTHON_VERSION],
),
**kwargs
)
Expand Down
3 changes: 2 additions & 1 deletion python/private/py_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ load(
"get_imports",
"runfiles_root_path",
)
load(":common_labels.bzl", "labels")
load(":flags.bzl", "AddSrcsToRunfilesFlag", "PrecompileFlag", "VenvsSitePackages")
load(":normalize_name.bzl", "normalize_name")
load(":precompile.bzl", "maybe_precompile")
Expand Down Expand Up @@ -102,7 +103,7 @@ and that only one package version will be included.
""",
),
"_add_srcs_to_runfiles_flag": lambda: attrb.Label(
default = "//python/config_settings:add_srcs_to_runfiles",
default = labels.ADD_SRCS_TO_RUNFILES,
),
},
)
Expand Down
3 changes: 2 additions & 1 deletion python/private/py_runtime_pair_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//python:py_runtime_info.bzl", "PyRuntimeInfo")
load(":common_labels.bzl", "labels")
load(":reexports.bzl", "BuiltinPyRuntimeInfo")
load(":util.bzl", "IS_BAZEL_7_OR_HIGHER")

Expand Down Expand Up @@ -94,7 +95,7 @@ The runtime to use for Python 3 targets. Must have `python_version` set to
""",
),
"_visible_for_testing": attr.label(
default = "//python/private:visible_for_testing",
default = labels.VISIBLE_FOR_TESTING,
),
},
fragments = ["py"],
Expand Down
5 changes: 3 additions & 2 deletions python/private/py_runtime_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(":attributes.bzl", "NATIVE_RULES_ALLOWLIST_ATTRS")
load(":common_labels.bzl", "labels")
load(":flags.bzl", "FreeThreadedFlag")
load(":py_internal.bzl", "py_internal")
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG", "PyRuntimeInfo")
Expand Down Expand Up @@ -379,10 +380,10 @@ The {obj}`PyRuntimeInfo.zip_main_template` field.
""",
),
"_py_freethreaded_flag": attr.label(
default = "//python/config_settings:py_freethreaded",
default = labels.PY_FREETHREADED,
),
"_python_version_flag": attr.label(
default = "//python/config_settings:python_version",
default = labels.PYTHON_VERSION,
),
},
),
Expand Down
3 changes: 3 additions & 0 deletions python/private/pypi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bzl_library(
srcs = ["config_settings.bzl"],
deps = [
":flags_bzl",
"//python/private:common_labels_bzl",
"//python/private:flags_bzl",
"@bazel_skylib//lib:selects",
],
Expand All @@ -89,6 +90,7 @@ bzl_library(
":env_marker_info_bzl",
":pep508_env_bzl",
":pep508_evaluate_bzl",
"//python/private:common_labels_bzl",
"//python/private:toolchain_types_bzl",
"@bazel_skylib//rules:common_settings",
],
Expand Down Expand Up @@ -337,6 +339,7 @@ bzl_library(
srcs = ["pkg_aliases.bzl"],
deps = [
":labels_bzl",
"//python/private:common_labels_bzl",
"//python/private:text_util_bzl",
"@bazel_skylib//lib:selects",
],
Expand Down
7 changes: 4 additions & 3 deletions python/private/pypi/env_marker_setting.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Implement a flag for matching the dependency specifiers at analysis time."""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//python/private:common_labels.bzl", "labels")
load("//python/private:toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE")
load(":env_marker_info.bzl", "EnvMarkerInfo")
load(":pep508_env.bzl", "create_env", "set_missing_env_defaults")
Expand Down Expand Up @@ -85,15 +86,15 @@ for the specification of behavior.
doc = "Environment marker expression to evaluate.",
),
"_env_marker_config_flag": attr.label(
default = "//python/config_settings:pip_env_marker_config",
default = labels.PIP_ENV_MARKER_CONFIG,
providers = [EnvMarkerInfo],
),
"_python_full_version_flag": attr.label(
default = "//python/config_settings:python_version",
default = labels.PYTHON_VERSION,
providers = [config_common.FeatureFlagInfo],
),
"_python_version_major_minor_flag": attr.label(
default = "//python/config_settings:python_version_major_minor",
default = labels.PYTHON_VERSION_MAJOR_MINOR,
providers = [config_common.FeatureFlagInfo],
),
},
Expand Down
Loading