Skip to content

Commit

Permalink
简化了 import_modules
Browse files Browse the repository at this point in the history
现在 `import_modules` 不需要指定 `prefix` 了
  • Loading branch information
carefree0910 committed Dec 26, 2023
1 parent c1bead1 commit e6accde
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cftool/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,14 @@ def get_err_msg(err: Exception) -> str:
return " | ".join(map(repr, sys.exc_info()[:2] + (str(err),)))


def import_modules(prefix: str) -> None:
def import_modules() -> None:
previous = inspect.stack()[1][0]
_globals = previous.f_globals
package = _globals["__package__"]
for path in Path(inspect.getfile(previous)).parent.glob("*.py"):
if path.stem == "__init__":
continue
module = importlib.import_module(f"{prefix}.{path.stem}")
module = importlib.import_module(f".{path.stem}", package)
if "__all__" in module.__dict__:
names = module.__dict__["__all__"]
else:
Expand Down

0 comments on commit e6accde

Please sign in to comment.