From 283b30a5c418a5bfe0313ed032c4c7d6eb2930ec Mon Sep 17 00:00:00 2001 From: Patrick Stevens Date: Sun, 2 Oct 2022 23:44:06 +0100 Subject: [PATCH] Allow legacy package indices to return absolute paths (#719) --- .gitignore | 2 ++ fetch_from_legacy.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e363fc8..306e7e6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ artifacts poetry2nix-flamegraph.svg .direnv flake.lock + +.idea/ diff --git a/fetch_from_legacy.py b/fetch_from_legacy.py index 8858b64..fee7374 100644 --- a/fetch_from_legacy.py +++ b/fetch_from_legacy.py @@ -80,14 +80,23 @@ if package_filename not in parser.sources: exit(1) package_file = open(package_filename, "wb") -# Sometimes the href is a relative path -if urlparse(parser.sources[package_filename]).netloc == "": +# Sometimes the href is a relative or absolute path within the index's domain. +indicated_url = urlparse(parser.sources[package_filename]) +if indicated_url.netloc == "": parsed_url = urlparse(index_url) + + if indicated_url.path.startswith("/"): + # An absolute path within the index's domain. + path = parser.sources[package_filename] + else: + # A relative path. + path = parsed_url.path + "/" + parser.sources[package_filename] + package_url = urlunparse( ( parsed_url.scheme, parsed_url.netloc, - parsed_url.path + "/" + parser.sources[package_filename], + path, None, None, None,