aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-01-19 14:42:56 -0500
committerJason R. Coombs <jaraco@jaraco.com>2020-01-19 14:44:50 -0500
commit7cfeee80514bbdcd91b5dfbb937a9848ba4b7cf3 (patch)
tree5287a8433b9aedef15ca87f618c0f616cd69d4a3
parent3463820b30f2b09fee9a5fe42f86f5fe53d7f185 (diff)
downloadexternal_python_setuptools-7cfeee80514bbdcd91b5dfbb937a9848ba4b7cf3.tar.gz
external_python_setuptools-7cfeee80514bbdcd91b5dfbb937a9848ba4b7cf3.tar.bz2
external_python_setuptools-7cfeee80514bbdcd91b5dfbb937a9848ba4b7cf3.zip
Extract 'find_spec' function to consolidate behavior. Ref #1905.
-rw-r--r--setuptools/_imp.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/setuptools/_imp.py b/setuptools/_imp.py
index 6ccec579..451e45a8 100644
--- a/setuptools/_imp.py
+++ b/setuptools/_imp.py
@@ -17,12 +17,18 @@ C_BUILTIN = 6
PY_FROZEN = 7
+def find_spec(module, paths):
+ finder = (
+ importlib.machinery.PathFinder().find_spec
+ if isinstance(paths, list) else
+ importlib.util.find_spec
+ )
+ return finder(module, paths)
+
+
def find_module(module, paths=None):
"""Just like 'imp.find_module()', but with package support"""
- if isinstance(paths, list):
- spec = importlib.machinery.PathFinder().find_spec(module, paths)
- else:
- spec = importlib.util.find_spec(module, paths)
+ spec = find_spec(module, paths)
if spec is None:
raise ImportError("Can't find %s" % module)
if not spec.has_location and hasattr(spec, 'submodule_search_locations'):
@@ -63,20 +69,14 @@ def find_module(module, paths=None):
def get_frozen_object(module, paths=None):
- if isinstance(paths, list):
- spec = importlib.machinery.PathFinder().find_spec(module, paths)
- else:
- spec = importlib.util.find_spec(module, paths)
+ spec = find_spec(module, paths)
if not spec:
raise ImportError("Can't find %s" % module)
return spec.loader.get_code(module)
def get_module(module, paths, info):
- if isinstance(paths, list):
- spec = importlib.machinery.PathFinder().find_spec(module, paths)
- else:
- spec = importlib.util.find_spec(module, paths)
+ spec = find_spec(module, paths)
if not spec:
raise ImportError("Can't find %s" % module)
return module_from_spec(spec)