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