-
-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathplugins.py
More file actions
36 lines (28 loc) · 1.24 KB
/
plugins.py
File metadata and controls
36 lines (28 loc) · 1.24 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
from typing import Dict, List, Union
import pluggy
import sys
from . import hookspecs
pm: pluggy.PluginManager = pluggy.PluginManager("sqlite_utils")
pm.add_hookspecs(hookspecs)
def _should_load_setuptools_plugins() -> bool:
# Avoid loading setuptools plugins while running test suites.
# Checking sys.modules for pytest makes this robust even if
# sys._called_from_test is set later during test initialization.
return not getattr(sys, "_called_from_test", False) and "pytest" not in sys.modules
if _should_load_setuptools_plugins():
pm.load_setuptools_entrypoints("sqlite_utils")
def get_plugins() -> List[Dict[str, Union[str, List[str]]]]:
plugins: List[Dict[str, Union[str, List[str]]]] = []
plugin_to_distinfo = dict(pm.list_plugin_distinfo())
for plugin in pm.get_plugins():
hookcallers = pm.get_hookcallers(plugin) or []
plugin_info: Dict[str, Union[str, List[str]]] = {
"name": plugin.__name__,
"hooks": [h.name for h in hookcallers],
}
distinfo = plugin_to_distinfo.get(plugin)
if distinfo:
plugin_info["version"] = distinfo.version
plugin_info["name"] = distinfo.project_name
plugins.append(plugin_info)
return plugins