1
0
forked from VimPlug/jedi

Merge branch 'linter' of github.com:davidhalter/jedi into linter

This commit is contained in:
Dave Halter
2014-07-21 17:40:25 +02:00
14 changed files with 63 additions and 80 deletions
+25 -12
View File
@@ -15,6 +15,13 @@ from jedi.evaluate.helpers import FakeName
from . import fake
_sep = os.path.sep
if os.path.altsep is not None:
_sep += os.path.altsep
_path_re = re.compile('(?:\.[^{0}]+|[{0}]__init__\.py)$'.format(re.escape(_sep)))
del _sep
class CompiledObject(Base):
# comply with the parser
start_pos = 0, 0
@@ -220,21 +227,27 @@ def dotted_from_fs_path(fs_path, sys_path=None):
compares the path with sys.path and then returns the dotted_path. If the
path is not in the sys.path, just returns None.
"""
sep = os.path.sep
shortest = None
if sys_path is None:
sys_path = get_sys_path()
# prefer
# - UNIX
# /path/to/pythonX.Y/lib-dynload
# /path/to/pythonX.Y/site-packages
# - Windows
# C:\path\to\DLLs
# C:\path\to\Lib\site-packages
# over
# - UNIX
# /path/to/pythonX.Y
# - Windows
# C:\path\to\Lib
path = ''
for s in sys_path:
if fs_path.startswith(s):
path = fs_path[len(s):].strip(sep)
path = re.sub('\.[^%s]*|%s__init__.py$' % (sep, sep), '', path)
dotted = path.split(sep)
dotted = '.'.join(dotted)
# At this point dotted could be both `lib-dynload.datetime` and
# `datetime`. The shorter one is typically the module we want.
if shortest is None or len(shortest) > len(dotted):
shortest = dotted
return shortest
if (fs_path.startswith(s) and
len(path) < len(s)):
path = s
return _path_re.sub('', fs_path[len(path):].lstrip(os.path.sep)).replace(os.path.sep, '.')
def load_module(path, name):
+3 -2
View File
@@ -103,7 +103,8 @@ class ImportWrapper(pr.Base):
names += self._get_module_names([path])
if self._is_relative_import():
rel_path = self._importer.get_relative_path() + '/__init__.py'
rel_path = os.path.join(self._importer.get_relative_path(),
'__init__.py')
if os.path.exists(rel_path):
m = _load_module(rel_path)
names += m.get_defined_names()
@@ -459,7 +460,7 @@ class _Importer(object):
if is_package_directory or current_namespace[0]:
# is a directory module
if is_package_directory:
path += '/__init__.py'
path = os.path.join(path, '__init__.py')
with open(path, 'rb') as f:
source = f.read()
else: