Skip to content

Commit 6775b16

Browse files
author
jwiltse
committed
- Add condition for handling any source URL which redirects and doesn't end in .tar.gz or .zip, such as Github enterprise releases endpoint
- Move url and header env var expansion into cfg_http_headers cfg_url functions
1 parent 54e6449 commit 6775b16

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/portable_python/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,18 @@ def cfg_version(self, default):
494494

495495
def cfg_http_headers(self):
496496
if config_http_headers := PPG.config.get_value("%s-http-headers" % self.m_name):
497-
return config_http_headers
497+
expanded_http_headers = {}
498+
for header_dict in config_http_headers:
499+
for key, value in header_dict.items():
500+
expanded_http_headers[os.path.expandvars(key)] = os.path.expandvars(value)
501+
return expanded_http_headers
498502

499503
def cfg_url(self, version):
500504
if config_url := PPG.config.get_value("%s-url" % self.m_name):
501505
url_template = Template(config_url)
502-
return url_template.substitute(version=version)
506+
url_subbed = url_template.substitute(version=version)
507+
url_expanded = os.path.expandvars(url_subbed)
508+
return url_expanded
503509

504510
def cfg_configure(self, deps_lib_dir, deps_lib64_dir):
505511
if configure := PPG.config.get_value("%s-configure" % self.m_name):
@@ -636,8 +642,13 @@ def compile(self):
636642
self._finalize()
637643
return
638644

639-
# Split on '#' for urls that include a checksum, such as #sha256=... fragment
640-
basename = runez.basename(self.url, extension_marker="#")
645+
if ".tar.gz" not in self.url and ".zip" not in self.url:
646+
# TODO: add self.cfg_src_extension to remove assumption of .tar.gz
647+
basename = f"{self.m_name}-{self.version}.tar.gz"
648+
else:
649+
# Split on '#' for urls that include a checksum, such as #sha256=... fragment
650+
basename = runez.basename(self.url, extension_marker="#")
651+
641652
path = self.setup.folders.sources / basename
642653
if not path.exists():
643654
proxies = {}
@@ -648,13 +659,7 @@ def compile(self):
648659
if https_proxy:
649660
proxies["https"] = https_proxy
650661

651-
expanded_url = os.path.expandvars(self.url)
652-
expanded_http_headers = {}
653-
if headers := self.cfg_http_headers():
654-
for header_dict in headers:
655-
for key, value in header_dict.items():
656-
expanded_http_headers[os.path.expandvars(key)] = os.path.expandvars(value)
657-
RestClient().download(expanded_url, path, proxies=proxies, headers=expanded_http_headers)
662+
RestClient().download(self.url, path, proxies=proxies, headers=self.headers)
658663

659664
runez.decompress(path, self.m_src_build, simplify=True)
660665

0 commit comments

Comments
 (0)