1
+ from __future__ import annotations
2
+
1
3
import importlib
2
4
import pkgutil
3
5
import warnings
4
- from typing import Dict , Iterable , Type
6
+ from typing import Iterable , Optional
7
+
8
+ import importlib_metadata as metadata
5
9
6
10
from 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
10
11
11
12
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 ]]:
13
16
"""Discover commitizen plugins on the path
14
17
15
18
Args:
@@ -19,21 +22,19 @@ def discover_plugins(path: Iterable[str] = None) -> Dict[str, Type[BaseCommitize
19
22
Returns:
20
23
Dict[str, Type[BaseCommitizen]]: Registry with found plugins
21
24
"""
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