Merge pull request #10186 from uranusjr/new-resolver-file-link-localhost

This commit is contained in:
Tzu-ping Chung 2021-07-23 17:01:28 +08:00 committed by GitHub
commit c5abdda6fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 0 deletions

2
news/10162.bugfix.rst Normal file
View File

@ -0,0 +1,2 @@
New resolver: URL comparison logic now treats ``file://localhost/`` and
``file:///`` as equivalent to conform to RFC 8089.

View File

@ -260,6 +260,9 @@ class _CleanResult(NamedTuple):
def from_link(cls, link: Link) -> "_CleanResult":
parsed = link._parsed_url
netloc = parsed.netloc.rsplit("@", 1)[-1]
# According to RFC 8089, an empty host in file: means localhost.
if parsed.scheme == "file" and not netloc:
netloc = "localhost"
fragment = urllib.parse.parse_qs(parsed.fragment)
if "egg" in fragment:
logger.debug("Ignoring egg= fragment in %s", link)

View File

@ -1,4 +1,5 @@
import os
import pathlib
import sys
import textwrap
@ -1962,3 +1963,49 @@ def test_new_resolver_transitively_depends_on_unnamed_local(script):
certbot_apache="99.99.0.dev0",
certbot_docs="1",
)
def _to_uri(path):
# Something like file:///path/to/package
return pathlib.Path(path).as_uri()
def _to_localhost_uri(path):
# Something like file://localhost/path/to/package
return pathlib.Path(path).as_uri().replace("///", "//localhost/")
@pytest.mark.parametrize(
"format_dep",
[
pytest.param(_to_uri, id="emptyhost"),
pytest.param(_to_localhost_uri, id="localhost"),
],
)
@pytest.mark.parametrize(
"format_input",
[
pytest.param(lambda path: path, id="path"),
pytest.param(_to_uri, id="emptyhost"),
pytest.param(_to_localhost_uri, id="localhost"),
],
)
def test_new_resolver_file_url_normalize(script, format_dep, format_input):
lib_a = create_test_package_with_setup(
script,
name="lib_a",
version="1",
)
lib_b = create_test_package_with_setup(
script,
name="lib_b",
version="1",
install_requires=[f"lib_a @ {format_dep(lib_a)}"],
)
script.pip(
"install",
"--no-cache-dir", "--no-index",
format_input(lib_a), lib_b,
)
script.assert_installed(lib_a="1", lib_b="1")