Allow legacy package indices to return absolute paths (#719)

This commit is contained in:
Patrick Stevens 2022-10-02 23:44:06 +01:00 committed by GitHub
parent 420107e7e7
commit 283b30a5c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ artifacts
poetry2nix-flamegraph.svg
.direnv
flake.lock
.idea/

View file

@ -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,