1import abc
2import os
3import pathlib
4import sys
5from email.message import Message
6from importlib.abc import MetaPathFinder
7from pathlib import Path
8from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union, overload
9
10if sys.version_info >= (3, 8):
11    class PackageNotFoundError(ModuleNotFoundError): ...
12    class _EntryPointBase(NamedTuple):
13        name: str
14        value: str
15        group: str
16    class EntryPoint(_EntryPointBase):
17        def load(self) -> Any: ...  # Callable[[], Any] or an importable module
18        @property
19        def extras(self) -> List[str]: ...
20    class PackagePath(pathlib.PurePosixPath):
21        def read_text(self, encoding: str = ...) -> str: ...
22        def read_binary(self) -> bytes: ...
23        def locate(self) -> os.PathLike[str]: ...
24        # The following attributes are not defined on PackagePath, but are dynamically added by Distribution.files:
25        hash: Optional[FileHash]
26        size: Optional[int]
27        dist: Distribution
28    class FileHash:
29        mode: str
30        value: str
31        def __init__(self, spec: str) -> None: ...
32    class Distribution:
33        @abc.abstractmethod
34        def read_text(self, filename: str) -> Optional[str]: ...
35        @abc.abstractmethod
36        def locate_file(self, path: Union[os.PathLike[str], str]) -> os.PathLike[str]: ...
37        @classmethod
38        def from_name(cls, name: str) -> Distribution: ...
39        @overload
40        @classmethod
41        def discover(cls, *, context: DistributionFinder.Context) -> Iterable[Distribution]: ...
42        @overload
43        @classmethod
44        def discover(
45            cls, *, context: None = ..., name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any
46        ) -> Iterable[Distribution]: ...
47        @staticmethod
48        def at(path: Union[str, os.PathLike[str]]) -> PathDistribution: ...
49        @property
50        def metadata(self) -> Message: ...
51        @property
52        def version(self) -> str: ...
53        @property
54        def entry_points(self) -> List[EntryPoint]: ...
55        @property
56        def files(self) -> Optional[List[PackagePath]]: ...
57        @property
58        def requires(self) -> Optional[List[str]]: ...
59    class DistributionFinder(MetaPathFinder):
60        class Context:
61            name: Optional[str]
62            def __init__(self, *, name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any) -> None: ...
63            @property
64            def path(self) -> List[str]: ...
65        @abc.abstractmethod
66        def find_distributions(self, context: DistributionFinder.Context = ...) -> Iterable[Distribution]: ...
67    class MetadataPathFinder(DistributionFinder):
68        @classmethod
69        def find_distributions(cls, context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
70    class PathDistribution(Distribution):
71        def __init__(self, path: Path) -> None: ...
72        def read_text(self, filename: Union[str, os.PathLike[str]]) -> str: ...
73        def locate_file(self, path: Union[str, os.PathLike[str]]) -> os.PathLike[str]: ...
74    def distribution(distribution_name: str) -> Distribution: ...
75    @overload
76    def distributions(*, context: DistributionFinder.Context) -> Iterable[Distribution]: ...
77    @overload
78    def distributions(
79        *, context: None = ..., name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any
80    ) -> Iterable[Distribution]: ...
81    def metadata(distribution_name: str) -> Message: ...
82    def version(distribution_name: str) -> str: ...
83    def entry_points() -> Dict[str, Tuple[EntryPoint, ...]]: ...
84    def files(distribution_name: str) -> Optional[List[PackagePath]]: ...
85    def requires(distribution_name: str) -> Optional[List[str]]: ...
86