mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
restructuring
This commit is contained in:
25
builtin.py
25
builtin.py
@@ -21,11 +21,18 @@ class Parser(object):
|
||||
""" This module tries to imitate parsing.Scope """
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.parent = None
|
||||
self.content = {}
|
||||
exec 'import %s as module' % name in self.content
|
||||
self.module = self.content['module']
|
||||
self._content = {}
|
||||
self._parser = None
|
||||
self._module = None
|
||||
|
||||
@property
|
||||
def module(self):
|
||||
if not self._module:
|
||||
print 'import', self.name
|
||||
exec 'import %s as module' % self.name in self._content
|
||||
print 'import2', self.name
|
||||
self._module = self._content['module']
|
||||
return self._module
|
||||
|
||||
@property
|
||||
def parser(self):
|
||||
@@ -33,7 +40,7 @@ class Parser(object):
|
||||
if self._parser:
|
||||
return self._parser
|
||||
else:
|
||||
code = self.generate_code(self.module)
|
||||
code = self._generate_code(self.module)
|
||||
try:
|
||||
self._parser = parsing.PyFuzzyParser(code)
|
||||
except:
|
||||
@@ -42,7 +49,7 @@ class Parser(object):
|
||||
raise
|
||||
return self._parser
|
||||
|
||||
def generate_code(self, scope, depth=0):
|
||||
def _generate_code(self, scope, depth=0):
|
||||
"""
|
||||
Generate a string, which uses python syntax as an input to the
|
||||
PyFuzzyParser.
|
||||
@@ -88,7 +95,7 @@ class Parser(object):
|
||||
bases = (c.__name__ for c in cl.__bases__)
|
||||
code += 'class %s(%s):\n' % (name, ','.join(bases))
|
||||
if depth == 0:
|
||||
cl_code = self.generate_code(cl, depth + 1)
|
||||
cl_code = self._generate_code(cl, depth + 1)
|
||||
code += parsing.indent_block(cl_code)
|
||||
code += '\n'
|
||||
|
||||
@@ -126,8 +133,8 @@ class Parser(object):
|
||||
if depth == 0:
|
||||
#with open('writeout.py', 'w') as f:
|
||||
# f.write(code)
|
||||
#import sys
|
||||
#sys.stdout.write(code)
|
||||
import sys
|
||||
sys.stdout.write(code)
|
||||
#exit()
|
||||
pass
|
||||
return code
|
||||
|
||||
37
evaluate.py
37
evaluate.py
@@ -55,7 +55,7 @@ def memoize(default=None):
|
||||
|
||||
|
||||
class Exec(object):
|
||||
def __init__(self, base, params):
|
||||
def __init__(self, base, params=None):
|
||||
self.base = base
|
||||
self.params = params
|
||||
|
||||
@@ -238,24 +238,25 @@ def get_scopes_for_name(scope, name, search_global=False):
|
||||
# else:
|
||||
# result += filter_name(i)
|
||||
#else:
|
||||
if [name] == list(scope.names):
|
||||
if isinstance(scope, ArrayElement):
|
||||
result.append(scope)
|
||||
else:
|
||||
par = scope.parent
|
||||
if isinstance(par, parsing.Flow):
|
||||
# TODO get Flow data, which is defined by the loop
|
||||
# (or with)
|
||||
pass
|
||||
elif isinstance(par, parsing.Param):
|
||||
if isinstance(par.parent.parent, parsing.Class) \
|
||||
and par.position == 0:
|
||||
result.append(Instance(par.parent.parent))
|
||||
else:
|
||||
# TODO get function data
|
||||
pass
|
||||
if [name] == list(scope.names):
|
||||
if isinstance(scope, ArrayElement):
|
||||
result.append(scope)
|
||||
else:
|
||||
par = scope.parent
|
||||
if isinstance(par, parsing.Flow):
|
||||
# TODO get Flow data, which is defined by the loop
|
||||
# (or with)
|
||||
pass
|
||||
elif isinstance(par, parsing.Param):
|
||||
if isinstance(par.parent.parent, parsing.Class) \
|
||||
and par.position == 0:
|
||||
# this is where self is added
|
||||
result.append(Instance(par.parent.parent))
|
||||
else:
|
||||
result.append(scope.parent)
|
||||
# TODO get function data
|
||||
pass
|
||||
else:
|
||||
result.append(scope.parent)
|
||||
debug.dbg('sfn filter', result)
|
||||
return result
|
||||
|
||||
|
||||
14
modules.py
14
modules.py
@@ -75,7 +75,8 @@ def find_module(current_module, point_path):
|
||||
path = [ns[1]]
|
||||
else:
|
||||
path = None
|
||||
debug.dbg('search_module', string, path)
|
||||
debug.dbg('search_module', string, path,
|
||||
current_module.module_path)
|
||||
try:
|
||||
i = imp.find_module(string, path)
|
||||
except ImportError:
|
||||
@@ -86,7 +87,7 @@ def find_module(current_module, point_path):
|
||||
raise
|
||||
return i
|
||||
|
||||
# TODO handle relative paths - they are included int the import object
|
||||
# TODO handle relative paths - they are included in the import object
|
||||
current_namespace = None
|
||||
sys.path.insert(0, os.path.dirname(current_module.module_path))
|
||||
# now execute those paths
|
||||
@@ -105,6 +106,7 @@ def find_module(current_module, point_path):
|
||||
path = current_namespace[1]
|
||||
is_package_directory = current_namespace[2][2] == imp.PKG_DIRECTORY
|
||||
|
||||
f = None
|
||||
if is_package_directory or current_namespace[0]:
|
||||
# is a directory module
|
||||
if is_package_directory:
|
||||
@@ -115,7 +117,11 @@ def find_module(current_module, point_path):
|
||||
source = open(path).read()
|
||||
else:
|
||||
source = current_namespace[0].read()
|
||||
f = File(path, source)
|
||||
else:
|
||||
if path.endswith('.py'):
|
||||
f = File(path, source)
|
||||
if not f:
|
||||
print 'lala'
|
||||
f = builtin.Parser(path)
|
||||
print 'lala2'
|
||||
|
||||
return f.parser.top, rest
|
||||
|
||||
@@ -138,13 +138,13 @@ class c1():
|
||||
return c5+'asdf'
|
||||
(c1().c2.\
|
||||
c, 1, c3()) [0].pop()
|
||||
|
||||
c = u"asdf".join([1,2])
|
||||
matrix_test = [[1,2], [1,3]]
|
||||
c = c1().c3().sleep()
|
||||
asdf = c1; asdf2 = asdf
|
||||
b= asdf2
|
||||
#import parsing as test
|
||||
c = b().c3()
|
||||
1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request;
|
||||
abc = [1,2+3]; abc[0].
|
||||
import pylab
|
||||
pylab.
|
||||
|
||||
@@ -10,6 +10,7 @@ import functions
|
||||
|
||||
#functions.set_debug_function(functions.debug.print_to_stdout)
|
||||
|
||||
|
||||
def completion_test(source):
|
||||
"""
|
||||
This is the completion test for some cases. The tests are not unit test
|
||||
@@ -56,7 +57,7 @@ def completion_test(source):
|
||||
# completion tests:
|
||||
completion_test_dir = 'completion'
|
||||
summary = []
|
||||
for f_name in os.listdir(completion_test_dir ):
|
||||
for f_name in os.listdir(completion_test_dir):
|
||||
if f_name.endswith(".py"):
|
||||
path = os.path.join(completion_test_dir, f_name)
|
||||
f = open(path)
|
||||
|
||||
Reference in New Issue
Block a user