summaryrefslogtreecommitdiff
path: root/astroid/modutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'astroid/modutils.py')
-rw-r--r--astroid/modutils.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/astroid/modutils.py b/astroid/modutils.py
index 24c72e6a..31aa7d2a 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -38,6 +38,7 @@ try:
import pkg_resources
except ImportError:
pkg_resources = None
+import six
ModuleType = enum.Enum('ModuleType', 'C_BUILTIN C_EXTENSION PKG_DIRECTORY '
'PY_CODERESOURCE PY_COMPILED PY_FROZEN PY_RESOURCE '
@@ -134,6 +135,10 @@ def _normalize_path(path):
return os.path.normcase(os.path.abspath(path))
+def _canonicalize_path(path):
+ return os.path.realpath(os.path.expanduser(path))
+
+
def _path_from_filename(filename, is_jython=IS_JYTHON):
if not is_jython:
if sys.version_info > (3, 0):
@@ -301,19 +306,21 @@ def modpath_from_file_with_callback(filename, extrapath=None, is_package_cb=None
base = os.path.splitext(filename)[0]
if extrapath is not None:
- for path_ in extrapath:
+ for path_ in six.moves.map(_canonicalize_path, extrapath):
path = os.path.abspath(path_)
if path and os.path.normcase(base[:len(path)]) == os.path.normcase(path):
submodpath = [pkg for pkg in base[len(path):].split(os.sep)
if pkg]
if is_package_cb(path, submodpath[:-1]):
return extrapath[path_].split('.') + submodpath
- for path in sys.path:
+
+ for path in six.moves.map(_canonicalize_path, sys.path):
path = _cache_normalize_path(path)
if path and os.path.normcase(base).startswith(path):
modpath = [pkg for pkg in base[len(path):].split(os.sep) if pkg]
if is_package_cb(path, modpath[:-1]):
return modpath
+
raise ImportError('Unable to find module for %s in %s' % (
filename, ', \n'.join(sys.path)))