-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy path__init__.py
More file actions
43 lines (33 loc) · 1.28 KB
/
__init__.py
File metadata and controls
43 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import annotations
import importlib
import pkgutil
import warnings
from collections.abc import Iterable
from importlib import metadata
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Iterable
from commitizen.cz.base import BaseCommitizen
def discover_plugins(
path: Iterable[str] | None = None,
) -> dict[str, type[BaseCommitizen]]:
"""Discover commitizen plugins on the path
Args:
path (Path, optional): If provided, 'path' should be either None or a list of paths to look for
modules in. If path is None, all top-level modules on sys.path.. Defaults to None.
Returns:
Dict[str, Type[BaseCommitizen]]: Registry with found plugins
"""
for _, name, _ in pkgutil.iter_modules(path):
if name.startswith("cz_"):
mod = importlib.import_module(name)
if hasattr(mod, "discover_this"):
warnings.warn(
UserWarning(
f"Legacy plugin '{name}' has been ignored: please expose it the 'commitizen.plugin' entrypoint"
)
)
return {
ep.name: ep.load() for ep in metadata.entry_points(group="commitizen.plugin")
}
registry: dict[str, type[BaseCommitizen]] = discover_plugins()