ok, seems that import_dir is a bit saner

This commit is contained in:
Dima Gerasimov 2020-05-18 21:04:38 +01:00
parent 44aa062756
commit 0f80e9d5e6
3 changed files with 16 additions and 3 deletions

View file

@ -9,6 +9,7 @@ import warnings
# some helper functions
PathIsh = Union[Path, str]
# TODO only used in tests? not sure if useful at all.
# TODO port annotations to kython?..
def import_file(p: PathIsh, name: Optional[str]=None) -> types.ModuleType:
p = Path(p)
@ -33,6 +34,11 @@ def import_from(path: PathIsh, name: str) -> types.ModuleType:
sys.path.remove(path)
def import_dir(path: PathIsh) -> types.ModuleType:
p = Path(path)
return import_from(p.parent, p.name)
T = TypeVar('T')
K = TypeVar('K')
V = TypeVar('V')