Skip to content

Commit 33d5ae4

Browse files
committed
Merge branch 'main' into refactor/pypi-extension
2 parents 9892c86 + af3516e commit 33d5ae4

File tree

18 files changed

+89
-43
lines changed

18 files changed

+89
-43
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ A brief description of the categories of changes:
4646
* (whl_filegroup): Provide per default also the `RECORD` file
4747
* (py_wheel): `RECORD` file entry elements are now quoted if necessary when a
4848
wheel is created
49+
* (whl_library) truncate progress messages from the repo rule to better handle
50+
case where a requirement has many `--hash=sha256:...` flags
4951

5052
### Added
5153
* (py_wheel) Now supports `compress = (True|False)` to allow disabling

docs/api/rules_python/python/runtime_env_toolchains/index.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77

88
::::{target} all
99

10-
A set of toolchains that invoke `python3` from the runtime environment.
11-
12-
Note that this toolchain provides no build-time information, which makes it of
13-
limited utility. This is because the invocation of `python3` is done when a
14-
program is run, not at build time.
10+
A set of toolchains that invoke `python3` from the runtime environment (i.e
11+
after building).
12+
13+
:::{note}
14+
These toolchains do not provide any build-time information, including but not
15+
limited to the Python version or C headers. As such, they cannot be used
16+
for e.g. precompiling, building Python C extension modules, or anything else
17+
that requires information about the Python runtime at build time. Under the
18+
hood, these simply create a fake "interpreter" that calls `python3` that
19+
built programs use to run themselves.
20+
:::
1521

1622
This is only provided to aid migration off the builtin Bazel toolchain
1723
(`@bazel_tools//python:autodetecting_toolchain`), and is largely only applicable

python/config_settings/transition.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def _transition_py_impl(ctx):
101101
]
102102
if PyInfo in target:
103103
providers.append(target[PyInfo])
104-
if BuiltinPyInfo in target and PyInfo != BuiltinPyInfo:
104+
if BuiltinPyInfo != None and BuiltinPyInfo in target and PyInfo != BuiltinPyInfo:
105105
providers.append(target[BuiltinPyInfo])
106106

107107
if PyRuntimeInfo in target:
108108
providers.append(target[PyRuntimeInfo])
109-
if BuiltinPyRuntimeInfo in target and PyRuntimeInfo != BuiltinPyRuntimeInfo:
109+
if BuiltinPyRuntimeInfo != None and BuiltinPyRuntimeInfo in target and PyRuntimeInfo != BuiltinPyRuntimeInfo:
110110
providers.append(target[BuiltinPyRuntimeInfo])
111111
return providers
112112

python/private/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@ bzl_library(
344344
visibility = [
345345
"//:__subpackages__",
346346
],
347-
deps = [":bazel_tools_bzl"],
347+
deps = [
348+
":bazel_tools_bzl",
349+
"@rules_python_internal//:rules_python_config_bzl",
350+
],
348351
)
349352

350353
bzl_library(

python/private/common/attributes.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,16 @@ COMMON_ATTRS = union_attrs(
253253
allow_none = True,
254254
)
255255

256+
_MaybeBuiltinPyInfo = [[BuiltinPyInfo]] if BuiltinPyInfo != None else []
257+
256258
# Attributes common to rules accepting Python sources and deps.
257259
PY_SRCS_ATTRS = union_attrs(
258260
{
259261
"deps": attr.label_list(
260262
providers = [
261263
[PyInfo],
262264
[CcInfo],
263-
[BuiltinPyInfo],
264-
],
265+
] + _MaybeBuiltinPyInfo,
265266
# TODO(b/228692666): Google-specific; remove these allowances once
266267
# the depot is cleaned up.
267268
allow_rules = DEPS_ATTR_ALLOW_RULES,

python/private/common/common.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def collect_imports(ctx, semantics):
280280
dep[BuiltinPyInfo].imports
281281
for dep in ctx.attr.deps
282282
if BuiltinPyInfo in dep
283-
])
283+
] if BuiltinPyInfo != None else [])
284284

