|
26 | 26 | from importlib import import_module |
27 | 27 | from importlib.abc import MetaPathFinder |
28 | 28 | from itertools import starmap |
29 | | -from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast |
| 29 | +from typing import Any, Iterable, List, Mapping, Optional, Set, cast |
30 | 30 |
|
31 | 31 | from . import _meta |
32 | 32 | from ._collections import FreezableDefaultDict, Pair |
@@ -133,6 +133,12 @@ def valid(line: str): |
133 | 133 | return line and not line.startswith('#') |
134 | 134 |
|
135 | 135 |
|
| 136 | +class _EntryPointMatch(types.SimpleNamespace): |
| 137 | + module: str |
| 138 | + attr: str |
| 139 | + extras: str |
| 140 | + |
| 141 | + |
136 | 142 | class EntryPoint: |
137 | 143 | """An entry point as defined by Python packaging conventions. |
138 | 144 |
|
@@ -185,28 +191,27 @@ def load(self) -> Any: |
185 | 191 | is indicated by the value, return that module. Otherwise, |
186 | 192 | return the named object. |
187 | 193 | """ |
188 | | - match = cast(Match, self.pattern.match(self.value)) |
189 | | - module = import_module(match.group('module')) |
190 | | - attrs = filter(None, (match.group('attr') or '').split('.')) |
| 194 | + module = import_module(self.module) |
| 195 | + attrs = filter(None, (self.attr or '').split('.')) |
191 | 196 | return functools.reduce(getattr, attrs, module) |
192 | 197 |
|
193 | 198 | @property |
194 | 199 | def module(self) -> str: |
195 | | - match = self.pattern.match(self.value) |
196 | | - assert match is not None |
197 | | - return match.group('module') |
| 200 | + return self._match.module |
198 | 201 |
|
199 | 202 | @property |
200 | 203 | def attr(self) -> str: |
201 | | - match = self.pattern.match(self.value) |
202 | | - assert match is not None |
203 | | - return match.group('attr') |
| 204 | + return self._match.attr |
204 | 205 |
|
205 | 206 | @property |
206 | 207 | def extras(self) -> List[str]: |
| 208 | + return re.findall(r'\w+', self._match.extras or '') |
| 209 | + |
| 210 | + @property |
| 211 | + def _match(self) -> _EntryPointMatch: |
207 | 212 | match = self.pattern.match(self.value) |
208 | 213 | assert match is not None |
209 | | - return re.findall(r'\w+', match.group('extras') or '') |
| 214 | + return _EntryPointMatch(**match.groupdict()) |
210 | 215 |
|
211 | 216 | def _for(self, dist): |
212 | 217 | vars(self).update(dist=dist) |
|
0 commit comments