summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-04-03 15:31:49 +0200
committerRonny Pfannschmidt <opensource@ronnypfannschmidt.de>2023-04-03 15:31:49 +0200
commitc74126382c636f364382508d97cf43c1df58b347 (patch)
tree8c441452393ebf2f040441b542ce27cd482dcc2d
parentaa76572cb34cc5169002bd942ec25bbd7a57876a (diff)
downloadsetuptools-scm-c74126382c636f364382508d97cf43c1df58b347.tar.gz
chore: drop unused code from _types
* migrates entrypoint protocol to entrypoints * drops global paramspecs
-rw-r--r--src/setuptools_scm/_entrypoints.py70
-rw-r--r--src/setuptools_scm/_types.py29
-rw-r--r--src/setuptools_scm/discover.py3
-rw-r--r--src/setuptools_scm/version.py9
4 files changed, 41 insertions, 70 deletions
diff --git a/src/setuptools_scm/_entrypoints.py b/src/setuptools_scm/_entrypoints.py
index e353260..01b48b1 100644
--- a/src/setuptools_scm/_entrypoints.py
+++ b/src/setuptools_scm/_entrypoints.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import warnings
from typing import Any
from typing import Callable
from typing import cast
@@ -8,23 +7,26 @@ from typing import Iterator
from typing import overload
from typing import TYPE_CHECKING
+from typing_extensions import Protocol
+
from . import _log
from . import version
if TYPE_CHECKING:
from ._config import Configuration
- from typing_extensions import Protocol
from . import _types as _t
-else:
- Configuration = Any
-
- class Protocol:
- pass
log = _log.log.getChild("entrypoints")
+class EntrypointProtocol(Protocol):
+ name: str
+
+ def load(self) -> Any:
+ pass
+
+
def _version_from_entrypoints(
config: Configuration, fallback: bool = False
) -> version.ScmVersion | None:
@@ -48,38 +50,25 @@ def _version_from_entrypoints(
try:
- from importlib.metadata import entry_points # type: ignore
- from importlib.metadata import EntryPoint
+ from importlib_metadata import entry_points
+ from importlib_metadata import EntryPoint
except ImportError:
- try:
- from importlib_metadata import entry_points
- from importlib_metadata import EntryPoint
- except ImportError:
- from collections import defaultdict
-
- def entry_points() -> dict[str, list[_t.EntrypointProtocol]]:
- warnings.warn(
- "importlib metadata missing, "
- "this may happen at build time for python3.7"
- )
- return defaultdict(list)
-
- class EntryPoint: # type: ignore
- def __init__(self, *args: Any, **kwargs: Any):
- pass # entry_points() already provides the warning
+ from importlib.metadata import entry_points # type: ignore [no-redef, import]
+ from importlib.metadata import EntryPoint # type: ignore [no-redef]
def iter_entry_points(
group: str, name: str | None = None
-) -> Iterator[_t.EntrypointProtocol]:
- all_eps = entry_points()
- if hasattr(all_eps, "select"):
- eps = all_eps.select(group=group)
- else:
- eps = all_eps[group]
- if name is None:
- return iter(eps)
- return (ep for ep in eps if ep.name == name)
+) -> Iterator[EntrypointProtocol]:
+ eps = entry_points(group=group)
+ res = (
+ eps
+ if name is None
+ else eps.select( # type: ignore [no-untyped-call]
+ name=name,
+ )
+ )
+ return cast(Iterator[EntrypointProtocol], iter(res))
def _get_ep(group: str, name: str) -> Any | None:
@@ -91,8 +80,11 @@ def _get_ep(group: str, name: str) -> Any | None:
def _get_from_object_reference_str(path: str) -> Any | None:
+ ep: EntrypointProtocol = EntryPoint(
+ path, path, None
+ ) # type: ignore [no-untyped-call]
try:
- return EntryPoint(path, path, None).load()
+ return ep.load()
except (AttributeError, ModuleNotFoundError):
return None
@@ -122,22 +114,22 @@ def _iter_version_schemes(
@overload
def _call_version_scheme(
- version: version.ScmVersion, entypoint: str, given_value: str, default: str
+ version: version.ScmVersion, entrypoint: str, given_value: str, default: str
) -> str:
...
@overload
def _call_version_scheme(
- version: version.ScmVersion, entypoint: str, given_value: str, default: None
+ version: version.ScmVersion, entrypoint: str, given_value: str, default: None
) -> str | None:
...
def _call_version_scheme(
- version: version.ScmVersion, entypoint: str, given_value: str, default: str | None
+ version: version.ScmVersion, entrypoint: str, given_value: str, default: str | None
) -> str | None:
- for scheme in _iter_version_schemes(entypoint, given_value):
+ for scheme in _iter_version_schemes(entrypoint, given_value):
result = scheme(version)
if result is not None:
return result
diff --git a/src/setuptools_scm/_types.py b/src/setuptools_scm/_types.py
index 7cd57a1..fdcd2dd 100644
--- a/src/setuptools_scm/_types.py
+++ b/src/setuptools_scm/_types.py
@@ -1,19 +1,17 @@
from __future__ import annotations
import os
-from typing import Any
from typing import Callable
from typing import List
from typing import Sequence
from typing import Tuple
-from typing import TypeVar
+from typing import TYPE_CHECKING
from typing import Union
-from typing_extensions import ParamSpec
-from typing_extensions import Protocol
from typing_extensions import TypeAlias
-from . import version
+if TYPE_CHECKING:
+ from . import version
PathT: TypeAlias = Union["os.PathLike[str]", str]
@@ -22,24 +20,3 @@ CMD_TYPE: TypeAlias = Union[Sequence[PathT], str]
VERSION_SCHEME: TypeAlias = Union[str, Callable[["version.ScmVersion"], str]]
VERSION_SCHEMES: TypeAlias = Union[List[str], Tuple[str, ...], VERSION_SCHEME]
SCMVERSION: TypeAlias = "version.ScmVersion"
-
-
-class EntrypointProtocol(Protocol):
- name: str
-
- def load(self) -> Any:
- pass
-
-
-T = TypeVar("T")
-T2 = TypeVar("T2")
-P = ParamSpec("P")
-
-
-def transfer_input_args(
- template: Callable[P, T],
-) -> Callable[[Callable[..., T]], Callable[P, T]]:
- def decorate(func: Callable[..., T2]) -> Callable[P, T2]:
- return func
-
- return decorate
diff --git a/src/setuptools_scm/discover.py b/src/setuptools_scm/discover.py
index d0655bb..85dd31f 100644
--- a/src/setuptools_scm/discover.py
+++ b/src/setuptools_scm/discover.py
@@ -5,6 +5,7 @@ from pathlib import Path
from typing import Iterable
from typing import Iterator
+from . import _entrypoints
from . import _log
from . import _types as _t
from ._config import Configuration
@@ -42,7 +43,7 @@ def match_entrypoint(root: _t.PathT, name: str) -> bool:
def iter_matching_entrypoints(
root: _t.PathT, entrypoint: str, config: Configuration
-) -> Iterable[_t.EntrypointProtocol]:
+) -> Iterable[_entrypoints.EntrypointProtocol]:
"""
Consider different entry-points in ``root`` and optionally its parents.
:param root: File path.
diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py
index f077280..a164849 100644
--- a/src/setuptools_scm/version.py
+++ b/src/setuptools_scm/version.py
@@ -22,8 +22,9 @@ from ._modify_version import _strip_local
if TYPE_CHECKING:
from typing_extensions import Concatenate
+ from typing_extensions import ParamSpec
- from . import _types as _t
+ _P = ParamSpec("_P")
from ._version_cls import Version as PkgVersion, _VersionT
@@ -156,10 +157,10 @@ class ScmVersion:
def format_next_version(
self,
- guess_next: Callable[Concatenate[ScmVersion, _t.P], str],
+ guess_next: Callable[Concatenate[ScmVersion, _P], str],
fmt: str = "{guessed}.dev{distance}",
- *k: _t.P.args,
- **kw: _t.P.kwargs,
+ *k: _P.args,
+ **kw: _P.kwargs,
) -> str:
guessed = guess_next(self, *k, **kw)
return self.format_with(fmt, guessed=guessed)