Skip to content

Commit 37c64ed

Browse files
committed
Merge branch 'main' into feat/support-requirement-markers
2 parents b9efaab + 68f752e commit 37c64ed

16 files changed

+344
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ A brief description of the categories of changes:
3131
* (rules) Signals are properly received when using {obj}`--bootstrap_impl=script`
3232
(for non-zip builds).
3333
([#2043](https://github.com/bazelbuild/rules_python/issues/2043))
34-
* (rules) Fixes python builds when the `--build_python_zip` is set to `false` on Windows. See [#1840](https://github.com/bazelbuild/rules_python/issues/1840).
35-
* (pypi) Fixed pypi parse_simpleapi_html function for feeds with package metadata
36-
containing ">" sign.
34+
* (rules) Fixes Python builds when the `--build_python_zip` is set to `false` on
35+
Windows. See [#1840](https://github.com/bazelbuild/rules_python/issues/1840).
36+
* (rules) Fixes Mac + `--build_python_zip` + {obj}`--bootstrap_impl=script`
37+
([#2030](https://github.com/bazelbuild/rules_python/issues/2030)).
38+
* (pip) Fixed pypi parse_simpleapi_html function for feeds with package metadata
39+
containing ">" sign
3740
* (pypi) Support env markers in requirements files. Note, that this means that
3841
if your requirements files contain env markers, the Python interpreter will
3942
have to be downloaded to re-evaluate the bzlmod extension.

examples/pip_parse/requirements_lock.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ zipp==3.17.0 \
232232
# via importlib-metadata
233233

234234
# The following packages are considered to be unsafe in a requirements file:
235-
setuptools==65.6.3 \
236-
--hash=sha256:57f6f22bde4e042978bcd50176fdb381d7c21a9efa4041202288d3737a0c6a54 \
237-
--hash=sha256:a7620757bf984b58deaf32fc8a4577a9bbc0850cf92c20e1ce41c38c19e5fb75
235+
setuptools==70.0.0 \
236+
--hash=sha256:54faa7f2e8d2d11bcd2c07bed282eef1046b5c080d1c32add737d7b5817b1ad4 \
237+
--hash=sha256:f211a66637b8fa059bb28183da127d4e86396c991a942b028c6650d4319c3fd0
238238
# via yamllint

examples/pip_parse/requirements_windows.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ zipp==3.17.0 \
236236
# via importlib-metadata
237237

238238
# The following packages are considered to be unsafe in a requirements file:
239-
setuptools==65.6.3 \
240-
--hash=sha256:57f6f22bde4e042978bcd50176fdb381d7c21a9efa4041202288d3737a0c6a54 \
241-
--hash=sha256:a7620757bf984b58deaf32fc8a4577a9bbc0850cf92c20e1ce41c38c19e5fb75
239+
setuptools==70.0.0 \
240+
--hash=sha256:54faa7f2e8d2d11bcd2c07bed282eef1046b5c080d1c32add737d7b5817b1ad4 \
241+
--hash=sha256:f211a66637b8fa059bb28183da127d4e86396c991a942b028c6650d4319c3fd0
242242
# via yamllint

python/private/stage1_bootstrap_template.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ PYTHON_BINARY='%python_binary%'
1616
IS_ZIPFILE="%is_zipfile%"
1717

1818
if [[ "$IS_ZIPFILE" == "1" ]]; then
19-
zip_dir=$(mktemp -d --suffix Bazel.runfiles_)
19+
# NOTE: Macs have an old version of mktemp, so we must use only the
20+
# minimal functionality of it.
21+
zip_dir=$(mktemp -d)
2022

2123
if [[ -n "$zip_dir" && -z "${RULES_PYTHON_BOOTSTRAP_VERBOSE:-}" ]]; then
2224
trap 'rm -fr "$zip_dir"' EXIT
@@ -27,7 +29,7 @@ if [[ "$IS_ZIPFILE" == "1" ]]; then
2729
# The alternative requires having to copy ourselves elsewhere with the prelude
2830
# stripped (because zip can't extract from a stream). We avoid that because
2931
# it's wasteful.
30-
( unzip -q -d "$zip_dir" "$0" 2>/dev/null || /bin/true )
32+
( unzip -q -d "$zip_dir" "$0" 2>/dev/null || true )
3133

3234
RUNFILES_DIR="$zip_dir/runfiles"
3335
if [[ ! -d "$RUNFILES_DIR" ]]; then
@@ -105,6 +107,11 @@ declare -a interpreter_args
105107
# NOTE: Only works for 3.11+
106108
interpreter_env+=("PYTHONSAFEPATH=1")
107109

110+
if [[ "$IS_ZIPFILE" == "1" ]]; then
111+
interpreter_args+=("-XRULES_PYTHON_ZIP_DIR=$zip_dir")
112+
fi
113+
114+
108115
export RUNFILES_DIR
109116

110117
command=(

python/uv/private/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ bzl_library(
3636
name = "toolchains_repo",
3737
srcs = ["toolchains_repo.bzl"],
3838
visibility = ["//python/uv:__subpackages__"],
39+
deps = [
40+
"//python/private:text_util_bzl",
41+
],
3942
)
4043

4144
bzl_library(

python/uv/private/toolchains_repo.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"Creates a repository to hold toolchains"
1616

17+
load("//python/private:text_util.bzl", "render")
18+
1719
_TOOLCHAIN_TEMPLATE = """
1820
toolchain(
1921
name = "{name}",
@@ -33,7 +35,7 @@ def _toolchains_repo_impl(repository_ctx):
3335
name = toolchain_name,
3436
toolchain_type = repository_ctx.attr.toolchain_type,
3537
toolchain_label = toolchain_label,
36-
compatible_with = json.encode(toolchain_compatible_with),
38+
compatible_with = render.list(toolchain_compatible_with),
3739
)
3840

3941
repository_ctx.file("BUILD.bazel", build_content)

python/uv/private/versions.bzl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,49 @@
1616

1717
UV_PLATFORMS = {
1818
"aarch64-apple-darwin": struct(
19-
default_repo_name = "rules_python_uv_darwin_aarch64",
19+
default_repo_name = "uv_darwin_aarch64",
2020
compatible_with = [
2121
"@platforms//os:macos",
2222
"@platforms//cpu:aarch64",
2323
],
2424
),
2525
"aarch64-unknown-linux-gnu": struct(
26-
default_repo_name = "rules_python_uv_linux_aarch64",
26+
default_repo_name = "uv_linux_aarch64",
2727
compatible_with = [
2828
"@platforms//os:linux",
2929
"@platforms//cpu:aarch64",
3030
],
3131
),
3232
"powerpc64le-unknown-linux-gnu": struct(
33-
default_repo_name = "rules_python_uv_linux_ppc",
33+
default_repo_name = "uv_linux_ppc",
3434
compatible_with = [
3535
"@platforms//os:linux",
3636
"@platforms//cpu:ppc",
3737
],
3838
),
3939
"s390x-unknown-linux-gnu": struct(
40-
default_repo_name = "rules_python_uv_linux_s390x",
40+
default_repo_name = "uv_linux_s390x",
4141
compatible_with = [
4242
"@platforms//os:linux",
4343
"@platforms//cpu:s390x",
4444
],
4545
),
4646
"x86_64-apple-darwin": struct(
47-
default_repo_name = "rules_python_uv_darwin_x86_64",
47+
default_repo_name = "uv_darwin_x86_64",
4848
compatible_with = [
4949
"@platforms//os:macos",
5050
"@platforms//cpu:x86_64",
5151
],
5252
),
5353
"x86_64-pc-windows-msvc": struct(
54-
default_repo_name = "rules_python_uv_windows_x86_64",
54+
default_repo_name = "uv_windows_x86_64",
5555
compatible_with = [
5656
"@platforms//os:windows",
5757
"@platforms//cpu:x86_64",
5858
],
5959
),
6060
"x86_64-unknown-linux-gnu": struct(
61-
default_repo_name = "rules_python_uv_linux_x86_64",
61+
default_repo_name = "uv_linux_x86_64",
6262
compatible_with = [
6363
"@platforms//os:linux",
6464
"@platforms//cpu:x86_64",

python/uv/repositories.bzl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ EXPERIMENTAL: This is experimental and may be removed without notice
1818
Create repositories for uv toolchain dependencies
1919
"""
2020

21-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
2221
load("//python/uv/private:toolchain_types.bzl", "UV_TOOLCHAIN_TYPE")
2322
load("//python/uv/private:toolchains_repo.bzl", "uv_toolchains_repo")
2423
load("//python/uv/private:versions.bzl", "UV_PLATFORMS", "UV_TOOL_VERSIONS")
@@ -98,8 +97,7 @@ def uv_register_toolchains(uv_version = None, register_toolchains = True):
9897
for platform in UV_PLATFORMS.keys():
9998
uv_repository_name = UV_PLATFORMS[platform].default_repo_name
10099

101-
maybe(
102-
uv_repository,
100+
uv_repository(
103101
name = uv_repository_name,
104102
uv_version = uv_version,
105103
platform = platform,

tests/base_rules/BUILD.bazel

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,43 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
16+
load("//tests/support:sh_py_run_test.bzl", "sh_py_run_test")
17+
18+
_SUPPORTS_BOOTSTRAP_SCRIPT = select({
19+
"@platforms//os:windows": ["@platforms//:incompatible"],
20+
"//conditions:default": [],
21+
}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"]
22+
23+
sh_py_run_test(
24+
name = "run_binary_zip_no_test",
25+
build_python_zip = "no",
26+
py_src = "bin.py",
27+
sh_src = "run_binary_zip_no_test.sh",
28+
)
29+
30+
sh_py_run_test(
31+
name = "run_binary_zip_yes_test",
32+
build_python_zip = "yes",
33+
py_src = "bin.py",
34+
sh_src = "run_binary_zip_yes_test.sh",
35+
)
36+
37+
sh_py_run_test(
38+
name = "run_binary_bootstrap_script_zip_yes_test",
39+
bootstrap_impl = "script",
40+
build_python_zip = "yes",
41+
py_src = "bin.py",
42+
sh_src = "run_binary_zip_yes_test.sh",
43+
target_compatible_with = _SUPPORTS_BOOTSTRAP_SCRIPT,
44+
)
45+
46+
sh_py_run_test(
47+
name = "run_binary_bootstrap_script_zip_no_test",
48+
bootstrap_impl = "script",
49+
build_python_zip = "no",
50+
py_src = "bin.py",
51+
sh_src = "run_binary_zip_no_test.sh",
52+
target_compatible_with = _SUPPORTS_BOOTSTRAP_SCRIPT,
53+
)

tests/base_rules/bin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
import sys
16+
17+
print("Hello")
18+
print(
19+
"RULES_PYTHON_ZIP_DIR:{}".format(sys._xoptions.get("RULES_PYTHON_ZIP_DIR", "UNSET"))
20+
)
21+
print("file:", __file__)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# --- begin runfiles.bash initialization v3 ---
16+
# Copy-pasted from the Bazel Bash runfiles library v3.
17+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
18+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
19+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
20+
source "$0.runfiles/$f" 2>/dev/null || \
21+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
22+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
23+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
24+
# --- end runfiles.bash initialization v3 ---
25+
set +e
26+
27+
bin=$(rlocation $BIN_RLOCATION)
28+
if [[ -z "$bin" ]]; then
29+
echo "Unable to locate test binary: $BIN_RLOCATION"
30+
exit 1
31+
fi
32+
actual=$($bin 2>&1)
33+
34+
# How we detect if a zip file was executed from depends on which bootstrap
35+
# is used.
36+
# bootstrap_impl=script outputs RULES_PYTHON_ZIP_DIR=<somepath>
37+
# bootstrap_impl=system_python outputs file:.*Bazel.runfiles
38+
expected_pattern="Hello"
39+
if ! (echo "$actual" | grep "$expected_pattern" ) >/dev/null; then
40+
echo "expected output to match: $expected_pattern"
41+
echo "but got:\n$actual"
42+
exit 1
43+
fi
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# --- begin runfiles.bash initialization v3 ---
16+
# Copy-pasted from the Bazel Bash runfiles library v3.
17+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
18+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
19+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
20+
source "$0.runfiles/$f" 2>/dev/null || \
21+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
22+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
23+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
24+
# --- end runfiles.bash initialization v3 ---
25+
set +e
26+
27+
bin=$(rlocation $BIN_RLOCATION)
28+
if [[ -z "$bin" ]]; then
29+
echo "Unable to locate test binary: $BIN_RLOCATION"
30+
exit 1
31+
fi
32+
actual=$($bin)
33+
34+
# How we detect if a zip file was executed from depends on which bootstrap
35+
# is used.
36+
# bootstrap_impl=script outputs RULES_PYTHON_ZIP_DIR:<somepath>
37+
# bootstrap_impl=system_python outputs file:.*Bazel.runfiles
38+
expected_pattern="RULES_PYTHON_ZIP_DIR:/\|file:.*Bazel.runfiles"
39+
if ! (echo "$actual" | grep "$expected_pattern" ) >/dev/null; then
40+
echo "expected output to match: $expected_pattern"
41+
echo "but got: $actual"
42+
exit 1
43+
fi
44+

tests/base_rules/run_zip_test.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# --- begin runfiles.bash initialization v3 ---
16+
# Copy-pasted from the Bazel Bash runfiles library v3.
17+
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
18+
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
19+
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
20+
source "$0.runfiles/$f" 2>/dev/null || \
21+
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
22+
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
23+
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
24+
# --- end runfiles.bash initialization v3 ---
25+
set +e
26+
27+
bin=$(rlocation _main/tests/base_rules/_run_zip_test_bin)
28+
if [[ -z "$bin" ]]; then
29+
echo "Unable to locate test binary"
30+
exit 1
31+
fi
32+
actual=$($bin)
33+
34+
if [[ ! "$actual" == RULES_PYTHON_ZIP_DIR=/* ]]; then
35+
echo "expected output: RULES_PYTHON_ZIP_DIR=<some path>"
36+
echo "but got: $actual"
37+
exit 1
38+
fi

0 commit comments

Comments
 (0)