-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid the deprecated JSON API (#6081)
Resolves #6076 I've taken the JSON version of the simple API and converted it into a `LinkSource` so that the package-finding logic in the `PyPiRepository` is very similar to - but annoyingly not quite the same as! - the `LegacyRepository`. I've also taken the opportunity to refactor the `LegacyRepository` ever so slightly to emphasise that similarity. I think I've probably fixed a small bug re caching and pre-releases: previously the processing for ignored pre-releases was skipped when reading from the cache. I believe this change will tend to be a modest performance hit. Eg consider a package like `cryptography`, for which there are maybe a couple of dozen downloads available at each release: to get the available versions we now have to iterate over each of those files and parse their names, rather than simply reading the answer. However if the API that poetry currently uses is truly deprecated I see little choice but to suck that up - or risk being in an awkward spot when it is turned off. cf #5970, but worse. Most of the changes are in the test fixtures: - unversioned fixtures were generated from the existing fixtures: I didn't want to download fresh data and start getting different answers than the tests were expecting - new versioned fixtures were downloaded fresh
- Loading branch information
Showing
44 changed files
with
4,276 additions
and
7,717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
from collections import defaultdict | ||
from typing import TYPE_CHECKING | ||
from typing import Any | ||
|
||
from poetry.core.packages.utils.link import Link | ||
|
||
from poetry.repositories.link_sources.base import LinkSource | ||
from poetry.utils._compat import cached_property | ||
|
||
|
||
if TYPE_CHECKING: | ||
from poetry.repositories.link_sources.base import LinkCache | ||
|
||
|
||
class SimpleJsonPage(LinkSource): | ||
"""Links as returned by PEP 691 compatible JSON-based Simple API.""" | ||
|
||
def __init__(self, url: str, content: dict[str, Any]) -> None: | ||
super().__init__(url=url) | ||
self.content = content | ||
|
||
@cached_property | ||
def _link_cache(self) -> LinkCache: | ||
links: LinkCache = defaultdict(lambda: defaultdict(list)) | ||
for file in self.content["files"]: | ||
url = file["url"] | ||
requires_python = file.get("requires-python") | ||
yanked = file.get("yanked", False) | ||
link = Link(url, requires_python=requires_python, yanked=yanked) | ||
|
||
if link.ext not in self.SUPPORTED_FORMATS: | ||
continue | ||
|
||
pkg = self.link_package_data(link) | ||
if pkg: | ||
links[pkg.name][pkg.version].append(link) | ||
|
||
return links |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.