pytorch/tools/shared/module_loader.py
chronos_secgrp_pytorch_oss_ci_oncall 0328afd12e 2022-05-05 nightly release (4baf7c0899)
2022-05-05 00:02:34 -07:00

13 lines
379 B
Python

from importlib.abc import Loader
from types import ModuleType
from typing import cast
def import_module(name: str, path: str) -> ModuleType:
import importlib.util
spec = importlib.util.spec_from_file_location(name, path)
assert spec is not None
module = importlib.util.module_from_spec(spec)
cast(Loader, spec.loader).exec_module(module)
return module