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