|
23 | 23 | from typing import Union
|
24 | 24 | import warnings
|
25 | 25 |
|
| 26 | +from . import _project |
26 | 27 | from ._result import Result
|
27 | 28 |
|
28 | 29 |
|
@@ -155,15 +156,24 @@ def __repr__(self) -> str:
|
155 | 156 | class HookspecMarker:
|
156 | 157 | """Decorator for marking functions as hook specifications.
|
157 | 158 |
|
158 |
| - Instantiate it with a project_name to get a decorator. |
| 159 | + Instantiate it with a project_name or ProjectSpec to get a decorator. |
159 | 160 | Calling :meth:`PluginManager.add_hookspecs` later will discover all marked
|
160 | 161 | functions if the :class:`PluginManager` uses the same project name.
|
161 | 162 | """
|
162 | 163 |
|
163 |
| - __slots__ = ("project_name",) |
| 164 | + __slots__ = ("_project_spec",) |
164 | 165 |
|
165 |
| - def __init__(self, project_name: str) -> None: |
166 |
| - self.project_name: Final = project_name |
| 166 | + def __init__(self, project_name_or_spec: str | _project.ProjectSpec) -> None: |
| 167 | + self._project_spec: Final = ( |
| 168 | + _project.ProjectSpec(project_name_or_spec) |
| 169 | + if isinstance(project_name_or_spec, str) |
| 170 | + else project_name_or_spec |
| 171 | + ) |
| 172 | + |
| 173 | + @property |
| 174 | + def project_name(self) -> str: |
| 175 | + """The project name from the associated ProjectSpec.""" |
| 176 | + return self._project_spec.project_name |
167 | 177 |
|
168 | 178 | @overload
|
169 | 179 | def __call__(
|
@@ -242,15 +252,24 @@ def setattr_hookspec_opts(func: _F) -> _F:
|
242 | 252 | class HookimplMarker:
|
243 | 253 | """Decorator for marking functions as hook implementations.
|
244 | 254 |
|
245 |
| - Instantiate it with a ``project_name`` to get a decorator. |
| 255 | + Instantiate it with a ``project_name`` or ProjectSpec to get a decorator. |
246 | 256 | Calling :meth:`PluginManager.register` later will discover all marked
|
247 | 257 | functions if the :class:`PluginManager` uses the same project name.
|
248 | 258 | """
|
249 | 259 |
|
250 |
| - __slots__ = ("project_name",) |
| 260 | + __slots__ = ("_project_spec",) |
251 | 261 |
|
252 |
| - def __init__(self, project_name: str) -> None: |
253 |
| - self.project_name: Final = project_name |
| 262 | + def __init__(self, project_name_or_spec: str | _project.ProjectSpec) -> None: |
| 263 | + self._project_spec: Final = ( |
| 264 | + _project.ProjectSpec(project_name_or_spec) |
| 265 | + if isinstance(project_name_or_spec, str) |
| 266 | + else project_name_or_spec |
| 267 | + ) |
| 268 | + |
| 269 | + @property |
| 270 | + def project_name(self) -> str: |
| 271 | + """The project name from the associated ProjectSpec.""" |
| 272 | + return self._project_spec.project_name |
254 | 273 |
|
255 | 274 | @overload
|
256 | 275 | def __call__(
|
|
0 commit comments