Skip to content

Commit a966f28

Browse files
committed
Merge branch 'main' into exp/distinfo-venv
2 parents 1d34260 + 9429ae6 commit a966f28

33 files changed

+821
-177
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ END_UNRELEASED_TEMPLATE
9393
also retrieved from the URL as opposed to only the `--hash` parameter. Fixes
9494
[#2363](https://github.com/bazel-contrib/rules_python/issues/2363).
9595
* (pypi) `whl_library` now infers file names from its `urls` attribute correctly.
96+
* (pypi) When running under `bazel test`, be sure that temporary `requirements` file
97+
remains writable.
9698
* (py_test, py_binary) Allow external files to be used for main
99+
* (pypi) Correctly aggregate the sources when the hashes specified in the lockfile differ
100+
by platform even though the same version is used. Fixes [#2648](https://github.com/bazel-contrib/rules_python/issues/2648).
101+
* (pypi) `compile_pip_requirements` test rule works behind the proxy
97102

98103
{#v0-0-0-added}
99104
### Added
@@ -107,6 +112,15 @@ END_UNRELEASED_TEMPLATE
107112
Set the `RULES_PYTHON_ENABLE_PIPSTAR=1` environment variable to enable it.
108113
* (utils) Add a way to run a REPL for any `rules_python` target that returns
109114
a `PyInfo` provider.
115+
* (uv) Handle `.netrc` and `auth_patterns` auth when downloading `uv`. Work towards
116+
[#1975](https://github.com/bazel-contrib/rules_python/issues/1975).
117+
* (toolchains) Arbitrary python-build-standalone runtimes can be registered
118+
and activated with custom flags. See the [Registering custom runtimes]
119+
docs and {obj}`single_version_platform_override()` API docs for more
120+
information.
121+
* (rules) Added support for a using constraints files with `compile_pip_requirements`.
122+
Useful when an intermediate dependency needs to be upgraded to pull in
123+
security patches.
110124

111125
{#v0-0-0-removed}
112126
### Removed

MODULE.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ dev_python.override(
131131
register_all_versions = True,
132132
)
133133

134+
# For testing an arbitrary runtime triggered by a custom flag.
135+
# See //tests/toolchains:custom_platform_toolchain_test
136+
dev_python.single_version_platform_override(
137+
platform = "linux-x86-install-only-stripped",
138+
python_version = "3.13.1",
139+
sha256 = "56817aa976e4886bec1677699c136cb01c1cdfe0495104c0d8ef546541864bbb",
140+
target_compatible_with = [
141+
"@platforms//os:linux",
142+
"@platforms//cpu:x86_64",
143+
],
144+
target_settings = [
145+
"@@//tests/support:is_custom_runtime_linux-x86-install-only-stripped",
146+
],
147+
urls = ["https://github.com/astral-sh/python-build-standalone/releases/download/20250115/cpython-3.13.1+20250115-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz"],
148+
)
149+
134150
dev_pip = use_extension(
135151
"//python/extensions:pip.bzl",
136152
"pip",

docs/toolchains.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,73 @@ existing attributes:
243243
* Adding additional Python versions via {bzl:obj}`python.single_version_override` or
244244
{bzl:obj}`python.single_version_platform_override`.
245245

246+
### Registering custom runtimes
247+
248+
Because the python-build-standalone project has _thousands_ of prebuilt runtimes
249+
available, rules_python only includes popular runtimes in its built in
250+
configurations. If you want to use a runtime that isn't already known to
251+
rules_python then {obj}`single_version_platform_override()` can be used to do
252+
so. In short, it allows specifying an arbitrary URL and using custom flags
253+
to control when a runtime is used.
254+
255+
In the example below, we register a particular python-build-standalone runtime
256+
that is activated for Linux x86 builds when the custom flag
257+
`--//:runtime=my-custom-runtime` is set.
258+
259+
```
260+
# File: MODULE.bazel
261+
bazel_dep(name = "bazel_skylib", version = "1.7.1.")
262+
bazel_dep(name = "rules_python", version = "1.5.0")
263+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
264+
python.single_version_platform_override(
265+
platform = "my-platform",
266+
python_version = "3.13.3",
267+
sha256 = "01d08b9bc8a96698b9d64c2fc26da4ecc4fa9e708ce0a34fb88f11ab7e552cbd",
268+
os_name = "linux",
269+
arch = "x86_64",
270+
target_settings = [
271+
"@@//:runtime=my-custom-runtime",
272+
],
273+
urls = ["https://github.com/astral-sh/python-build-standalone/releases/download/20250409/cpython-3.13.3+20250409-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz"],
274+
)
275+
# File: //:BUILD.bazel
276+
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
277+
string_flag(
278+
name = "custom_runtime",
279+
build_setting_default = "",
280+
)
281+
config_setting(
282+
name = "is_custom_runtime_linux-x86-install-only-stripped",
283+
flag_values = {
284+
":custom_runtime": "linux-x86-install-only-stripped",
285+
},
286+
)
287+
```
288+
289+
Notes:
290+
- While any URL and archive can be used, it's assumed their content looks how
291+
a python-build-standalone archive looks.
292+
- A "version aware" toolchain is registered, which means the Python version flag
293+
must also match (e.g. `--@rules_python//python/config_settings:python_version=3.13.3`
294+
must be set -- see `minor_mapping` and `is_default` for controls and docs
295+
about version matching and selection).
296+
- The `target_compatible_with` attribute can be used to entirely specify the
297+
arg of the same name the toolchain uses.
298+
- The labels in `target_settings` must be absolute; `@@` refers to the main repo.
299+
- The `target_settings` are `config_setting` targets, which means you can
300+
customize how matching occurs.
301+
302+
:::{seealso}
303+
See {obj}`//python/config_settings` for flags rules_python already defines
304+
that can be used with `target_settings`. Some particular ones of note are:
305+
{flag}`--py_linux_libc` and {flag}`--py_freethreaded`, among others.
306+
:::
307+
308+
:::{versionadded} VERSION_NEXT_FEATURE
309+
Added support for custom platform names, `target_compatible_with`, and
310+
`target_settings` with `single_version_platform_override`.
311+
:::
312+
246313
### Using defined toolchains from WORKSPACE
247314

248315
It is possible to use toolchains defined in `MODULE.bazel` in `WORKSPACE`. For example

examples/pip_parse/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ py_console_script_binary(
5757
compile_pip_requirements(
5858
name = "requirements",
5959
src = "requirements.in",
60+
constraints = [
61+
"constraints_certifi.txt",
62+
"constraints_urllib3.txt",
63+
],
6064
requirements_txt = "requirements_lock.txt",
6165
requirements_windows = "requirements_windows.txt",
6266
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
certifi>=2025.1.31
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
urllib3>1.26.18

examples/pip_parse/requirements_lock.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ babel==2.13.1 \
1212
--hash=sha256:33e0952d7dd6374af8dbf6768cc4ddf3ccfefc244f9986d4074704f2fbd18900 \
1313
--hash=sha256:7077a4984b02b6727ac10f1f7294484f737443d7e2e66c5e4380e41a3ae0b4ed
1414
# via sphinx
15-
certifi==2024.7.4 \
16-
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
17-
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
18-
# via requests
15+
certifi==2025.4.26 \
16+
--hash=sha256:0a816057ea3cdefcef70270d2c515e4506bbc954f417fa5ade2021213bb8f0c6 \
17+
--hash=sha256:30350364dfe371162649852c63336a15c70c6510c2ad5015b21c2345311805f3
18+
# via
19+
# -c ./constraints_certifi.txt
20+
# requests
1921
chardet==4.0.0 \
2022
--hash=sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa \
2123
--hash=sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5
@@ -218,10 +220,12 @@ sphinxcontrib-serializinghtml==1.1.9 \
218220
# via
219221
# -r requirements.in
220222
# sphinx
221-
urllib3==1.26.18 \
222-
--hash=sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07 \
223-
--hash=sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0
224-
# via requests
223+
urllib3==1.26.20 \
224+
--hash=sha256:0ed14ccfbf1c30a9072c7ca157e4319b70d65f623e91e7b32fadb2853431016e \
225+
--hash=sha256:40c2dc0c681e47eb8f90e7e27bf6ff7df2e677421fd46756da1161c39ca70d32
226+
# via
227+
# -c ./constraints_urllib3.txt
228+
# requests
225229
yamllint==1.28.0 \
226230
--hash=sha256:89bb5b5ac33b1ade059743cf227de73daa34d5e5a474b06a5e17fc16583b0cf2 \
227231
--hash=sha256:9e3d8ddd16d0583214c5fdffe806c9344086721f107435f68bad990e5a88826b

examples/pip_parse/requirements_windows.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ babel==2.13.1 \
1212
--hash=sha256:33e0952d7dd6374af8dbf6768cc4ddf3ccfefc244f9986d4074704f2fbd18900 \
1313
--hash=sha256:7077a4984b02b6727ac10f1f7294484f737443d7e2e66c5e4380e41a3ae0b4ed
1414
# via sphinx
15-
certifi==2024.7.4 \
16-
--hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \
17-
--hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90
18-
# via requests
15+
certifi==2025.4.26 \
16+
--hash=sha256:0a816057ea3cdefcef70270d2c515e4506bbc954f417fa5ade2021213bb8f0c6 \
17+
--hash=sha256:30350364dfe371162649852c63336a15c70c6510c2ad5015b21c2345311805f3
18+
# via
19+
# -c ./constraints_certifi.txt
20+
# requests
1921
chardet==4.0.0 \
2022
--hash=sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa \
2123
--hash=sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5
@@ -222,10 +224,12 @@ sphinxcontrib-serializinghtml==1.1.9 \
222224
# via
223225
# -r requirements.in
224226
# sphinx
225-
urllib3==1.26.18 \
226-
--hash=sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07 \
227-
--hash=sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0
228-
# via requests
227+
urllib3==1.26.20 \
228+
--hash=sha256:0ed14ccfbf1c30a9072c7ca157e4319b70d65f623e91e7b32fadb2853431016e \
229+
--hash=sha256:40c2dc0c681e47eb8f90e7e27bf6ff7df2e677421fd46756da1161c39ca70d32
230+
# via
231+
# -c ./constraints_urllib3.txt
232+
# requests
229233
yamllint==1.28.0 \
230234
--hash=sha256:89bb5b5ac33b1ade059743cf227de73daa34d5e5a474b06a5e17fc16583b0cf2 \
231235
--hash=sha256:9e3d8ddd16d0583214c5fdffe806c9344086721f107435f68bad990e5a88826b

internal_dev_setup.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def rules_python_internal_setup():
4242
toolchain_platform_keys = {},
4343
toolchain_python_versions = {},
4444
toolchain_set_python_version_constraints = {},
45-
base_toolchain_repo_names = [],
45+
host_compatible_repo_names = [],
4646
)
4747

4848
runtime_env_repo(name = "rules_python_runtime_env_tc_info")

python/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ bzl_library(
247247
name = "versions_bzl",
248248
srcs = ["versions.bzl"],
249249
visibility = ["//:__subpackages__"],
250+
deps = ["//python/private:platform_info_bzl"],
250251
)
251252

252253
# NOTE: Remember to add bzl_library targets to //tests:bzl_libraries

0 commit comments

Comments
 (0)