1
+ from pip ._internal .utils .misc import stdlib_pkgs # TODO: Move definition here.
1
2
from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
2
3
3
4
if MYPY_CHECK_RUNNING :
4
- from typing import List , Optional
5
+ from typing import Container , Iterator , List , Optional
5
6
6
7
7
8
class BaseDistribution :
9
+ @property
10
+ def canonical_name (self ):
11
+ # type: () -> str
12
+ raise NotImplementedError ()
13
+
8
14
@property
9
15
def installer (self ):
10
16
# type: () -> str
11
17
raise NotImplementedError ()
12
18
19
+ @property
20
+ def editable (self ):
21
+ # type: () -> bool
22
+ raise NotImplementedError ()
23
+
24
+ @property
25
+ def local (self ):
26
+ # type: () -> bool
27
+ raise NotImplementedError ()
28
+
29
+ @property
30
+ def in_usersite (self ):
31
+ # type: () -> bool
32
+ raise NotImplementedError ()
33
+
13
34
14
35
class BaseEnvironment :
15
36
"""An environment containing distributions to introspect."""
@@ -27,3 +48,27 @@ def from_paths(cls, paths):
27
48
def get_distribution (self , name ):
28
49
# type: (str) -> Optional[BaseDistribution]
29
50
raise NotImplementedError ()
51
+
52
+ def iter_distributions (self ):
53
+ # type: () -> Iterator[BaseDistribution]
54
+ raise NotImplementedError ()
55
+
56
+ def iter_installed_distributions (
57
+ self ,
58
+ local_only = True , # type: bool
59
+ skip = stdlib_pkgs , # type: Container[str]
60
+ include_editables = True , # type: bool
61
+ editables_only = False , # type: bool
62
+ user_only = False , # type: bool
63
+ ):
64
+ # type: (...) -> Iterator[BaseDistribution]
65
+ it = self .iter_distributions ()
66
+ if local_only :
67
+ it = (d for d in it if d .local )
68
+ if not include_editables :
69
+ it = (d for d in it if not d .editable )
70
+ if editables_only :
71
+ it = (d for d in it if d .editable )
72
+ if user_only :
73
+ it = (d for d in it if d .in_usersite )
74
+ return (d for d in it if d .canonical_name not in skip )
0 commit comments