Skip to content

Commit aca2ad8

Browse files
committed
Merge branch 'main' into refactor-use-pep440-version-parser
2 parents 9c8d123 + a2ff7da commit aca2ad8

34 files changed

+615
-236
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ END_UNRELEASED_TEMPLATE
5555
{#v0-0-0-changed}
5656
### Changed
5757

58+
* If using the (deprecated) autodetecting/runtime_env toolchain, then the Python
59+
version specified at build-time *must* match the Python version used at
60+
runtime (the {obj}`--@rules_python//python/config_settings:python_version`
61+
flag and the {attr}`python_version` attribute control the build-time version
62+
for a target). If they don't match, dependencies won't be importable. (Such a
63+
misconfiguration was unlikely to work to begin with; this is called out as an
64+
FYI).
65+
* (rules) {obj}`--bootstrap_impl=script` is the default for non-Windows.
5866
* (rules) On Windows, {obj}`--bootstrap_impl=system_python` is forced. This
5967
allows setting `--bootstrap_impl=script` in bazelrc for mixed-platform
6068
environments.
@@ -88,11 +96,25 @@ END_UNRELEASED_TEMPLATE
8896
(the default), the subprocess's stdout/stderr will be logged.
8997
* (toolchains) Local toolchains can be activated with custom flags. See
9098
[Conditionally using local toolchains] docs for how to configure.
99+
* (pypi) `RULES_PYTHON_ENABLE_PIPSTAR` environment variable: when `1`, the Starlark
100+
implementation of wheel METADATA parsing is used (which has improved multi-platform
101+
build support).
91102

92103
{#v0-0-0-removed}
93104
### Removed
94105
* Nothing removed.
95106

107+
{#1-4-1}
108+
## [1.4.1] - 2025-05-08
109+
110+
[1.4.1]: https://github.com/bazel-contrib/rules_python/releases/tag/1.4.1
111+
112+
{#1-4-1-fixed}
113+
### Fixed
114+
* (pypi) Fix a typo not allowing users to benefit from using the downloader when the hashes in the
115+
requirements file are not present. Fixes
116+
[#2863](https://github.com/bazel-contrib/rules_python/issues/2863).
117+
96118
{#1-4-0}
97119
## [1.4.0] - 2025-04-19
98120

MODULE.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ internal_dev_deps = use_extension(
9898
"internal_dev_deps",
9999
dev_dependency = True,
100100
)
101-
use_repo(internal_dev_deps, "buildkite_config", "wheel_for_testing")
101+
use_repo(
102+
internal_dev_deps,
103+
"buildkite_config",
104+
"rules_python_runtime_env_tc_info",
105+
"wheel_for_testing",
106+
)
102107

103108
# Add gazelle plugin so that we can run the gazelle example as an e2e integration
104109
# test and include the distribution files.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ Values:
159159
:::
160160
::::
161161

162+
::::{bzl:flag} pip_env_marker_config
163+
The target that provides the values for pip env marker evaluation.
164+
165+
Default: `//python/config_settings:_pip_env_marker_default_config`
166+
167+
This flag points to a target providing {obj}`EnvMarkerInfo`, which determines
168+
the values used when environment markers are resolved at build time.
169+
170+
:::{versionadded} VERSION_NEXT_FEATURE
171+
:::
172+
::::
173+
162174
::::{bzl:flag} pip_whl
163175
Set what distributions are used in the `pip` integration.
164176

@@ -233,6 +245,10 @@ Values:
233245
::::{bzl:flag} bootstrap_impl
234246
Determine how programs implement their startup process.
235247

248+
The default for this depends on the platform:
249+
* Windows: `system_python` (**always** used)
250+
* Other: `script`
251+
236252
Values:
237253
* `system_python`: Use a bootstrap that requires a system Python available
238254
in order to start programs. This requires
@@ -257,6 +273,11 @@ instead.
257273
:::{versionadded} 0.33.0
258274
:::
259275

276+
:::{versionchanged} VERSION_NEXT_FEATURE
277+
* The default for non-Windows changed from `system_python` to `script`.
278+
* On Windows, the value is forced to `system_python`.
279+
:::
280+
260281
::::
261282

262283
::::{bzl:flag} current_config

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

docs/pypi-dependencies.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ leg of the dependency manually. For instance by making
338338
perhaps `apache-airflow-providers-common-sql`.
339339

340340

341-
(bazel-downloader)=
342341
### Multi-platform support
343342

344343
Multi-platform support of cross-building the wheels can be done in two ways - either
@@ -391,6 +390,31 @@ compatible indexes.
391390
This is only supported on `bzlmd`.
392391
```
393392

393+
<!--
394+
395+
TODO: uncomment this when analysis-phase dependency selection is available
396+
397+
#### Customizing requirements resolution
398+
399+
In Python packaging, packages can express dependencies with conditions
400+
using "environment markers", which represent the Python version, OS, etc.
401+
402+
While the PyPI integration provides reasonable defaults to support most
403+
platforms and environment markers, the values it uses can be customized in case
404+
more esoteric configurations are needed.
405+
406+
To customize the values used, you need to do two things:
407+
1. Define a target that returns {obj}`EnvMarkerInfo`
408+
2. Set the {obj}`//python/config_settings:pip_env_marker_config` flag to
409+
the target defined in (1).
410+
411+
The keys and values should be compatible with the [PyPA dependency specifiers
412+
specification](https://packaging.python.org/en/latest/specifications/dependency-specifiers/).
413+
This is not strictly enforced, however, so you can return a subset of keys or
414+
additional keys, which become available during dependency evalution.
415+
416+
-->
417+
394418
(bazel-downloader)=
395419
### Bazel downloader and multi-platform wheel hub repository.
396420

@@ -487,3 +511,9 @@ Bazel will call this file like `cred_helper.sh get` and use the returned JSON to
487511
into whatever HTTP(S) request it performs against `example.com`.
488512

489513
[rfc7617]: https://datatracker.ietf.org/doc/html/rfc7617
514+
515+
<!--
516+
517+
518+
519+
-->

internal_dev_setup.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_
2424
load("//:version.bzl", "SUPPORTED_BAZEL_VERSIONS")
2525
load("//python:versions.bzl", "MINOR_MAPPING", "TOOL_VERSIONS")
2626
load("//python/private:pythons_hub.bzl", "hub_repo") # buildifier: disable=bzl-visibility
27+
load("//python/private:runtime_env_repo.bzl", "runtime_env_repo") # buildifier: disable=bzl-visibility
2728
load("//python/private/pypi:deps.bzl", "pypi_deps") # buildifier: disable=bzl-visibility
2829

2930
def rules_python_internal_setup():
@@ -40,6 +41,8 @@ def rules_python_internal_setup():
4041
python_versions = sorted(TOOL_VERSIONS.keys()),
4142
)
4243

44+
runtime_env_repo(name = "rules_python_runtime_env_tc_info")
45+
4346
pypi_deps()
4447

4548
bazel_skylib_workspace()

python/config_settings/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ string_flag(
9090

9191
rp_string_flag(
9292
name = "bootstrap_impl",
93-
build_setting_default = BootstrapImplFlag.SYSTEM_PYTHON,
93+
build_setting_default = BootstrapImplFlag.SCRIPT,
9494
override = select({
9595
# Windows doesn't yet support bootstrap=script, so force disable it
9696
":_is_windows": BootstrapImplFlag.SYSTEM_PYTHON,
@@ -220,3 +220,10 @@ string_flag(
220220
define_pypi_internal_flags(
221221
name = "define_pypi_internal_flags",
222222
)
223+
224+
label_flag(
225+
name = "pip_env_marker_config",
226+
build_setting_default = ":_pip_env_marker_default_config",
227+
# NOTE: Only public because it is used in pip hub repos.
228+
visibility = ["//visibility:public"],
229+
)

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/config_settings.bzl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,19 @@ def is_python_version_at_least(name, **kwargs):
225225
)
226226

227227
def _python_version_at_least_impl(ctx):
228-
at_least = tuple(ctx.attr.at_least.split("."))
229-
current = tuple(
230-
ctx.attr._major_minor[config_common.FeatureFlagInfo].value.split("."),
231-
)
228+
flag_value = ctx.attr._major_minor[config_common.FeatureFlagInfo].value
229+
230+
# CI is, somehow, getting an empty string for the current flag value.
231+
# How isn't clear.
232+
if not flag_value:
233+
return [config_common.FeatureFlagInfo(value = "no")]
234+
235+
current = tuple([
236+
int(x)
237+
for x in flag_value.split(".")
238+
])
239+
at_least = tuple([int(x) for x in ctx.attr.at_least.split(".")])
240+
232241
value = "yes" if current >= at_least else "no"
233242
return [config_common.FeatureFlagInfo(value = value)]
234243

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,

0 commit comments

Comments
 (0)