forked from orbit-oss/flask
fix use of importlib.util.find_spec
This commit is contained in:
parent
c8cf4694c6
commit
bda295d37f
3 changed files with 40 additions and 82 deletions
|
|
@ -575,13 +575,20 @@ def get_root_path(import_name: str) -> str:
|
|||
return os.path.dirname(os.path.abspath(mod.__file__))
|
||||
|
||||
# Next attempt: check the loader.
|
||||
spec = importlib.util.find_spec(import_name)
|
||||
loader = spec.loader if spec is not None else None
|
||||
try:
|
||||
spec = importlib.util.find_spec(import_name)
|
||||
|
||||
if spec is None:
|
||||
raise ValueError
|
||||
except (ImportError, ValueError):
|
||||
loader = None
|
||||
else:
|
||||
loader = spec.loader
|
||||
|
||||
# Loader does not exist or we're referring to an unloaded main
|
||||
# module or a main module without path (interactive sessions), go
|
||||
# with the current working directory.
|
||||
if loader is None or import_name == "__main__":
|
||||
if loader is None:
|
||||
return os.getcwd()
|
||||
|
||||
if hasattr(loader, "get_filename"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue