@@ -68,20 +68,20 @@ def glob(pathname, recursive=False):
68
68
if sys .version_info >= (3 , 4 ):
69
69
import importlib .util
70
70
71
- def find_package_dir (name ):
71
+ def find_package_dirs (name ):
72
72
spec = importlib .util .find_spec (name )
73
73
# When `imp.find_module()` cannot find a package it raises ImportError.
74
74
# Here we should simulate it to keep the compatibility with older
75
75
# versions.
76
76
if not spec :
77
77
raise ImportError ('No module named {!r}' .format (name ))
78
- return os . path . dirname ( spec .origin )
78
+ return spec .submodule_search_locations
79
79
else :
80
80
import imp
81
81
import importlib
82
82
83
- def find_package_dir (name ):
84
- return imp .find_module (name )[1 ]
83
+ def find_package_dirs (name ):
84
+ return [ imp .find_module (name )[1 ] ]
85
85
86
86
87
87
logger = logging .getLogger (__name__ )
@@ -759,12 +759,11 @@ def resolve_package_path(cls, package_path):
759
759
if ':' not in package_path :
760
760
raise ValueError ("Expected format is 'PACKAGE:PATH'" )
761
761
package_name , path_relative = package_path .split (':' , 1 )
762
- spec = importlib .util .find_spec (package_name )
763
- if spec :
764
- for package_dir in spec .submodule_search_locations :
765
- path_abs = os .path .join (package_dir , path_relative )
766
- if os .path .exists (path_abs ):
767
- return path_abs
762
+ package_dirs = find_package_dirs (package_name )
763
+ for package_dir in package_dirs :
764
+ path_abs = os .path .join (package_dir , path_relative )
765
+ if os .path .exists (path_abs ):
766
+ return path_abs
768
767
raise ImportError ("Can't find {path_relative} in package:{package_name}" .format (
769
768
path_relative = path_relative ,
770
769
package_name = package_name ))
0 commit comments