From a7d234cc6afaee1ec6d389cf4499ebf36e8fa467 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 7 Jul 2024 06:54:37 +0100 Subject: [PATCH] remove SimpleRepositoryPage (#9166) fixes python-poetry#6885 --- src/poetry/repositories/legacy_repository.py | 6 +- src/poetry/repositories/link_sources/html.py | 7 -- .../repositories/single_page_repository.py | 6 +- tests/repositories/fixtures/legacy.py | 4 +- .../single-page/mmcv_torch_releases.html | 104 ++++++++++++++++++ tests/repositories/test_legacy_repository.py | 2 +- .../test_single_page_repository.py | 18 ++- 7 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 tests/repositories/fixtures/single-page/mmcv_torch_releases.html diff --git a/src/poetry/repositories/legacy_repository.py b/src/poetry/repositories/legacy_repository.py index a6edf66729c..8b1bcea8236 100644 --- a/src/poetry/repositories/legacy_repository.py +++ b/src/poetry/repositories/legacy_repository.py @@ -12,7 +12,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 from poetry.repositories.link_sources.html import SimpleRepositoryRootPage @@ -125,10 +125,10 @@ def _get_release_info( ), ) - def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage: + def _get_page(self, name: NormalizedName) -> HTMLPage: if not (response := self._get_response(f"/{name}/")): raise PackageNotFound(f"Package [{name}] not found.") - return SimpleRepositoryPage(response.url, response.text) + return HTMLPage(response.url, response.text) @cached_property def root_page(self) -> SimpleRepositoryRootPage: diff --git a/src/poetry/repositories/link_sources/html.py b/src/poetry/repositories/link_sources/html.py index 3128b15fa1b..6b849e4e4cb 100644 --- a/src/poetry/repositories/link_sources/html.py +++ b/src/poetry/repositories/link_sources/html.py @@ -100,10 +100,3 @@ def package_names(self) -> list[str]: results.append(href.rstrip("/")) return results - - -class SimpleRepositoryPage(HTMLPage): - def __init__(self, url: str, content: str) -> None: - if not url.endswith("/"): - url += "/" - super().__init__(url=url, content=content) diff --git a/src/poetry/repositories/single_page_repository.py b/src/poetry/repositories/single_page_repository.py index 7bdc469bbf0..446957f12db 100644 --- a/src/poetry/repositories/single_page_repository.py +++ b/src/poetry/repositories/single_page_repository.py @@ -4,7 +4,7 @@ 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: @@ -12,11 +12,11 @@ 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) diff --git a/tests/repositories/fixtures/legacy.py b/tests/repositories/fixtures/legacy.py index 58f431b0268..57c06aee1cb 100644 --- a/tests/repositories/fixtures/legacy.py +++ b/tests/repositories/fixtures/legacy.py @@ -22,7 +22,7 @@ from packaging.utils import NormalizedName from pytest_mock import MockerFixture - from poetry.repositories.link_sources.html import SimpleRepositoryPage + from poetry.repositories.link_sources.html import HTMLPage from tests.types import HTTPrettyRequestCallback from tests.types import NormalizedNameTransformer from tests.types import SpecializedLegacyRepositoryMocker @@ -129,7 +129,7 @@ def mock( ) original_get_page = specialized_repository._get_page - def _mocked_get_page(name: NormalizedName) -> SimpleRepositoryPage: + def _mocked_get_page(name: NormalizedName) -> HTMLPage: return original_get_page( canonicalize_name(f"{name}{transformer_or_suffix}") if isinstance(transformer_or_suffix, str) diff --git a/tests/repositories/fixtures/single-page/mmcv_torch_releases.html b/tests/repositories/fixtures/single-page/mmcv_torch_releases.html new file mode 100644 index 00000000000..dff3ab240c3 --- /dev/null +++ b/tests/repositories/fixtures/single-page/mmcv_torch_releases.html @@ -0,0 +1,104 @@ +../torch1.12.0/mmcv-2.0.0-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc1-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc2-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc3-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.0rc4-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv-2.0.1-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.1-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv-2.0.1-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.1-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv-2.0.1-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.1-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv-2.0.1-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.0.1-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv-2.1.0-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.1.0-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv-2.1.0-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.1.0-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv-2.1.0-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.1.0-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv-2.1.0-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv-2.1.0-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.0-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.1-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.6.2-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.0-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.1-cp39-cp39-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp310-cp310-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp310-cp310-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp37-cp37m-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp37-cp37m-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp38-cp38-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp38-cp38-win_amd64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp39-cp39-manylinux1_x86_64.whl
+../torch1.12.0/mmcv_full-1.7.2-cp39-cp39-win_amd64.whl
diff --git a/tests/repositories/test_legacy_repository.py b/tests/repositories/test_legacy_repository.py index 0d9f304f7c1..f4d955fbae6 100644 --- a/tests/repositories/test_legacy_repository.py +++ b/tests/repositories/test_legacy_repository.py @@ -592,7 +592,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( diff --git a/tests/repositories/test_single_page_repository.py b/tests/repositories/test_single_page_repository.py index bbe3002c8e7..05789690874 100644 --- a/tests/repositories/test_single_page_repository.py +++ b/tests/repositories/test_single_page_repository.py @@ -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 @@ -22,18 +22,18 @@ class MockSinglePageRepository(SinglePageRepository): def __init__(self, page: str) -> None: super().__init__( "single-page", - url=f"http://single-page.foo.bar/{page}.html", + url=f"http://single-page.foo.bar/single/page/repo/{page}.html", disable_cache=True, ) 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 @@ -67,3 +67,13 @@ def test_single_page_repository_find_packages() -> None: package = packages[0] assert package.name == dep.name assert package.to_dependency().to_pep_508() == dep.to_pep_508() + + +def test_single_page_repository_get_page_with_relative_links() -> None: + repo = MockSinglePageRepository("mmcv_torch_releases") + + base_path = Path("/single/page/torch1.12.0") + page = repo.get_page("mmcv") + for link in page.links: + path = Path(link.path) + assert path.parent == base_path