mirror of
https://github.com/davidhalter/jedi.git
synced 2026-03-07 00:31:52 +08:00
@@ -15,6 +15,13 @@ from jedi.evaluate.helpers import FakeName
|
|||||||
from . import fake
|
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):
|
class CompiledObject(Base):
|
||||||
# comply with the parser
|
# comply with the parser
|
||||||
start_pos = 0, 0
|
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
|
compares the path with sys.path and then returns the dotted_path. If the
|
||||||
path is not in the sys.path, just returns None.
|
path is not in the sys.path, just returns None.
|
||||||
"""
|
"""
|
||||||
sep = os.path.sep
|
|
||||||
shortest = None
|
|
||||||
if sys_path is None:
|
if sys_path is None:
|
||||||
sys_path = get_sys_path()
|
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:
|
for s in sys_path:
|
||||||
if fs_path.startswith(s):
|
if (fs_path.startswith(s) and
|
||||||
path = fs_path[len(s):].strip(sep)
|
len(path) < len(s)):
|
||||||
path = re.sub('\.[^%s]*|%s__init__.py$' % (sep, sep), '', path)
|
path = s
|
||||||
dotted = path.split(sep)
|
return _path_re.sub('', fs_path[len(path):].lstrip(os.path.sep)).replace(os.path.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
|
|
||||||
|
|
||||||
|
|
||||||
def load_module(path, name):
|
def load_module(path, name):
|
||||||
|
|||||||
@@ -103,7 +103,8 @@ class ImportWrapper(pr.Base):
|
|||||||
names += self._get_module_names([path])
|
names += self._get_module_names([path])
|
||||||
|
|
||||||
if self._is_relative_import():
|
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):
|
if os.path.exists(rel_path):
|
||||||
m = _load_module(rel_path)
|
m = _load_module(rel_path)
|
||||||
names += m.get_defined_names()
|
names += m.get_defined_names()
|
||||||
@@ -459,7 +460,7 @@ class _Importer(object):
|
|||||||
if is_package_directory or current_namespace[0]:
|
if is_package_directory or current_namespace[0]:
|
||||||
# is a directory module
|
# is a directory module
|
||||||
if is_package_directory:
|
if is_package_directory:
|
||||||
path += '/__init__.py'
|
path = os.path.join(path, '__init__.py')
|
||||||
with open(path, 'rb') as f:
|
with open(path, 'rb') as f:
|
||||||
source = f.read()
|
source = f.read()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class IntegrationTestCase(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def module_name(self):
|
def module_name(self):
|
||||||
return re.sub('.*/|\.py$', '', self.path)
|
return os.path.splitext(os.path.basename(self.path))[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def line_nr_test(self):
|
def line_nr_test(self):
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
This directory contains pre-compiled extensions modules used to test completions
|
|
||||||
for compiled modules on Travis-CI (Ubuntu 12.04 64bit).
|
|
||||||
|
|
||||||
To build the extensions modules, run::
|
|
||||||
|
|
||||||
python setup.py build_ext -i
|
|
||||||
|
|
||||||
|
|
||||||
Then move the compiled modules to their testing package ( ./**compiledXX**, where XX is the
|
|
||||||
python version used to run setup.py).
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
cdef class Foo:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
cdef class Bar:
|
|
||||||
pass
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +0,0 @@
|
|||||||
from distutils.core import setup
|
|
||||||
from Cython.Build import cythonize
|
|
||||||
|
|
||||||
setup(
|
|
||||||
ext_modules=cythonize("compiled.pyx")
|
|
||||||
)
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
from ..helpers import cwd_at
|
|
||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
|
from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
|
||||||
|
_get_buildout_scripts,
|
||||||
|
_check_module)
|
||||||
from jedi.parser import Parser
|
from jedi.parser import Parser
|
||||||
from jedi.evaluate.sys_path import (
|
|
||||||
_get_parent_dir_with_file,
|
from ..helpers import cwd_at
|
||||||
_get_buildout_scripts,
|
|
||||||
_check_module
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')
|
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')
|
||||||
@@ -14,7 +14,7 @@ def test_parent_dir_with_file():
|
|||||||
parent = _get_parent_dir_with_file(
|
parent = _get_parent_dir_with_file(
|
||||||
os.path.abspath(os.curdir), 'buildout.cfg')
|
os.path.abspath(os.curdir), 'buildout.cfg')
|
||||||
assert parent is not None
|
assert parent is not None
|
||||||
assert parent.endswith('test/test_evaluate/buildout_project')
|
assert parent.endswith(os.path.join('test', 'test_evaluate', 'buildout_project'))
|
||||||
|
|
||||||
|
|
||||||
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')
|
@cwd_at('test/test_evaluate/buildout_project/src/proj_name')
|
||||||
|
|||||||
@@ -2,41 +2,30 @@
|
|||||||
Test compiled module
|
Test compiled module
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import platform
|
|
||||||
import sys
|
|
||||||
import jedi
|
import jedi
|
||||||
|
|
||||||
from ..helpers import cwd_at
|
|
||||||
|
|
||||||
|
|
||||||
@cwd_at('test/test_evaluate/extensions')
|
|
||||||
def test_completions():
|
def test_completions():
|
||||||
if platform.architecture()[0] == '64bit':
|
s = jedi.Script('import _ctypes; _ctypes.')
|
||||||
package_name = "compiled%s%s" % sys.version_info[:2]
|
assert len(s.completions()) >= 15
|
||||||
sys.path.insert(0, os.getcwd())
|
|
||||||
if os.path.exists(package_name):
|
|
||||||
s = jedi.Script("from %s import compiled; compiled." % package_name)
|
|
||||||
assert len(s.completions()) >= 2
|
|
||||||
|
|
||||||
|
|
||||||
@cwd_at('test/test_evaluate/extensions')
|
|
||||||
def test_call_signatures_extension():
|
def test_call_signatures_extension():
|
||||||
# with a cython extension
|
if os.name == 'nt':
|
||||||
if platform.architecture()[0] == '64bit':
|
func = 'LoadLibrary'
|
||||||
package_name = "compiled%s%s" % sys.version_info[:2]
|
params = 1
|
||||||
sys.path.insert(0, os.getcwd())
|
else:
|
||||||
if os.path.exists(package_name):
|
func = 'dlopen'
|
||||||
s = jedi.Script("from %s import compiled; compiled.Foo(" %
|
params = 2
|
||||||
package_name)
|
s = jedi.Script('import _ctypes; _ctypes.%s(' % (func,))
|
||||||
defs = s.call_signatures()
|
sigs = s.call_signatures()
|
||||||
for call_def in defs:
|
assert len(sigs) == 1
|
||||||
for param in call_def.params:
|
assert len(sigs[0].params) == params
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def test_call_signatures_stdlib():
|
def test_call_signatures_stdlib():
|
||||||
code = "import math; math.cos("
|
s = jedi.Script('import math; math.cos(')
|
||||||
s = jedi.Script(code)
|
sigs = s.call_signatures()
|
||||||
defs = s.call_signatures()
|
assert len(sigs) == 1
|
||||||
for call_def in defs:
|
assert len(sigs[0].params) == 1
|
||||||
assert len(call_def.params) == 1
|
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
from jedi import parser
|
|
||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
|
from jedi import parser
|
||||||
|
|
||||||
try:
|
from ..helpers import unittest
|
||||||
import unittest2 as unittest
|
|
||||||
except ImportError: # pragma: no cover
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
|
|
||||||
class TokenTest(unittest.TestCase):
|
class TokenTest(unittest.TestCase):
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import readline
|
try:
|
||||||
|
import readline
|
||||||
|
except ImportError:
|
||||||
|
readline = False
|
||||||
|
|
||||||
from jedi import utils
|
from jedi import utils
|
||||||
from .helpers import TestCase, cwd_at
|
|
||||||
|
from .helpers import unittest, cwd_at
|
||||||
|
|
||||||
|
|
||||||
class TestSetupReadline(TestCase):
|
@unittest.skipIf(not readline, "readline not found")
|
||||||
|
class TestSetupReadline(unittest.TestCase):
|
||||||
class NameSpace(object):
|
class NameSpace(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user