Skip to content

Commit

Permalink
Initial commit for poc
Browse files Browse the repository at this point in the history
  • Loading branch information
rd4398 committed Oct 2, 2024
1 parent b815993 commit b780c80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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

0 comments on commit b780c80

Please sign in to comment.