|
24 | 24 | from importlib import import_module |
25 | 25 | from importlib.abc import MetaPathFinder |
26 | 26 | from itertools import starmap |
27 | | -from typing import Any, List, TypeVar, Union |
| 27 | +from typing import Any, List, Optional, TypeVar, Union |
28 | 28 |
|
29 | 29 |
|
30 | 30 | __all__ = [ |
@@ -85,6 +85,8 @@ class EntryPoint( |
85 | 85 | following the attr, and following any extras. |
86 | 86 | """ |
87 | 87 |
|
| 88 | + dist: Optional['Distribution'] = None |
| 89 | + |
88 | 90 | def load(self): |
89 | 91 | """Load the entry point from its definition. If only a module |
90 | 92 | is indicated by the value, return that module. Otherwise, |
@@ -112,19 +114,27 @@ def extras(self): |
112 | 114 |
|
113 | 115 | @classmethod |
114 | 116 | def _from_config(cls, config): |
115 | | - return [ |
| 117 | + return ( |
116 | 118 | cls(name, value, group) |
117 | 119 | for group in config.sections() |
118 | 120 | for name, value in config.items(group) |
119 | | - ] |
| 121 | + ) |
120 | 122 |
|
121 | 123 | @classmethod |
122 | 124 | def _from_text(cls, text): |
123 | 125 | config = ConfigParser(delimiters='=') |
124 | 126 | # case sensitive: https://stackoverflow.com/q/1611799/812183 |
125 | 127 | config.optionxform = str |
126 | 128 | config.read_string(text) |
127 | | - return EntryPoint._from_config(config) |
| 129 | + return cls._from_config(config) |
| 130 | + |
| 131 | + @classmethod |
| 132 | + def _from_text_for(cls, text, dist): |
| 133 | + return (ep._for(dist) for ep in cls._from_text(text)) |
| 134 | + |
| 135 | + def _for(self, dist): |
| 136 | + self.dist = dist |
| 137 | + return self |
128 | 138 |
|
129 | 139 | def __iter__(self): |
130 | 140 | """ |
@@ -282,14 +292,19 @@ def metadata(self) -> PackageMetadata: |
282 | 292 | ) |
283 | 293 | return email.message_from_string(text) |
284 | 294 |
|
| 295 | + @property |
| 296 | + def name(self): |
| 297 | + """Return the 'Name' metadata for the distribution package.""" |
| 298 | + return self.metadata['Name'] |
| 299 | + |
285 | 300 | @property |
286 | 301 | def version(self): |
287 | 302 | """Return the 'Version' metadata for the distribution package.""" |
288 | 303 | return self.metadata['Version'] |
289 | 304 |
|
290 | 305 | @property |
291 | 306 | def entry_points(self): |
292 | | - return EntryPoint._from_text(self.read_text('entry_points.txt')) |
| 307 | + return list(EntryPoint._from_text_for(self.read_text('entry_points.txt'), self)) |
293 | 308 |
|
294 | 309 | @property |
295 | 310 | def files(self): |
|
0 commit comments