Skip to content

Commit f1a68ab

Browse files
committed
Merge branch 'main' into dev/philsc/repl
2 parents d9bed35 + 61b5a8d commit f1a68ab

File tree

68 files changed

+1941
-1346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1941
-1346
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
55
# To update these lines, execute
66
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
7-
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
8-
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/python/private,gazelle/pythonconfig,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
7+
build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
8+
query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma
99

1010
test --test_output=errors
1111

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ max_line_length = 100
1515
[*.{py,bzl}]
1616
indent_style = space
1717
indent_size = 4
18+
19+
# different overrides for git commit messages
20+
[.git/COMMIT_EDITMSG]
21+
max_line_length = 72

CHANGELOG.md

Lines changed: 27 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.
@@ -78,6 +86,11 @@ END_UNRELEASED_TEMPLATE
7886
multiple times.
7987
* (tools/wheelmaker.py) Extras are now preserved in Requires-Dist metadata when using requires_file
8088
to specify the requirements.
89+
* (pypi) Use bazel downloader for direct URL references and correctly detect the filenames from
90+
various URL formats - URL encoded version strings get correctly resolved, sha256 value can be
91+
also retrieved from the URL as opposed to only the `--hash` parameter. Fixes
92+
[#2363](https://github.com/bazel-contrib/rules_python/issues/2363).
93+
* (pypi) `whl_library` now infers file names from its `urls` attribute correctly.
8194

8295
{#v0-0-0-added}
8396
### Added
@@ -86,11 +99,25 @@ END_UNRELEASED_TEMPLATE
8699
(the default), the subprocess's stdout/stderr will be logged.
87100
* (toolchains) Local toolchains can be activated with custom flags. See
88101
[Conditionally using local toolchains] docs for how to configure.
102+
* (pypi) Starlark-based evaluation of environment markers (requirements.txt conditionals)
103+
available (not enabled by default) for improved multi-platform build support.
104+
Set the `RULES_PYTHON_ENABLE_PIPSTAR=1` environment variable to enable it.
89105

90106
{#v0-0-0-removed}
91107
### Removed
92108
* Nothing removed.
93109

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

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: 11 additions & 4 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():
@@ -33,13 +34,19 @@ def rules_python_internal_setup():
3334
name = "pythons_hub",
3435
minor_mapping = MINOR_MAPPING,
3536
default_python_version = "",
36-
toolchain_prefixes = [],
37-
toolchain_python_versions = [],
38-
toolchain_set_python_version_constraints = [],
39-
toolchain_user_repository_names = [],
4037
python_versions = sorted(TOOL_VERSIONS.keys()),
38+
toolchain_names = [],
39+
toolchain_repo_names = {},
40+
toolchain_target_compatible_with_map = {},
41+
toolchain_target_settings_map = {},
42+
toolchain_platform_keys = {},
43+
toolchain_python_versions = {},
44+
toolchain_set_python_version_constraints = {},
45+
base_toolchain_repo_names = [],
4146
)
4247

48+
runtime_env_repo(name = "rules_python_runtime_env_tc_info")
49+
4350
pypi_deps()
4451

4552
bazel_skylib_workspace()

python/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ bzl_library(
9393
"//python/private:bzlmod_enabled_bzl",
9494
"//python/private:py_package.bzl",
9595
"//python/private:py_wheel_bzl",
96-
"//python/private:py_wheel_normalize_pep440.bzl",
9796
"//python/private:stamp_bzl",
9897
"//python/private:util_bzl",
98+
"//python/private:version.bzl",
9999
"@bazel_skylib//rules:native_binary",
100100
],
101101
)

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+
)

0 commit comments

Comments
 (0)