Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 658 Metadata download: Initial commit for poc #464

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ tomlkit
tqdm
virtualenv
wheel
mousebender
3 changes: 3 additions & 0 deletions src/fromager/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
name: str,
version: Version,
url: str,
metadata_hash: tuple[str, str] | None,
extras: typing.Iterable[str] | None = None,
is_sdist: bool | None = None,
build_tag: BuildTag = (),
Expand All @@ -35,9 +36,11 @@ def __init__(
self.extras = extras
self.is_sdist = is_sdist
self.build_tag = build_tag
self.metadata_hash = metadata_hash

self._metadata: Metadata | None = None
self._dependencies: list[Requirement] | None = None
self.metadata_url: str | None = None

def __repr__(self) -> str:
if not self.extras:
Expand Down
15 changes: 15 additions & 0 deletions src/fromager/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from operator import attrgetter
from platform import python_version
from urllib.parse import urljoin, urlparse
import mousebender

import github
import html5lib
Expand Down Expand Up @@ -105,7 +106,19 @@ def get_project_from_pypi(
simple_index_url = sdist_server_url.rstrip("/") + "/" + project + "/"
logger.debug("%s: getting available versions from %s", project, simple_index_url)
data = session.get(simple_index_url).content
metadata_response = session.get(simple_index_url, headers={"accept": mousebender.simple.ACCEPT_SUPPORTED})
doc = html5lib.parse(data, namespaceHTMLElements=False)
parsed_metadata_doc = mousebender.simple.parse_project_details(metadata_response.content, metadata_response.headers["content-type"], project)
files = parsed_metadata_doc["files"]

for dct in files:
if dct.get("yanked", False):
continue
hash_val = dct.get("data-dist-info-metadata")
if hash_val:
_metadata_hash = hash_val
_metadata_url = dct.get("url") + ".metadata"

for i in doc.findall(".//a"):
candidate_url = urljoin(simple_index_url, i.attrib["href"])
py_req = i.attrib.get("data-requires-python")
Expand Down Expand Up @@ -174,10 +187,12 @@ def get_project_from_pypi(
name,
version,
url=candidate_url,
metadata_hash=_metadata_hash,
extras=extras,
is_sdist=is_sdist,
build_tag=build_tag,
)
c.metadata_url = _metadata_url
if DEBUG_RESOLVER:
logger.debug(
"%s: candidate %s (%s) %s", project, filename, c, candidate_url
Expand Down
Loading