Skip to content

Commit 5f893b0

Browse files
committed
Merge branch 'main' of https://github.com/bazel-contrib/rules_python into feat.bootstrap.script.default
2 parents 4f81501 + 1492ae4 commit 5f893b0

File tree

11 files changed

+194
-90
lines changed

11 files changed

+194
-90
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ END_UNRELEASED_TEMPLATE
8787
(the default), the subprocess's stdout/stderr will be logged.
8888
* (toolchains) Local toolchains can be activated with custom flags. See
8989
[Conditionally using local toolchains] docs for how to configure.
90+
* (pypi) `RULES_PYTHON_ENABLE_PIPSTAR` environment variable: when `1`, the Starlark
91+
implementation of wheel METADATA parsing is used (which has improved multi-platform
92+
build support).
9093

9194
{#v0-0-0-removed}
9295
### Removed

docs/environment-variables.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ The default became `1` if unspecified
6060
:::
6161
::::
6262

63+
::::{envvar} RULES_PYTHON_ENABLE_PIPSTAR
64+
65+
When `1`, the rules_python Starlark implementation of the pypi/pip integration is used
66+
instead of the legacy Python scripts.
67+
68+
:::{versionadded} VERSION_NEXT_FEATURE
69+
:::
70+
::::
71+
6372
::::{envvar} RULES_PYTHON_EXTRACT_ROOT
6473

6574
Directory to use as the root for creating files necessary for bootstrapping so

python/private/attributes.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,14 @@ COVERAGE_ATTRS = {
397397
"_collect_cc_coverage": lambda: attrb.Label(
398398
default = "@bazel_tools//tools/test:collect_cc_coverage",
399399
executable = True,
400-
cfg = "exec",
400+
cfg = config.exec(exec_group = "test"),
401401
),
402402
# Magic attribute to make coverage work. There's no
403403
# docs about this; see TestActionBuilder.java
404404
"_lcov_merger": lambda: attrb.Label(
405405
default = configuration_field(fragment = "coverage", name = "output_generator"),
406406
executable = True,
407-
cfg = "exec",
407+
cfg = config.exec(exec_group = "test"),
408408
),
409409
}
410410

python/private/internal_config_repo.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ settings for rules to later use.
2020

2121
load(":repo_utils.bzl", "repo_utils")
2222

23+
_ENABLE_PIPSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PIPSTAR"
24+
_ENABLE_PIPSTAR_DEFAULT = "0"
2325
_ENABLE_PYSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PYSTAR"
2426
_ENABLE_PYSTAR_DEFAULT = "1"
2527
_ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME = "RULES_PYTHON_DEPRECATION_WARNINGS"
@@ -28,6 +30,7 @@ _ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"
2830
_CONFIG_TEMPLATE = """\
2931
config = struct(
3032
enable_pystar = {enable_pystar},
33+
enable_pipstar = {enable_pipstar},
3134
enable_deprecation_warnings = {enable_deprecation_warnings},
3235
BuiltinPyInfo = getattr(getattr(native, "legacy_globals", None), "PyInfo", {builtin_py_info_symbol}),
3336
BuiltinPyRuntimeInfo = getattr(getattr(native, "legacy_globals", None), "PyRuntimeInfo", {builtin_py_runtime_info_symbol}),
@@ -84,6 +87,7 @@ def _internal_config_repo_impl(rctx):
8487

8588
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
8689
enable_pystar = enable_pystar,
90+
enable_pipstar = _bool_from_environ(rctx, _ENABLE_PIPSTAR_ENVVAR_NAME, _ENABLE_PIPSTAR_DEFAULT),
8791
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
8892
builtin_py_info_symbol = builtin_py_info_symbol,
8993
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,

python/private/py_executable.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ EXECUTABLE_ATTRS = dicts.add(
7878
AGNOSTIC_EXECUTABLE_ATTRS,
7979
PY_SRCS_ATTRS,
8080
IMPORTS_ATTRS,
81-
COVERAGE_ATTRS,
8281
{
8382
"interpreter_args": lambda: attrb.StringList(
8483
doc = """
@@ -1903,7 +1902,7 @@ def create_executable_rule_builder(implementation, **kwargs):
19031902
"""
19041903
builder = ruleb.Rule(
19051904
implementation = implementation,
1906-
attrs = EXECUTABLE_ATTRS,
1905+
attrs = EXECUTABLE_ATTRS | (COVERAGE_ATTRS if kwargs.get("test") else {}),
19071906
exec_groups = dict(REQUIRED_EXEC_GROUP_BUILDERS), # Mutable copy
19081907
fragments = ["py", "bazel_py"],
19091908
provides = [PyExecutableInfo, PyInfo] + _MaybeBuiltinPyInfo,

python/private/pypi/whl_installer/arguments.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def parser(**kwargs: Any) -> argparse.ArgumentParser:
4747
type=Platform.from_string,
4848
help="Platforms to target dependencies. Can be used multiple times.",
4949
)
50+
parser.add_argument(
51+
"--enable-pipstar",
52+
action="store_true",
53+
help="Disable certain code paths if we expect to process the whl in Starlark.",
54+
)
5055
parser.add_argument(
5156
"--pip_data_exclude",
5257
action="store",

python/private/pypi/whl_installer/wheel_installer.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def _setup_namespace_pkg_compatibility(wheel_dir: str) -> None:
104104
def _extract_wheel(
105105
wheel_file: str,
106106
extras: Dict[str, Set[str]],
107+
enable_pipstar: bool,
107108
enable_implicit_namespace_pkgs: bool,
108109
platforms: List[wheel.Platform],
109110
installation_dir: Path = Path("."),
@@ -114,6 +115,7 @@ def _extract_wheel(
114115
wheel_file: the filepath of the .whl
115116
installation_dir: the destination directory for installation of the wheel.
116117
extras: a list of extras to add as dependencies for the installed wheel
118+
enable_pipstar: if true, turns off certain operations.
117119
enable_implicit_namespace_pkgs: if true, disables conversion of implicit namespace packages and will unzip as-is
118120
"""
119121

@@ -123,26 +125,31 @@ def _extract_wheel(
123125
if not enable_implicit_namespace_pkgs:
124126
_setup_namespace_pkg_compatibility(installation_dir)
125127

126-
extras_requested = extras[whl.name] if whl.name in extras else set()
127-
128-
dependencies = whl.dependencies(extras_requested, platforms)
128+
metadata = {
129+
"python_version": f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}",
130+
"entry_points": [
131+
{
132+
"name": name,
133+
"module": module,
134+
"attribute": attribute,
135+
}
136+
for name, (module, attribute) in sorted(whl.entry_points().items())
137+
],
138+
}
139+
if not enable_pipstar:
140+
extras_requested = extras[whl.name] if whl.name in extras else set()
141+
dependencies = whl.dependencies(extras_requested, platforms)
142+
143+
metadata.update(
144+
{
145+
"name": whl.name,
146+
"version": whl.version,
147+
"deps": dependencies.deps,
148+
"deps_by_platform": dependencies.deps_select,
149+
}
150+
)
129151

130152
with open(os.path.join(installation_dir, "metadata.json"), "w") as f:
131-
metadata = {
132-
"name": whl.name,
133-
"version": whl.version,
134-
"deps": dependencies.deps,
135-
"python_version": f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}",
136-
"deps_by_platform": dependencies.deps_select,
137-
"entry_points": [
138-
{
139-
"name": name,
140-
"module": module,
141-
"attribute": attribute,
142-
}
143-
for name, (module, attribute) in sorted(whl.entry_points().items())
144-
],
145-
}
146153
json.dump(metadata, f)
147154

148155

@@ -161,6 +168,7 @@ def main() -> None:
161168
_extract_wheel(
162169
wheel_file=whl,
163170
extras=extras,
171+
enable_pipstar=args.enable_pipstar,
164172
enable_implicit_namespace_pkgs=args.enable_implicit_namespace_pkgs,
165173
platforms=arguments.get_platforms(args),
166174
)

0 commit comments

Comments
 (0)