lib.init.detect_modules(): Renovate signature #1
6 changed files with 20 additions and 18 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
from ..lib.init import detect_modules
|
from ..lib.init import detect_modules
|
||||||
|
|
||||||
__all__ = detect_modules(
|
__all__ = detect_modules(
|
||||||
package_name = __name__,
|
|
||||||
package_path = __path__,
|
|
||||||
namespace = globals(),
|
namespace = globals(),
|
||||||
prefix = 'Cmd',
|
prefix = 'Cmd',
|
||||||
skip = {'Cmd'},
|
skip = {'Cmd'},
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
from ...lib.init import detect_modules
|
from ...lib.init import detect_modules
|
||||||
|
|
||||||
__all__ = detect_modules(
|
__all__ = detect_modules(
|
||||||
package_name = __name__,
|
|
||||||
package_path = __path__,
|
|
||||||
namespace = globals(),
|
namespace = globals(),
|
||||||
prefix = 'Cmd',
|
prefix = 'Cmd',
|
||||||
skip = {'Cmd'},
|
skip = {'Cmd'},
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
from ...lib.init import detect_modules
|
from ...lib.init import detect_modules
|
||||||
|
|
||||||
__all__ = detect_modules(
|
__all__ = detect_modules(
|
||||||
package_name = __name__,
|
|
||||||
package_path = __path__,
|
|
||||||
namespace = globals(),
|
namespace = globals(),
|
||||||
prefix = 'Cmd',
|
prefix = 'Cmd',
|
||||||
skip = {'Cmd'},
|
skip = {'Cmd'},
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
from ...lib.init import detect_modules
|
from ...lib.init import detect_modules
|
||||||
|
|
||||||
__all__ = detect_modules(
|
__all__ = detect_modules(
|
||||||
package_name = __name__,
|
|
||||||
package_path = __path__,
|
|
||||||
namespace = globals(),
|
namespace = globals(),
|
||||||
prefix = 'Cmd',
|
prefix = 'Cmd',
|
||||||
skip = {'Cmd'},
|
skip = {'Cmd'},
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
from ....lib.init import detect_modules
|
from ....lib.init import detect_modules
|
||||||
|
|
||||||
__all__ = detect_modules(
|
__all__ = detect_modules(
|
||||||
package_name = __name__,
|
|
||||||
package_path = __path__,
|
|
||||||
namespace = globals(),
|
namespace = globals(),
|
||||||
prefix = 'Cmd',
|
prefix = 'Cmd',
|
||||||
skip = {'Cmd'},
|
skip = {'Cmd'},
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,45 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pkgutil
|
||||||
|
from importlib import import_module
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import MutableMapping
|
from collections.abc import MutableMapping
|
||||||
from typing import Any, Iterable
|
from typing import Any
|
||||||
|
|
||||||
def detect_modules(
|
def detect_modules(
|
||||||
package_name: str,
|
|
||||||
package_path: Iterable[str],
|
|
||||||
namespace: MutableMapping[str, Any],
|
namespace: MutableMapping[str, Any],
|
||||||
prefix: str,
|
prefix: str | None = None,
|
||||||
skip: set[str] | None = None,
|
skip: set[str] | None = None,
|
||||||
|
*,
|
||||||
|
extend_namespace: bool = True,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
|
|
||||||
import importlib
|
package_name = namespace.get("__name__")
|
||||||
import pkgutil
|
package_path = namespace.get("__path__")
|
||||||
|
|
||||||
|
if not isinstance(package_name, str):
|
||||||
|
raise TypeError("namespace must contain string __name__")
|
||||||
|
|
||||||
|
if package_path is None:
|
||||||
|
raise TypeError("namespace must be a package namespace with __path__")
|
||||||
|
|
||||||
|
if extend_namespace:
|
||||||
|
package_path = pkgutil.extend_path(package_path, package_name)
|
||||||
|
namespace["__path__"] = package_path
|
||||||
|
|
||||||
ret: list[str] = []
|
ret: list[str] = []
|
||||||
skip = skip or set()
|
skip = skip or set()
|
||||||
|
|
||||||
for _finder, module_name, _ispkg in pkgutil.iter_modules(package_path):
|
for _finder, module_name, _ispkg in pkgutil.iter_modules(package_path):
|
||||||
if not module_name.startswith(prefix):
|
if prefix is not None and not module_name.startswith(prefix):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if module_name in skip:
|
if module_name in skip:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
module = importlib.import_module(f'.{module_name}', package_name)
|
module = import_module(f".{module_name}", package_name)
|
||||||
cls = getattr(module, module_name)
|
cls = getattr(module, module_name)
|
||||||
|
|
||||||
namespace[module_name] = cls
|
namespace[module_name] = cls
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue