Skip to content

Commit 87906f0

Browse files
authored
fix: handle urls without release id format (#3306)
Sometimes when users customize the URLs for release, they use urls that don't have the same format the python-build-standalone URLs. Namely, they may not have the release_id component of the url. This would result in an error parsing such urls. To fix, refine the url parsing to check if a component is a valid numeric release id. Fixes #3285
1 parent c4935b1 commit 87906f0

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

python/versions.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,12 @@ def get_release_info(platform, python_version, base_url = DEFAULT_RELEASE_BASE_U
10451045
for u in url:
10461046
p, _, _ = platform.partition(FREETHREADED)
10471047

1048-
release_id = int(u.split("/")[-2])
1048+
# Assume an unknown release_id is a newer url format
1049+
release_id = 99999999
1050+
url_parts = u.split("/")
1051+
if len(url_parts) >= 2 and url_parts[-2].isdigit():
1052+
maybe_release_id = url_parts[-2]
1053+
release_id = int(maybe_release_id)
10491054

10501055
if FREETHREADED.lstrip("-") in platform:
10511056
build = "{}+{}-full".format(

tests/get_release_info/BUILD.bazel

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
load(":get_release_info_tests.bzl", "get_release_info_test_suite")
16+
17+
package(
18+
default_testonly = True,
19+
default_visibility = ["//:__subpackages__"],
20+
)
21+
22+
licenses(["notice"])
23+
24+
get_release_info_test_suite(name = "get_release_info")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
"""Tests for get_release_info."""
16+
17+
load("@rules_testing//lib:test_suite.bzl", "test_suite")
18+
load("//python:versions.bzl", "get_release_info") # buildifier: disable=bzl-visibility
19+
20+
_tests = []
21+
22+
def _test_file_url(env):
23+
"""Tests that a file:/// url is handled correctly."""
24+
tool_versions = {
25+
"3.11.5": {
26+
"sha256": {
27+
"x86_64-unknown-linux-gnu": "fbed6f7694b2faae5d7c401a856219c945397f772eea5ca50c6eb825cbc9d1e1",
28+
},
29+
"strip_prefix": "python",
30+
"url": "file:///tmp/cpython-3.11.5.tar.gz",
31+
},
32+
}
33+
34+
expected_url = "file:///tmp/cpython-3.11.5.tar.gz"
35+
expected_filename = "file:///tmp/cpython-3.11.5.tar.gz"
36+
37+
filename, urls, strip_prefix, patches, patch_strip = get_release_info(
38+
platform = "x86_64-unknown-linux-gnu",
39+
python_version = "3.11.5",
40+
tool_versions = tool_versions,
41+
)
42+
43+
env.expect.that_str(filename).equals(expected_filename)
44+
env.expect.that_collection(urls).contains_exactly([expected_url])
45+
env.expect.that_str(strip_prefix).equals("python")
46+
env.expect.that_collection(patches).has_size(0)
47+
env.expect.that_bool(patch_strip == None).equals(True)
48+
49+
_tests.append(_test_file_url)
50+
51+
def get_release_info_test_suite(name):
52+
"""Defines the test suite for get_release_info."""
53+
test_suite(
54+
name = name,
55+
basic_tests = _tests,
56+
)

0 commit comments

Comments
 (0)