Skip to content

Commit

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


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

0 comments on commit c1bead1

Please sign in to comment.