use importlib instead of pkgutil

This commit is contained in:
David Lord 2023-06-07 13:07:41 -07:00
parent 367e1df785
commit 84e11a1e82
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
3 changed files with 7 additions and 4 deletions

View File

@ -3,6 +3,8 @@ Version 2.3.3
Unreleased
- Python 3.12 compatibility.
Version 2.3.2
-------------

View File

@ -1,7 +1,7 @@
from __future__ import annotations
import importlib.util
import os
import pkgutil
import socket
import sys
import typing as t
@ -575,7 +575,8 @@ def get_root_path(import_name: str) -> str:
return os.path.dirname(os.path.abspath(mod.__file__))
# Next attempt: check the loader.
loader = pkgutil.get_loader(import_name)
spec = importlib.util.find_spec(import_name)
loader = spec.loader if spec is not None else None
# Loader does not exist or we're referring to an unloaded main
# module or a main module without path (interactive sessions), go

View File

@ -3,7 +3,6 @@ from __future__ import annotations
import importlib.util
import os
import pathlib
import pkgutil
import sys
import typing as t
from collections import defaultdict
@ -856,7 +855,8 @@ def _find_package_path(import_name):
return os.path.dirname(root_spec.origin)
# we were unable to find the `package_path` using PEP 451 loaders
loader = pkgutil.get_loader(root_mod_name)
spec = importlib.util.find_spec(root_mod_name)
loader = spec.loader if spec is not None else None
if loader is None or root_mod_name == "__main__":
# import name is not found, or interactive/main module