diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-06-01 17:16:55 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-06-01 17:16:55 +0100 |
commit | 788bb41c9eb1078237724933e3d33ca98419c41f (patch) | |
tree | 6fef9d26adb7a70b091f532f3a21147f2eafa263 /astroid/modutils.py | |
parent | 54fb1ab7d57a4100f147b69fb04d846cd68de909 (diff) | |
download | astroid-git-788bb41c9eb1078237724933e3d33ca98419c41f.tar.gz |
Try to canonicalize the lookup paths as well.
Diffstat (limited to 'astroid/modutils.py')
-rw-r--r-- | astroid/modutils.py | 11 |
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))) |