Skip to content

Commit

Permalink
remove SimpleRepositoryPage
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Mar 16, 2024
1 parent 0b6b030 commit 78f4191
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from poetry.inspection.info import PackageInfo
from poetry.repositories.exceptions import PackageNotFound
from poetry.repositories.http_repository import HTTPRepository
from poetry.repositories.link_sources.html import SimpleRepositoryPage
from poetry.repositories.link_sources.html import HTMLPage


if TYPE_CHECKING:
Expand Down Expand Up @@ -134,8 +134,8 @@ def _get_release_info(
),
)

def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage:
def _get_page(self, name: NormalizedName) -> HTMLPage:
response = self._get_response(f"/{name}/")
if not response:
raise PackageNotFound(f"Package [{name}] not found.")
return SimpleRepositoryPage(response.url, response.text)
return HTMLPage(response.url, response.text)
7 changes: 0 additions & 7 deletions src/poetry/repositories/link_sources/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,3 @@ def _link_cache(self) -> LinkCache:
links[pkg.name][pkg.version].append(link)

return links


class SimpleRepositoryPage(HTMLPage):
def __init__(self, url: str, content: str) -> None:
if not url.endswith("/"):
url += "/"
super().__init__(url=url, content=content)
6 changes: 3 additions & 3 deletions src/poetry/repositories/single_page_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

from poetry.repositories.exceptions import PackageNotFound
from poetry.repositories.legacy_repository import LegacyRepository
from poetry.repositories.link_sources.html import SimpleRepositoryPage
from poetry.repositories.link_sources.html import HTMLPage


if TYPE_CHECKING:
from packaging.utils import NormalizedName


class SinglePageRepository(LegacyRepository):
def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage:
def _get_page(self, name: NormalizedName) -> HTMLPage:
"""
Single page repositories only have one page irrespective of endpoint.
"""
response = self._get_response("")
if not response:
raise PackageNotFound(f"Package [{name}] not found.")
return SimpleRepositoryPage(response.url, response.text)
return HTMLPage(response.url, response.text)
12 changes: 6 additions & 6 deletions tests/repositories/test_legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from poetry.repositories.exceptions import PackageNotFound
from poetry.repositories.exceptions import RepositoryError
from poetry.repositories.legacy_repository import LegacyRepository
from poetry.repositories.link_sources.html import SimpleRepositoryPage
from poetry.repositories.link_sources.html import HTMLPage


if TYPE_CHECKING:
Expand All @@ -45,13 +45,13 @@ def __init__(self) -> None:
super().__init__("legacy", url="http://legacy.foo.bar", disable_cache=True)
self._lazy_wheel = False

def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage:
def _get_page(self, name: NormalizedName) -> HTMLPage:
fixture = self.FIXTURES / (name + ".html")
if not fixture.exists():
raise PackageNotFound(f"Package [{name}] not found.")

with fixture.open(encoding="utf-8") as f:
return SimpleRepositoryPage(self._url + f"/{name}/", f.read())
return HTMLPage(self._url + f"/{name}/", f.read())

def _download(
self, url: str, dest: Path, *, raise_accepts_ranges: bool = False
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_page_invalid_version_link() -> None:

def test_page_filters_out_invalid_package_names() -> None:
class SpecialMockRepository(MockRepository):
def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage:
def _get_page(self, name: NormalizedName) -> HTMLPage:
return super()._get_page(canonicalize_name(f"{name}-with-extra-packages"))

repo = SpecialMockRepository()
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_package_yanked(

def test_package_partial_yank() -> None:
class SpecialMockRepository(MockRepository):
def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage:
def _get_page(self, name: NormalizedName) -> HTMLPage:
return super()._get_page(canonicalize_name(f"{name}-partial-yank"))

repo = MockRepository()
Expand Down Expand Up @@ -587,7 +587,7 @@ def get_mock(
monkeypatch.setattr(repo.session, "get", get_mock)
page = repo.get_page("foo")
assert page is not None
assert page._url == "http://legacy.redirect.bar/foo/"
assert page._url == "http://legacy.redirect.bar/foo"


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions tests/repositories/test_single_page_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from poetry.core.packages.dependency import Dependency

from poetry.repositories.exceptions import PackageNotFound
from poetry.repositories.link_sources.html import SimpleRepositoryPage
from poetry.repositories.link_sources.html import HTMLPage
from poetry.repositories.single_page_repository import SinglePageRepository


Expand All @@ -27,13 +27,13 @@ def __init__(self, page: str) -> None:
)
self._lazy_wheel = False

def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage:
def _get_page(self, name: NormalizedName) -> HTMLPage:
fixture = self.FIXTURES / self.url.rsplit("/", 1)[-1]
if not fixture.exists():
raise PackageNotFound(f"Package [{name}] not found.")

with fixture.open(encoding="utf-8") as f:
return SimpleRepositoryPage(self._url, f.read())
return HTMLPage(self._url, f.read())

def _download(
self, url: str, dest: Path, *, raise_accepts_ranges: bool = False
Expand Down

0 comments on commit 78f4191

Please sign in to comment.