1+ from __future__ import annotations
2+
13import importlib
24import pkgutil
35import warnings
4- from typing import Dict , Iterable , Type
6+ from typing import Iterable , Optional
7+
8+ import importlib_metadata as metadata
59
610from commitizen .cz .base import BaseCommitizen
7- from commitizen .cz .conventional_commits import ConventionalCommitsCz
8- from commitizen .cz .customize import CustomizeCommitsCz
9- from commitizen .cz .jira import JiraSmartCz
1011
1112
12- def discover_plugins (path : Iterable [str ] = None ) -> Dict [str , Type [BaseCommitizen ]]:
13+ def discover_plugins (
14+ path : Optional [Iterable [str ]] = None ,
15+ ) -> dict [str , type [BaseCommitizen ]]:
1316 """Discover commitizen plugins on the path
1417
1518 Args:
@@ -19,21 +22,19 @@ def discover_plugins(path: Iterable[str] = None) -> Dict[str, Type[BaseCommitize
1922 Returns:
2023 Dict[str, Type[BaseCommitizen]]: Registry with found plugins
2124 """
22- plugins = {}
23- for _finder , name , _ispkg in pkgutil .iter_modules (path ):
24- try :
25- if name .startswith ("cz_" ):
26- plugins [name ] = importlib .import_module (name ).discover_this
27- except AttributeError as e :
28- warnings .warn (UserWarning (e .args [0 ]))
29- continue
30- return plugins
31-
32-
33- registry : Dict [str , Type [BaseCommitizen ]] = {
34- "cz_conventional_commits" : ConventionalCommitsCz ,
35- "cz_jira" : JiraSmartCz ,
36- "cz_customize" : CustomizeCommitsCz ,
37- }
38-
39- registry .update (discover_plugins ())
25+ for _ , name , _ in pkgutil .iter_modules (path ):
26+ if name .startswith ("cz_" ):
27+ mod = importlib .import_module (name )
28+ if hasattr (mod , "discover_this" ):
29+ warnings .warn (
30+ UserWarning (
31+ f"Legacy plugin '{ name } ' has been ignored: please expose it the 'commitizen.plugin' entrypoint"
32+ )
33+ )
34+
35+ return {
36+ ep .name : ep .load () for ep in metadata .entry_points (group = "commitizen.plugin" )
37+ }
38+
39+
40+ registry : dict [str , type [BaseCommitizen ]] = discover_plugins ()
0 commit comments