Skip to content

Commit b63d9ec

Browse files
committed
Merge branch 'main' of https://github.com/bazel-contrib/rules_python into fix.site.packages.overlap
2 parents c2ec385 + 668a551 commit b63d9ec

33 files changed

+106
-89
lines changed

python/BUILD.bazel

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ filegroup(
5656
bzl_library(
5757
name = "current_py_toolchain_bzl",
5858
srcs = ["current_py_toolchain.bzl"],
59+
deps = ["//python/private:toolchain_types_bzl"],
5960
)
6061

6162
bzl_library(
@@ -91,11 +92,9 @@ bzl_library(
9192
deps = [
9293
":py_binary_bzl",
9394
"//python/private:bzlmod_enabled_bzl",
94-
"//python/private:py_package.bzl",
95+
"//python/private:py_package_bzl",
9596
"//python/private:py_wheel_bzl",
96-
"//python/private:stamp_bzl",
9797
"//python/private:util_bzl",
98-
"//python/private:version.bzl",
9998
"@bazel_skylib//rules:native_binary",
10099
],
101100
)
@@ -215,7 +214,6 @@ bzl_library(
215214
deps = [
216215
"//python/private:py_runtime_info_bzl",
217216
"//python/private:reexports_bzl",
218-
"//python/private:util_bzl",
219217
"@rules_python_internal//:rules_python_config_bzl",
220218
],
221219
)

python/extensions/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ bzl_library(
4646
visibility = ["//:__subpackages__"],
4747
deps = [
4848
"//python/private:internal_config_repo_bzl",
49+
"//python/private/pypi:deps_bzl",
4950
],
5051
)

python/private/BUILD.bazel

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ bzl_library(
6666
deps = [
6767
":attr_builders_bzl",
6868
":common_bzl",
69+
":common_labels_bzl",
6970
":enum_bzl",
7071
":flags_bzl",
7172
":py_info_bzl",
@@ -356,6 +357,7 @@ bzl_library(
356357
name = "py_cc_toolchain_rule_bzl",
357358
srcs = ["py_cc_toolchain_rule.bzl"],
358359
deps = [
360+
":common_labels.bzl",
359361
":py_cc_toolchain_info_bzl",
360362
":rules_cc_srcs_bzl",
361363
":util_bzl",
@@ -390,6 +392,7 @@ bzl_library(
390392
srcs = ["py_exec_tools_toolchain.bzl"],
391393
deps = [
392394
":common_bzl",
395+
":common_labels_bzl",
393396
":py_exec_tools_info_bzl",
394397
":sentinel_bzl",
395398
":toolchain_types_bzl",
@@ -405,6 +408,7 @@ bzl_library(
405408
":attributes_bzl",
406409
":cc_helper_bzl",
407410
":common_bzl",
411+
":common_labels_bzl",
408412
":flags_bzl",
409413
":precompile_bzl",
410414
":py_cc_link_params_info_bzl",
@@ -457,6 +461,7 @@ bzl_library(
457461
deps = [
458462
":attributes_bzl",
459463
":common_bzl",
464+
":common_labels_bzl",
460465
":flags_bzl",
461466
":normalize_name_bzl",
462467
":precompile_bzl",
@@ -481,6 +486,7 @@ bzl_library(
481486
name = "py_library_rule_bzl",
482487
srcs = ["py_library_rule.bzl"],
483488
deps = [
489+
":common_labels_bzl",
484490
":py_library_bzl",
485491
],
486492
)
@@ -524,6 +530,7 @@ bzl_library(
524530
srcs = ["py_runtime_rule.bzl"],
525531
deps = [
526532
":attributes_bzl",
533+
":common_labels_bzl",
527534
":flags_bzl",
528535
":py_internal_bzl",
529536
":py_runtime_info_bzl",
@@ -547,6 +554,7 @@ bzl_library(
547554
name = "py_runtime_pair_rule_bzl",
548555
srcs = ["py_runtime_pair_rule.bzl"],
549556
deps = [
557+
":common_labels_bzl",
550558
"//python:py_runtime_bzl",
551559
"//python:py_runtime_info_bzl",
552560
"@bazel_skylib//rules:common_settings",
@@ -593,6 +601,7 @@ bzl_library(
593601
":py_package_bzl",
594602
":stamp_bzl",
595603
":transition_labels_bzl",
604+
":version_bzl",
596605
],
597606
)
598607

@@ -663,7 +672,7 @@ bzl_library(
663672
name = "transition_labels_bzl",
664673
srcs = ["transition_labels.bzl"],
665674
deps = [
666-
"common_labels_bzl",
675+
":common_labels_bzl",
667676
"@bazel_skylib//lib:collections",
668677
"@rules_python_internal//:extra_transition_settings_bzl",
669678
],

python/private/attributes.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
1717
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
1818
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
1919
load(":attr_builders.bzl", "attrb")
20+
load(":common_labels.bzl", "labels")
2021
load(":enum.bzl", "enum")
2122
load(":flags.bzl", "PrecompileFlag", "PrecompileSourceRetentionFlag")
2223
load(":py_info.bzl", "PyInfo")
@@ -370,11 +371,11 @@ files that may be needed at run time belong in `data`.
370371
doc = "Defunct, unused, does nothing.",
371372
),
372373
"_precompile_flag": lambda: attrb.Label(
373-
default = "//python/config_settings:precompile",
374+
default = labels.PRECOMPILE,
374375
providers = [BuildSettingInfo],
375376
),
376377
"_precompile_source_retention_flag": lambda: attrb.Label(
377-
default = "//python/config_settings:precompile_source_retention",
378+
default = labels.PRECOMPILE_SOURCE_RETENTION,
378379
providers = [BuildSettingInfo],
379380
),
380381
# Force enabling auto exec groups, see

python/private/common_labels.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ labels = struct(
99
BOOTSTRAP_IMPL = str(Label("//python/config_settings:bootstrap_impl")),
1010
EXEC_TOOLS_TOOLCHAIN = str(Label("//python/config_settings:exec_tools_toolchain")),
1111
PIP_ENV_MARKER_CONFIG = str(Label("//python/config_settings:pip_env_marker_config")),
12-
PIP_WHL_MUSLC_VERSION = str(Label("//python/config_settings:pip_whl_muslc_version")),
12+
NONE = str(Label("//python:none")),
1313
PIP_WHL = str(Label("//python/config_settings:pip_whl")),
1414
PIP_WHL_GLIBC_VERSION = str(Label("//python/config_settings:pip_whl_glibc_version")),
15+
PIP_WHL_MUSLC_VERSION = str(Label("//python/config_settings:pip_whl_muslc_version")),
1516
PIP_WHL_OSX_ARCH = str(Label("//python/config_settings:pip_whl_osx_arch")),
1617
PIP_WHL_OSX_VERSION = str(Label("//python/config_settings:pip_whl_osx_version")),
1718
PRECOMPILE = str(Label("//python/config_settings:precompile")),
1819
PRECOMPILE_SOURCE_RETENTION = str(Label("//python/config_settings:precompile_source_retention")),
20+
PYC_COLLECTION = str(Label("//python/config_settings:pyc_collection")),
1921
PYTHON_SRC = str(Label("//python/bin:python_src")),
2022
PYTHON_VERSION = str(Label("//python/config_settings:python_version")),
2123
PYTHON_VERSION_MAJOR_MINOR = str(Label("//python/config_settings:python_version_major_minor")),
@@ -24,4 +26,5 @@ labels = struct(
2426
REPL_DEP = str(Label("//python/bin:repl_dep")),
2527
VENVS_SITE_PACKAGES = str(Label("//python/config_settings:venvs_site_packages")),
2628
VENVS_USE_DECLARE_SYMLINK = str(Label("//python/config_settings:venvs_use_declare_symlink")),
29+
VISIBLE_FOR_TESTING = str(Label("//python/private:visible_for_testing")),
2730
)

python/private/py_cc_toolchain_rule.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ https://github.com/bazel-contrib/rules_python/issues/824 is considered done.
2020

2121
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
2222
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
23+
load(":common_labels.bzl", "labels")
2324
load(":py_cc_toolchain_info.bzl", "PyCcToolchainInfo")
2425

2526
def _py_cc_toolchain_impl(ctx):
@@ -70,7 +71,7 @@ py_cc_toolchain = rule(
7071
mandatory = True,
7172
),
7273
"_visible_for_testing": attr.label(
73-
default = "//python/private:visible_for_testing",
74+
default = labels.VISIBLE_FOR_TESTING,
7475
),
7576
},
7677
doc = """\

python/private/py_exec_tools_toolchain.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
load("@bazel_skylib//lib:paths.bzl", "paths")
1818
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
19+
load(":common_labels.bzl", "labels")
1920
load(":py_exec_tools_info.bzl", "PyExecToolsInfo")
2021
load(":sentinel.bzl", "SentinelInfo")
2122
load(":toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE")
@@ -89,7 +90,7 @@ so that the toolchain `py_runtime` field can be correctly forwarded.
8990
doc = "See {obj}`PyExecToolsInfo.precompiler`",
9091
),
9192
"_visible_for_testing": attr.label(
92-
default = "//python/private:visible_for_testing",
93+
default = labels.VISIBLE_FOR_TESTING,
9394
),
9495
},
9596
)

python/private/py_executable.bzl

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ load(
5252
"runfiles_root_path",
5353
"target_platform_has_any_constraint",
5454
)
55+
load(":common_labels.bzl", "labels")
5556
load(":flags.bzl", "BootstrapImplFlag", "VenvsUseDeclareSymlinkFlag")
5657
load(":precompile.bzl", "maybe_precompile")
5758
load(":py_cc_link_params_info.bzl", "PyCcLinkParamsInfo")
@@ -61,19 +62,13 @@ load(":py_internal.bzl", "py_internal")
6162
load(":py_runtime_info.bzl", "DEFAULT_STUB_SHEBANG", "PyRuntimeInfo")
6263
load(":reexports.bzl", "BuiltinPyInfo", "BuiltinPyRuntimeInfo")
6364
load(":rule_builders.bzl", "ruleb")
64-
load(
65-
":toolchain_types.bzl",
66-
"EXEC_TOOLS_TOOLCHAIN_TYPE",
67-
"TARGET_TOOLCHAIN_TYPE",
68-
TOOLCHAIN_TYPE = "TARGET_TOOLCHAIN_TYPE",
69-
)
65+
load(":toolchain_types.bzl", "EXEC_TOOLS_TOOLCHAIN_TYPE", "TARGET_TOOLCHAIN_TYPE", TOOLCHAIN_TYPE = "TARGET_TOOLCHAIN_TYPE")
7066
load(":transition_labels.bzl", "TRANSITION_LABELS")
7167
load(":venv_runfiles.bzl", "create_venv_app_files")
7268

7369
_py_builtins = py_internal
7470
_EXTERNAL_PATH_PREFIX = "external"
7571
_ZIP_RUNFILES_DIRECTORY_NAME = "runfiles"
76-
_PYTHON_VERSION_FLAG = str(Label("//python/config_settings:python_version"))
7772

7873
# Non-Google-specific attributes for executables
7974
# These attributes are for rules that accept Python sources.
@@ -194,7 +189,7 @@ accepting arbitrary Python versions.
194189
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
195190
),
196191
"_bootstrap_impl_flag": lambda: attrb.Label(
197-
default = "//python/config_settings:bootstrap_impl",
192+
default = labels.BOOTSTRAP_IMPL,
198193
providers = [BuildSettingInfo],
199194
),
200195
"_bootstrap_template": lambda: attrb.Label(
@@ -224,10 +219,10 @@ accepting arbitrary Python versions.
224219
default = TARGET_TOOLCHAIN_TYPE,
225220
),
226221
"_python_version_flag": lambda: attrb.Label(
227-
default = "//python/config_settings:python_version",
222+
default = labels.PYTHON_VERSION,
228223
),
229224
"_venvs_use_declare_symlink_flag": lambda: attrb.Label(
230-
default = "//python/config_settings:venvs_use_declare_symlink",
225+
default = labels.VENVS_USE_DECLARE_SYMLINK,
231226
providers = [BuildSettingInfo],
232227
),
233228
"_windows_constraints": lambda: attrb.LabelList(
@@ -1793,7 +1788,7 @@ def _transition_executable_impl(settings, attr):
17931788
apply_config_settings_attr(settings, attr)
17941789

17951790
if attr.python_version and attr.python_version not in ("PY2", "PY3"):
1796-
settings[_PYTHON_VERSION_FLAG] = attr.python_version
1791+
settings[labels.PYTHON_VERSION] = attr.python_version
17971792
return settings
17981793

17991794
def create_executable_rule(*, attrs, **kwargs):
@@ -1844,8 +1839,8 @@ def create_executable_rule_builder(implementation, **kwargs):
18441839
],
18451840
cfg = dict(
18461841
implementation = _transition_executable_impl,
1847-
inputs = TRANSITION_LABELS + [_PYTHON_VERSION_FLAG],
1848-
outputs = TRANSITION_LABELS + [_PYTHON_VERSION_FLAG],
1842+
inputs = TRANSITION_LABELS + [labels.PYTHON_VERSION],
1843+
outputs = TRANSITION_LABELS + [labels.PYTHON_VERSION],
18491844
),
18501845
**kwargs
18511846
)

python/private/py_library.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ load(
3838
"filter_to_py_srcs",
3939
"get_imports",
4040
)
41+
load(":common_labels.bzl", "labels")
4142
load(":flags.bzl", "AddSrcsToRunfilesFlag", "PrecompileFlag", "VenvsSitePackages")
4243
load(":normalize_name.bzl", "normalize_name")
4344
load(":precompile.bzl", "maybe_precompile")
@@ -101,7 +102,7 @@ and that only one package version will be included.
101102
""",
102103
),
103104
"_add_srcs_to_runfiles_flag": lambda: attrb.Label(
104-
default = "//python/config_settings:add_srcs_to_runfiles",
105+
default = labels.ADD_SRCS_TO_RUNFILES,
105106
),
106107
},
107108
)

python/private/py_runtime_pair_rule.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
1818
load("//python:py_runtime_info.bzl", "PyRuntimeInfo")
19+
load(":common_labels.bzl", "labels")
1920
load(":reexports.bzl", "BuiltinPyRuntimeInfo")
2021
load(":util.bzl", "IS_BAZEL_7_OR_HIGHER")
2122

@@ -94,7 +95,7 @@ The runtime to use for Python 3 targets. Must have `python_version` set to
9495
""",
9596
),
9697
"_visible_for_testing": attr.label(
97-
default = "//python/private:visible_for_testing",
98+
default = labels.VISIBLE_FOR_TESTING,
9899
),
99100
},
100101
fragments = ["py"],

0 commit comments

Comments
 (0)