285285
def collect_runfiles(ctx, files = depset()):
286286
"""Collects the necessary files from the rule's context.
@@ -374,7 +374,7 @@ def create_py_info(ctx, *, direct_sources, direct_pyc_files, imports):
374374

375375
for target in ctx.attr.deps:
376376
# PyInfo may not be present e.g. cc_library rules.
377-
if PyInfo in target or BuiltinPyInfo in target:
377+
if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target):
378378
py_info.merge(_get_py_info(target))
379379
else:
380380
# TODO(b/228692666): Remove this once non-PyInfo targets are no
@@ -395,7 +395,7 @@ def create_py_info(ctx, *, direct_sources, direct_pyc_files, imports):
395395
for target in ctx.attr.data:
396396
# TODO(b/234730058): Remove checking for PyInfo in data once depot
397397
# cleaned up.
398-
if PyInfo in target or BuiltinPyInfo in target:
398+
if PyInfo in target or (BuiltinPyInfo != None and BuiltinPyInfo in target):
399399
info = _get_py_info(target)
400400
py_info.merge_uses_shared_libraries(info.uses_shared_libraries)
401401
else:
@@ -410,7 +410,7 @@ def create_py_info(ctx, *, direct_sources, direct_pyc_files, imports):
410410
return py_info.build(), deps_transitive_sources, py_info.build_builtin_py_info()
411411

412412
def _get_py_info(target):
413-
return target[PyInfo] if PyInfo in target else target[BuiltinPyInfo]
413+
return target[PyInfo] if PyInfo in target or BuiltinPyInfo == None else target[BuiltinPyInfo]
414414

415415
def create_instrumented_files_info(ctx):
416416
return _coverage_common.instrumented_files_info(

python/private/common/py_executable.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ def _create_providers(
855855
# builtin py_runtime rule or defined their own. We can't directly detect
856856
# the type of the provider object, but the rules_python PyRuntimeInfo
857857
# object has an extra attribute that the builtin one doesn't.
858-
if hasattr(py_runtime_info, "interpreter_version_info"):
858+
if hasattr(py_runtime_info, "interpreter_version_info") and BuiltinPyRuntimeInfo != None:
859859
providers.append(BuiltinPyRuntimeInfo(
860860
interpreter_path = py_runtime_info.interpreter_path,
861861
interpreter = py_runtime_info.interpreter,
@@ -890,7 +890,8 @@ def _create_providers(
890890
)
891891

892892
providers.append(py_info)
893-
providers.append(builtin_py_info)
893+
if builtin_py_info:
894+
providers.append(builtin_py_info)
894895
providers.append(create_output_group_info(py_info.transitive_sources, output_groups))
895896

896897
extra_providers = semantics.get_extra_providers(

python/private/common/py_library.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ def py_library_impl(ctx, *, semantics):
9898
dependency_transitive_python_sources = deps_transitive_sources,
9999
)
100100

101-
return [
101+
providers = [
102102
DefaultInfo(files = default_outputs, runfiles = runfiles),
103103
py_info,
104-
builtins_py_info,
105104
create_instrumented_files_info(ctx),
106105
PyCcLinkParamsProvider(cc_info = cc_info),
107106
create_output_group_info(py_info.transitive_sources, extra_groups = {}),
108107
]
108+
if builtins_py_info:
109+
providers.append(builtins_py_info)
110+
return providers
109111

110112
_DEFAULT_PY_LIBRARY_DOC = """
111113
A library of Python code that can be depended upon.

python/private/common/py_runtime_rule.bzl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,20 @@ def _py_runtime_impl(ctx):
125125
if not IS_BAZEL_7_OR_HIGHER:
126126
builtin_py_runtime_info_kwargs.pop("bootstrap_template")
127127

128-
return [
128+
providers = [
129129
PyRuntimeInfo(**py_runtime_info_kwargs),
130-
# Return the builtin provider for better compatibility.
131-
# 1. There is a legacy code path in py_binary that
132-
# checks for the provider when toolchains aren't used
133-
# 2. It makes it easier to transition from builtins to rules_python
134-
BuiltinPyRuntimeInfo(**builtin_py_runtime_info_kwargs),
135130
DefaultInfo(
136131
files = runtime_files,
137132
runfiles = runfiles,
138133
),
139134
]
135+
if BuiltinPyRuntimeInfo != None and BuiltinPyRuntimeInfo != PyRuntimeInfo:
136+
# Return the builtin provider for better compatibility.
137+
# 1. There is a legacy code path in py_binary that
138+
# checks for the provider when toolchains aren't used
139+
# 2. It makes it easier to transition from builtins to rules_python
140+
providers.append(BuiltinPyRuntimeInfo(**builtin_py_runtime_info_kwargs))
141+
return providers
140142

141143
# Bind to the name "py_runtime" to preserve the kind/rule_class it shows up
142144
# as elsewhere.

python/private/internal_config_repo.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ _ENABLE_PYSTAR_DEFAULT = "1"
2424
_CONFIG_TEMPLATE = """\
2525
config = struct(
2626
enable_pystar = {enable_pystar},
27+
BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}),
28+
BuiltinPyRuntimeInfo = getattr(getattr(native, "legacy_globals", None), "PyRuntimeInfo", {builtin_py_runtime_info_symbol}),
29+
BuiltinPyCcLinkParamsProvider = getattr(getattr(native, "legacy_globals", None), "PyCcLinkParamsProvider", {builtin_py_cc_link_params_provider}),
2730
)
2831
"""
2932

@@ -65,8 +68,20 @@ def _internal_config_repo_impl(rctx):
6568
else:
6669
enable_pystar = False
6770

71+
if native.bazel_version.startswith("8."):
72+
builtin_py_info_symbol = "None"
73+
builtin_py_runtime_info_symbol = "None"
74+
builtin_py_cc_link_params_provider = "None"
75+
else:
76+
builtin_py_info_symbol = "PyInfo"
77+
builtin_py_runtime_info_symbol = "PyRuntimeInfo"
78+
builtin_py_cc_link_params_provider = "PyCcLinkParamsProvider"
79+
6880
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
6981
enable_pystar = enable_pystar,
82+
builtin_py_info_symbol = builtin_py_info_symbol,
83+
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
84+
builtin_py_cc_link_params_provider = builtin_py_cc_link_params_provider,
7085
))
7186

7287
if enable_pystar:

0 commit comments

Comments
 (0)