Files
pytorch/tools/shared/module_loader.py
Edward Z. Yang a11c1bbdd0 Run Black on all of tools/
Signed-off-by: Edward Z. Yang <ezyangfb.com>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76089

Approved by: https://github.com/albanD
2022-04-20 17:29:41 +00:00

13 lines
351 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)
module = importlib.util.module_from_spec(spec)
cast(Loader, spec.loader).exec_module(module)
return module