mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
Stuff mostly related to namespace packages.
This commit is contained in:
@@ -528,7 +528,7 @@ class _Importer(object):
|
|||||||
options = ('declare_namespace(__name__)', 'extend_path(__path__')
|
options = ('declare_namespace(__name__)', 'extend_path(__path__')
|
||||||
if options[0] in content or options[1] in content:
|
if options[0] in content or options[1] in content:
|
||||||
# It is a namespace, now try to find the rest of the modules.
|
# It is a namespace, now try to find the rest of the modules.
|
||||||
return follow_path(iter(import_path), sys.path)
|
return follow_path((str(i) for i in import_path), sys.path)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _follow_sys_path(self, sys_path):
|
def _follow_sys_path(self, sys_path):
|
||||||
@@ -647,7 +647,6 @@ class _Importer(object):
|
|||||||
if os.path.isdir(flaskext):
|
if os.path.isdir(flaskext):
|
||||||
names += self._get_module_names([flaskext])
|
names += self._get_module_names([flaskext])
|
||||||
|
|
||||||
# TODO delete
|
|
||||||
# namespace packages
|
# namespace packages
|
||||||
if isinstance(scope, pr.Module) and scope.path.endswith('__init__.py'):
|
if isinstance(scope, pr.Module) and scope.path.endswith('__init__.py'):
|
||||||
pkg_path = os.path.dirname(scope.path)
|
pkg_path = os.path.dirname(scope.path)
|
||||||
@@ -661,8 +660,10 @@ class _Importer(object):
|
|||||||
# os.path is a hardcoded exception, because it's a
|
# os.path is a hardcoded exception, because it's a
|
||||||
# ``sys.modules`` modification.
|
# ``sys.modules`` modification.
|
||||||
names.append(self._generate_name('path'))
|
names.append(self._generate_name('path'))
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# TODO delete
|
||||||
if False and not self.import_stmt.from_names or False and self.is_partial_import:
|
if False and not self.import_stmt.from_names or False and self.is_partial_import:
|
||||||
# from_names must be defined to access module
|
# from_names must be defined to access module
|
||||||
# values plus a partial import means that there
|
# values plus a partial import means that there
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
addopts = --doctest-modules
|
addopts = --doctest-modules
|
||||||
|
|
||||||
# Ignore broken files in blackbox test directories
|
# Ignore broken files in blackbox test directories
|
||||||
norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions speed static_analysis
|
norecursedirs = .* docs completion refactor absolute_import namespace_package scripts extensions speed static_analysis not_in_sys_path buildout_project
|
||||||
|
|
||||||
# Activate `clean_jedi_cache` fixture for all tests. This should be
|
# Activate `clean_jedi_cache` fixture for all tests. This should be
|
||||||
# fine as long as we are using `clean_jedi_cache` as a session scoped
|
# fine as long as we are using `clean_jedi_cache` as a session scoped
|
||||||
|
|||||||
@@ -56,4 +56,3 @@ def test_flask_ext(script, name):
|
|||||||
"""flask.ext.foo is really imported from flaskext.foo or flask_foo.
|
"""flask.ext.foo is really imported from flaskext.foo or flask_foo.
|
||||||
"""
|
"""
|
||||||
assert name in [c.name for c in jedi.Script(script).completions()]
|
assert name in [c.name for c in jedi.Script(script).completions()]
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def test_namespace_package():
|
|||||||
names = [str(c.name) for c in completions] # str because of unicode
|
names = [str(c.name) for c in completions] # str because of unicode
|
||||||
compare = ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file']
|
compare = ['foo', 'ns1_file', 'ns1_folder', 'ns2_folder', 'ns2_file']
|
||||||
# must at least contain these items, other items are not important
|
# must at least contain these items, other items are not important
|
||||||
assert not (set(compare) - set(names))
|
assert set(compare) == set(names)
|
||||||
|
|
||||||
tests = {
|
tests = {
|
||||||
'from pkg import ns2_folder as x': 'ns2_folder!',
|
'from pkg import ns2_folder as x': 'ns2_folder!',
|
||||||
|
|||||||
Reference in New Issue
Block a user