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

Add direct_url.json content to distribution #429

Closed
wants to merge 3 commits into from
Closed
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
49 changes: 48 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import itertools
import posixpath
import collections
import json

from . import _adapters, _meta, _py39compat
from ._collections import FreezableDefaultDict, Pair
Expand All @@ -31,7 +32,8 @@
from importlib import import_module
from importlib.abc import MetaPathFinder
from itertools import starmap
from typing import Iterable, List, Mapping, Optional, Set, cast
from typing import Any, Dict, Iterable, List, Mapping, Optional, Set, cast


__all__ = [
'Distribution',
Expand Down Expand Up @@ -618,6 +620,51 @@ def url_req_space(req):
space = url_req_space(section.value)
yield section.value + space + quoted_marker(section.name)

class VCSInfo:
def __init__(self, data: Dict[str, Any]) -> None:
self.vcs: str = data["vcs"]
self.requested_revision: Optional[str] = data.get("requested_revision")
self.commit_id: str = data["commit_id"]
self.resolved_revision: Optional[str] = data.get("resolved_revision")
self.resolved_revision_type: Optional[str] = data.get(
"resolved_revision_type"
)
self.hash: Optional[str] = data.get("hash")

class ArchiveInfo:
def __init__(self, data: Dict[str, Any]) -> None:
self.hash: Optional[str] = data["hash"]

class DirInfo:
def __init__(self, data: Dict[str, Any]) -> None:
self.editable: bool = data.get("editable", False)

class Origin:
def __init__(self, direct_url: str) -> None:
parsed: Dict = json.loads(direct_url)
self.url: str = parsed["url"]
self.subdirectory: Optional[str] = parsed.get("subdirectory")
self.vcs_info = (
Distribution.VCSInfo(parsed["vcs_info"])
if "vcs_info" in parsed
else None
)
self.archive_info = (
Distribution.ArchiveInfo(parsed["archive_info"])
if "archive_info" in parsed
else None
)
self.dir_info = (
Distribution.DirInfo(parsed["dir_info"])
if "dir_info" in parsed
else None
)

@property
def origin(self) -> Optional[Origin]:
direct_url = self.read_text("direct_url.json")
return Distribution.Origin(direct_url) if direct_url else None


class DistributionFinder(MetaPathFinder):
"""
Expand Down