Skip to content

Commit 2e8aa91

Browse files
aignasrickeylev
andauthored
chore: make pipstar non-switchable (bazel-contrib#3737)
The pipstar code has been there for some time and might be stable enough to not have a fallback anymore. Related bazel-contrib#2949 --------- Co-authored-by: Richard Levasseur <rlevasseur@google.com>
1 parent 5d0016a commit 2e8aa91

25 files changed

Lines changed: 87 additions & 1579 deletions

docs/environment-variables.md

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,6 @@ When `1`, `rules_python` will warn users about deprecated functionality that wil
5252
be removed in a subsequent major `rules_python` version. Defaults to `0` if unset.
5353
:::
5454

55-
::::{envvar} RULES_PYTHON_ENABLE_PYSTAR
56-
57-
When `1`, the `rules_python` Starlark implementation of the core rules is used
58-
instead of the Bazel-builtin rules. Note that this requires Bazel 7+. Defaults
59-
to `1`.
60-
61-
:::{versionadded} 0.26.0
62-
Defaults to `0` if unspecified.
63-
:::
64-
:::{versionchanged} 0.40.0
65-
The default became `1` if unspecified
66-
:::
67-
::::
68-
69-
::::{envvar} RULES_PYTHON_ENABLE_PIPSTAR
70-
71-
When `1`, the `rules_python` Starlark implementation of the PyPI/pip integration is used
72-
instead of the legacy Python scripts.
73-
74-
:::{versionadded} 1.5.0
75-
:::
76-
:::{versionchanged} 1.7.0
77-
Flipped to be enabled by default.
78-
:::
79-
::::
80-
8155
::::{envvar} RULES_PYTHON_EXTRACT_ROOT
8256

8357
Directory to use as the root for creating files necessary for bootstrapping so
@@ -174,3 +148,14 @@ os, arch values are the same as the ones mentioned in the
174148

175149
When `1`, debug information about coverage behavior is printed to stderr.
176150
:::
151+
152+
## Removed Environment Variables
153+
154+
:::{versionremoved} VERSION_NEXT_FEATURE
155+
The following environment variables were removed:
156+
157+
* `RULES_PYTHON_ENABLE_PYSTAR`: Used to enable the Starlark implementation of
158+
core rules.
159+
* `RULES_PYTHON_ENABLE_PIPSTAR`: Used to enable the Starlark implementation of
160+
PyPI integration.
161+
:::

docs/readthedocs_build.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ done < <(env -0)
1212
# In order to get the build number, we extract it from the host name
1313
extra_env+=("--@sphinxdocs//sphinxdocs:extra_env=HOSTNAME=$HOSTNAME")
1414

15-
export RULES_PYTHON_ENABLE_PIPSTAR=1
16-
1715
set -x
18-
export RULES_PYTHON_ENABLE_PIPSTAR=1
1916
bazel run \
2017
--config=rtd \
2118
"--@sphinxdocs//sphinxdocs:extra_defines=version=$READTHEDOCS_VERSION" \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.x

python/private/internal_config_repo.bzl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ settings for rules to later use.
2121
load("//python/private:text_util.bzl", "render")
2222
load(":repo_utils.bzl", "repo_utils")
2323

24-
_ENABLE_PIPSTAR_ENVVAR_NAME = "RULES_PYTHON_ENABLE_PIPSTAR"
25-
_ENABLE_PIPSTAR_DEFAULT = "1"
2624
_ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME = "RULES_PYTHON_DEPRECATION_WARNINGS"
2725
_ENABLE_DEPRECATION_WARNINGS_DEFAULT = "0"
2826

@@ -31,7 +29,6 @@ config = struct(
3129
build_python_zip_default = {build_python_zip_default},
3230
supports_whl_extraction = {supports_whl_extraction},
3331
enable_pystar = True,
34-
enable_pipstar = {enable_pipstar},
3532
enable_deprecation_warnings = {enable_deprecation_warnings},
3633
bazel_8_or_later = {bazel_8_or_later},
3734
bazel_9_or_later = {bazel_9_or_later},
@@ -104,7 +101,6 @@ def _internal_config_repo_impl(rctx):
104101

105102
rctx.file("rules_python_config.bzl", _CONFIG_TEMPLATE.format(
106103
build_python_zip_default = repo_utils.get_platforms_os_name(rctx) == "windows",
107-
enable_pipstar = _bool_from_environ(rctx, _ENABLE_PIPSTAR_ENVVAR_NAME, _ENABLE_PIPSTAR_DEFAULT),
108104
enable_deprecation_warnings = _bool_from_environ(rctx, _ENABLE_DEPRECATION_WARNINGS_ENVVAR_NAME, _ENABLE_DEPRECATION_WARNINGS_DEFAULT),
109105
builtin_py_info_symbol = builtin_py_info_symbol,
110106
builtin_py_runtime_info_symbol = builtin_py_runtime_info_symbol,
@@ -139,7 +135,7 @@ def _internal_config_repo_impl(rctx):
139135
internal_config_repo = repository_rule(
140136
implementation = _internal_config_repo_impl,
141137
configure = True,
142-
environ = [_ENABLE_PIPSTAR_ENVVAR_NAME],
138+
environ = [],
143139
attrs = {
144140
"transition_setting_generators": attr.string_list_dict(),
145141
"transition_settings": attr.string_list(),

python/private/pypi/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,13 @@ bzl_library(
113113
":deps_bzl",
114114
":pep508_evaluate_bzl",
115115
":pep508_requirement_bzl",
116-
":pypi_repo_utils_bzl",
117116
],
118117
)
119118

120119
bzl_library(
121120
name = "extension_bzl",
122121
srcs = ["extension.bzl"],
123122
deps = [
124-
":evaluate_markers_bzl",
125123
":hub_builder_bzl",
126124
":hub_repository_bzl",
127125
":parse_whl_name_bzl",
@@ -331,6 +329,7 @@ bzl_library(
331329
":attrs_bzl",
332330
":evaluate_markers_bzl",
333331
":parse_requirements_bzl",
332+
":pep508_env_bzl",
334333
":pip_repository_attrs_bzl",
335334
":pypi_repo_utils_bzl",
336335
":render_pkg_aliases_bzl",

python/private/pypi/attrs.bzl

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -118,39 +118,6 @@ Warning:
118118
If a dependency participates in multiple cycles, all of those cycles must be
119119
collapsed down to one. For instance `a <-> b` and `a <-> c` cannot be listed
120120
as two separate cycles.
121-
""",
122-
),
123-
"experimental_target_platforms": attr.string_list(
124-
default = [],
125-
doc = """\
126-
*NOTE*: This will be removed in the next major version, so please consider migrating
127-
to `bzlmod` and rely on {attr}`pip.parse.requirements_by_platform` for this feature.
128-
129-
A list of platforms that we will generate the conditional dependency graph for
130-
cross platform wheels by parsing the wheel metadata. This will generate the
131-
correct dependencies for packages like `sphinx` or `pylint`, which include
132-
`colorama` when installed and used on Windows platforms.
133-
134-
An empty list means falling back to the legacy behaviour where the host
135-
platform is the target platform.
136-
137-
WARNING: It may not work as expected in cases where the python interpreter
138-
implementation that is being used at runtime is different between different platforms.
139-
This has been tested for CPython only.
140-
141-
For specific target platforms use values of the form `<os>_<arch>` where `<os>`
142-
is one of `linux`, `osx`, `windows` and arch is one of `x86_64`, `x86_32`,
143-
`aarch64`, `s390x` and `ppc64le`.
144-
145-
You can also target a specific Python version by using `cp3<minor_version>_<os>_<arch>`.
146-
If multiple python versions are specified as target platforms, then select statements
147-
of the `lib` and `whl` targets will include usage of version aware toolchain config
148-
settings like `@rules_python//python/config_settings:is_python_3.y`.
149-
150-
Special values: `host` (for generating deps for the host platform only) and
151-
`<prefix>_*` values. For example, `cp39_*`, `linux_*`, `cp39_linux_*`.
152-
153-
NOTE: this is not for cross-compiling Python wheels but rather for parsing the `whl` METADATA correctly.
154121
""",
155122
),
156123
"extra_hub_aliases": attr.string_list_dict(

python/private/pypi/evaluate_markers.bzl

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,8 @@
1414

1515
"""A simple function that evaluates markers using a python interpreter."""
1616

17-
load(":deps.bzl", "record_files")
1817
load(":pep508_evaluate.bzl", "evaluate")
1918
load(":pep508_requirement.bzl", "requirement")
20-
load(":pypi_repo_utils.bzl", "pypi_repo_utils")
21-
22-
# Used as a default value in a rule to ensure we fetch the dependencies.
23-
SRCS = [
24-
# When the version, or any of the files in `packaging` package changes,
25-
# this file will change as well.
26-
record_files["pypi__packaging"],
27-
Label("//python/private/pypi/requirements_parser:resolve_target_platforms.py"),
28-
Label("//python/private/pypi/whl_installer:platform.py"),
29-
]
3019

3120
def evaluate_markers(*, requirements, platforms):
3221
"""Return the list of supported platforms per requirements line.
@@ -51,57 +40,3 @@ def evaluate_markers(*, requirements, platforms):
5140
ret.setdefault(req_string, []).append(platform_str)
5241

5342
return ret
54-
55-
def evaluate_markers_py(mrctx, *, requirements, python_interpreter, python_interpreter_target, srcs, logger = None):
56-
"""Return the list of supported platforms per requirements line.
57-
58-
Args:
59-
mrctx: repository_ctx or module_ctx.
60-
requirements: {type}`dict[str, list[str]]` of the requirement file lines to evaluate.
61-
python_interpreter: str, path to the python_interpreter to use to
62-
evaluate the env markers in the given requirements files. It will
63-
be only called if the requirements files have env markers. This
64-
should be something that is in your PATH or an absolute path.
65-
python_interpreter_target: Label, same as python_interpreter, but in a
66-
label format.
67-
srcs: list[Label], the value of SRCS passed from the `rctx` or `mctx` to this function.
68-
logger: repo_utils.logger or None, a simple struct to log diagnostic
69-
messages. Defaults to None.
70-
71-
Returns:
72-
dict of string lists with target platforms
73-
"""
74-
if not requirements:
75-
return {}
76-
77-
in_file = mrctx.path("requirements_with_markers.in.json")
78-
out_file = mrctx.path("requirements_with_markers.out.json")
79-
mrctx.file(in_file, json.encode(requirements))
80-
81-
interpreter = pypi_repo_utils.resolve_python_interpreter(
82-
mrctx,
83-
python_interpreter = python_interpreter,
84-
python_interpreter_target = python_interpreter_target,
85-
)
86-
87-
pypi_repo_utils.execute_checked(
88-
mrctx,
89-
op = "ResolveRequirementEnvMarkers({})".format(in_file),
90-
python = interpreter,
91-
arguments = [
92-
"-m",
93-
"python.private.pypi.requirements_parser.resolve_target_platforms",
94-
in_file,
95-
out_file,
96-
],
97-
srcs = srcs,
98-
environment = {
99-
"PYTHONHOME": str(interpreter.dirname),
100-
"PYTHONPATH": [
101-
Label("@pypi__packaging//:BUILD.bazel"),
102-
Label("//:BUILD.bazel"),
103-
],
104-
},
105-
logger = logger,
106-
)
107-
return json.decode(mrctx.read(out_file))

python/private/pypi/extension.bzl

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ load("@rules_python_internal//:rules_python_config.bzl", rp_config = "config")
2020
load("//python/private:auth.bzl", "AUTH_ATTRS")
2121
load("//python/private:normalize_name.bzl", "normalize_name")
2222
load("//python/private:repo_utils.bzl", "repo_utils")
23-
load(":evaluate_markers.bzl", EVALUATE_MARKERS_SRCS = "SRCS")
2423
load(":hub_builder.bzl", "hub_builder")
2524
load(":hub_repository.bzl", "hub_repository", "whl_config_settings_to_json")
2625
load(":parse_whl_name.bzl", "parse_whl_name")
@@ -71,14 +70,11 @@ def _configure(config, *, override = False, **kwargs):
7170
def build_config(
7271
*,
7372
module_ctx,
74-
enable_pipstar,
7573
enable_pipstar_extract):
7674
"""Parse 'configure' and 'default' extension tags
7775
7876
Args:
7977
module_ctx: {type}`module_ctx` module context.
80-
enable_pipstar: {type}`bool` a flag to enable dropping Python dependency for
81-
evaluation of the extension.
8278
enable_pipstar_extract: {type}`bool | None` a flag to also not pass Python
8379
interpreter to `whl_library` when possible.
8480
@@ -132,24 +128,20 @@ def build_config(
132128
name: _plat(**values)
133129
for name, values in defaults["platforms"].items()
134130
},
135-
enable_pipstar = enable_pipstar,
136131
enable_pipstar_extract = enable_pipstar_extract,
137132
)
138133

139134
def parse_modules(
140135
module_ctx,
141136
_fail = fail,
142137
simpleapi_download = simpleapi_download,
143-
enable_pipstar = False,
144138
enable_pipstar_extract = False,
145139
**kwargs):
146140
"""Implementation of parsing the tag classes for the extension and return a struct for registering repositories.
147141
148142
Args:
149143
module_ctx: {type}`module_ctx` module context.
150144
simpleapi_download: Used for testing overrides
151-
enable_pipstar: {type}`bool` a flag to enable dropping Python dependency for
152-
evaluation of the extension.
153145
enable_pipstar_extract: {type}`bool` a flag to enable dropping Python dependency for
154146
extracting wheels.
155147
_fail: {type}`function` the failure function, mainly for testing.
@@ -189,7 +181,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
189181
srcs_exclude_glob = whl_mod.srcs_exclude_glob,
190182
)
191183

192-
config = build_config(module_ctx = module_ctx, enable_pipstar = enable_pipstar, enable_pipstar_extract = enable_pipstar_extract)
184+
config = build_config(module_ctx = module_ctx, enable_pipstar_extract = enable_pipstar_extract)
193185

194186
# TODO @aignas 2025-06-03: Merge override API with the builder?
195187
_overriden_whl_set = {}
@@ -377,8 +369,7 @@ def _pip_impl(module_ctx):
377369

378370
mods = parse_modules(
379371
module_ctx,
380-
enable_pipstar = rp_config.enable_pipstar,
381-
enable_pipstar_extract = rp_config.enable_pipstar and rp_config.bazel_8_or_later,
372+
enable_pipstar_extract = rp_config.bazel_8_or_later,
382373
)
383374

384375
# Build all of the wheel modifications if the tag class is called.
@@ -447,10 +438,6 @@ Supported keys:
447438
* `platform_system`, defaults to a value inferred from the {attr}`os_name`.
448439
* `platform_version`, defaults to `0`.
449440
* `sys_platform`, defaults to a value inferred from the {attr}`os_name`.
450-
451-
::::{note}
452-
This is only used if the {envvar}`RULES_PYTHON_ENABLE_PIPSTAR` is enabled.
453-
::::
454441
""",
455442
),
456443
"index_url": attr.string(
@@ -716,13 +703,6 @@ a string `"{os}_{arch}"` as the value here. You could also use `"{os}_{arch}_fre
716703
doc = """\
717704
A dict of labels to wheel names that is typically generated by the whl_modifications.
718705
The labels are JSON config files describing the modifications.
719-
""",
720-
),
721-
"_evaluate_markers_srcs": attr.label_list(
722-
default = EVALUATE_MARKERS_SRCS,
723-
doc = """\
724-
The list of labels to use as SRCS for the marker evaluation code. This ensures that the
725-
code will be re-evaluated when any of files in the default changes.
726706
""",
727707
),
728708
}, **ATTRS)

0 commit comments

Comments
 (0)