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]]: Reg
(
path: Iterable[str] | None = None,
)
| 14 | |
| 15 | |
| 16 | def discover_plugins( |
| 17 | path: Iterable[str] | None = None, |
| 18 | ) -> dict[str, type[BaseCommitizen]]: |
| 19 | """Discover commitizen plugins on the path |
| 20 | |
| 21 | Args: |
| 22 | path (Path, optional): If provided, 'path' should be either None or a list of paths to look for |
| 23 | modules in. If path is None, all top-level modules on sys.path.. Defaults to None. |
| 24 | |
| 25 | Returns: |
| 26 | Dict[str, Type[BaseCommitizen]]: Registry with found plugins |
| 27 | """ |
| 28 | for _, name, _ in pkgutil.iter_modules(path): |
| 29 | if name.startswith("cz_"): |
| 30 | mod = importlib.import_module(name) |
| 31 | if hasattr(mod, "discover_this"): |
| 32 | warnings.warn( |
| 33 | UserWarning( |
| 34 | f"Legacy plugin '{name}' has been ignored: please expose it the 'commitizen.plugin' entrypoint" |
| 35 | ) |
| 36 | ) |
| 37 | |
| 38 | return { |
| 39 | ep.name: ep.load() for ep in metadata.entry_points(group="commitizen.plugin") |
| 40 | } |
| 41 | |
| 42 | |
| 43 | registry: dict[str, type[BaseCommitizen]] = discover_plugins() |
no outgoing calls