Skip to content

Commit 99fa343

Browse files
author
Zoran Simic
committed
Do not consider optional sha checksum in url as basename, added test
1 parent 586c5b7 commit 99fa343

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/portable_python/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ def cfg_http_headers(self):
498498
for header_dict in config_http_headers:
499499
for key, value in header_dict.items():
500500
expanded_http_headers[os.path.expandvars(key)] = os.path.expandvars(value)
501+
501502
return expanded_http_headers
502503

503504
def cfg_url(self, version):
@@ -656,12 +657,13 @@ def compile(self):
656657

657658
# Some URL's may not end in file extension, such as with redirects.
658659
# Github releases asset endpoint is this way .../releases/assets/48151
659-
if not self.url.endswith((".zip", ".tar.gz")):
660+
661+
# Split on '#' for urls that include a checksum, such as #sha256=... fragment
662+
basename = runez.basename(self.url, extension_marker="#")
663+
if not basename.endswith((".zip", ".tar.gz")):
660664
suffix = self.src_suffix or ".tar.gz"
661-
basename = f"{self.m_name}-{self.version}.{suffix}"
662-
else:
663-
# Split on '#' for urls that include a checksum, such as #sha256=... fragment
664-
basename = runez.basename(self.url, extension_marker="#")
665+
suffix = ".%s" % (suffix.strip(".")) # Ensure it starts with a dot (in case config forgot leading dot)
666+
basename = f"{self.m_name}-{self.version}{suffix}"
665667

666668
path = self.setup.folders.sources / basename
667669
if not path.exists():

tests/sample-config1.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ cpython-pep668-externally-managed:
4040
4141
cpython-configure:
4242
- --enable-shared
43+
44+
# Exercise custom url
45+
bzip2-url: https://my-enterprise/.../assets/bzip2/123
46+
bzip2-version: 1.2.3
47+
bzip2-src-suffix: tar.gz # Forgot leading dot on purpose
48+
bzip2-http-headers:
49+
- Authorization: Bearer foo
50+
Accept: application/octet-stream

tests/test_setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ def test_config(cli):
99
with pytest.raises(runez.system.AbortException):
1010
PPG.config.parsed_yaml("a: b\ninvalid line", "testing")
1111

12+
# Exercise custom url in config
13+
cli.run("-ntmacos-arm64", "-c", cli.tests_path("sample-config1.yml"), "build", "3.9.7", "-mbzip2")
14+
assert cli.succeeded
15+
assert "Would download https://my-enterprise/.../assets/bzip2/123" in cli.logged
16+
assert "Would untar build/sources/bzip2-1.2.3.tar.gz -> build/components/bzip2" in cli.logged
17+
1218
cli.run("-ntmacos-arm64", "-c", cli.tests_path("sample-config1.yml"), "build", "3.9.7", "-mnone")
1319
assert cli.succeeded
20+
1421
assert " -mpip install --no-cache-dir --upgrade my-additional-package" in cli.logged
1522
assert "env MACOSX_DEPLOYMENT_TARGET=12" in cli.logged # Comes from more specific macos-arm64.yml
1623
assert " -> dist/cpython-3.9.7-macos-arm64.tar.xz" in cli.logged # Comes from macos.yml (not defined in macos-arm64.yml)

0 commit comments

Comments
 (0)