Skip to content

Commit e2b0e1f

Browse files
committed
keep the compatibility with py2.7. pass tests
1 parent 9c0a2fb commit e2b0e1f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pyhocon/config_parser.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ def glob(pathname, recursive=False):
6868
if sys.version_info >= (3, 4):
6969
import importlib.util
7070

71-
def find_package_dir(name):
71+
def find_package_dirs(name):
7272
spec = importlib.util.find_spec(name)
7373
# When `imp.find_module()` cannot find a package it raises ImportError.
7474
# Here we should simulate it to keep the compatibility with older
7575
# versions.
7676
if not spec:
7777
raise ImportError('No module named {!r}'.format(name))
78-
return os.path.dirname(spec.origin)
78+
return spec.submodule_search_locations
7979
else:
8080
import imp
8181
import importlib
8282

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]]
8585

8686

8787
logger = logging.getLogger(__name__)
@@ -759,12 +759,11 @@ def resolve_package_path(cls, package_path):
759759
if ':' not in package_path:
760760
raise ValueError("Expected format is 'PACKAGE:PATH'")
761761
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
768767
raise ImportError("Can't find {path_relative} in package:{package_name}".format(
769768
path_relative=path_relative,
770769
package_name=package_name))

0 commit comments

Comments
 (0)