Skip to content

Commit

Permalink
fix: Allow using local file:// locations with find_links and index_ur…
Browse files Browse the repository at this point in the history
…ls (#132)
  • Loading branch information
frostming authored Jul 10, 2024
1 parent c113b18 commit a941242
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
9 changes: 7 additions & 2 deletions src/unearth/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,14 @@ def collect_links_from_location(
index_html = Link(path_to_url(path.joinpath("index.html").as_posix()))
yield from _collect_links_from_index(session, index_html, headers)
else:
yield from _collect_links_from_index(session, location, headers)
if _is_html_file(str(path)):
yield from _collect_links_from_index(session, location, headers)
else:
yield location

else:
else: # remote url, can be either a remote file or an index URL containing files
if is_secure_origin(session, location) and not location.is_vcs:
yield location
yield from _collect_links_from_index(session, location)


Expand Down
7 changes: 3 additions & 4 deletions src/unearth/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import itertools
import os
import pathlib
import posixpath
import warnings
from datetime import datetime
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Any, Iterable, NamedTuple, Sequence
from urllib.parse import urljoin

import packaging.requirements
from packaging.utils import BuildTag, canonicalize_name, parse_wheel_filename
Expand Down Expand Up @@ -190,9 +190,8 @@ def build_evaluator(
)

def _build_index_page_link(self, index_url: str, package_name: str) -> Link:
return Link(
urljoin(index_url.rstrip("/") + "/", canonicalize_name(package_name) + "/")
)
url = posixpath.join(index_url, canonicalize_name(package_name)) + "/"
return self._build_find_link(url)

def _build_find_link(self, find_link: str) -> Link:
if os.path.exists(find_link):
Expand Down
21 changes: 7 additions & 14 deletions tests/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,15 @@ def test_collector_skip_vcs_link(pypi_session, caplog):


def test_collect_links_from_404_page(pypi_session):
collected = list(
collect_links_from_location(
pypi_session, Link("https://test.pypi.org/simple/not-found")
)
)
assert not collected
link = Link("https://test.pypi.org/simple/not-found")
collected = list(collect_links_from_location(pypi_session, link))
assert collected == [link]


def test_skip_non_html_archive(pypi_session, caplog):
collected = list(
collect_links_from_location(
pypi_session,
Link("https://test.pypi.org/files/click-8.1.3-py3-none-any.whl"),
)
)
assert not collected
link = Link("https://test.pypi.org/files/click-8.1.3-py3-none-any.whl")
collected = list(collect_links_from_location(pypi_session, link))
assert collected == [link]
assert "Content-Type unsupported" in caplog.records[0].message


Expand All @@ -52,7 +45,7 @@ def test_collect_links_from_index_page(pypi_session):
),
key=lambda link: link.filename,
)
assert len(collected) == 4
assert len(collected) == 5
assert all(link.url.startswith("https://test.pypi.org") for link in collected)


Expand Down

0 comments on commit a941242

Please sign in to comment.