-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test.py
112 lines (87 loc) · 3.92 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2009- Spyder Project Contributors
#
# Distributed under the terms of the MIT License
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------
# Standard library imports
import os.path as osp
import time
# Third party imports
import rope.base.project
import rope.base.libutils
import rope.contrib.codeassist
ROPE_PREFS = {
'ignore_syntax_errors': True,
'ignore_bad_imports': True,
'automatic_soa': False,
'perform_doa': False,
'import_dynload_stdmods': False,
'soa_followed_calls': 2,
'extension_modules': [
"PyQt4", "PyQt4.QtGui", "QtGui", "PyQt4.QtCore", "QtCore",
"PyQt4.QtScript", "QtScript", "os.path", "numpy", "scipy", "PIL",
"OpenGL", "array", "audioop", "binascii", "cPickle", "cStringIO",
"cmath", "collections", "datetime", "errno", "exceptions", "gc",
"imageop", "imp", "itertools", "marshal", "math", "mmap", "msvcrt",
"nt", "operator", "os", "parser", "rgbimg", "signal", "strop", "sys",
"thread", "time", "wx", "wxPython", "xxsubtype", "zipimport", "zlib"],
}
def ropetest():
project = rope.base.project.Project('src', **ROPE_PREFS)
project.validate(project.root)
filename = osp.join('src', 'script.py')
source_code = file(filename, 'rb').read()
offset = len(source_code)
resource = rope.base.libutils.path_to_resource(project, filename)
t0 = time.time()
proposals = rope.contrib.codeassist.code_assist(project, source_code,
offset, resource)
proposals = rope.contrib.codeassist.sorted_proposals(proposals)
print "%s: %d ms" % ("completion", 10*round(1e2*(time.time()-t0)))
print 'loadtxt' in [proposal.name for proposal in proposals]
pydocextractor = rope.contrib.codeassist.PyDocExtractor()
def get_pyobject(project, source_code, offset, resource=None, maxfixes=1):
fixer = rope.contrib.codeassist.fixsyntax.FixSyntax(project.pycore,
source_code, resource, maxfixes)
pyname = fixer.pyname_at(offset)
if pyname is None:
return None
return pyname.get_object()
def get_calltip_from_pyobject(pyobject,
ignore_unknown=False, remove_self=False):
return pydocextractor.get_calltip(pyobject, ignore_unknown, remove_self)
def get_doc_from_pyobject(pyobject):
return pydocextractor.get_doc(pyobject)
from spyder import rope_patch
rope_patch.apply()
def other_features():
project = rope.base.project.Project('src', **ROPE_PREFS)
project.validate(project.root)
filename = osp.join('src', 'script2.py')
source_code = file(filename, 'rb').read()
offset = len(source_code)
resource = rope.base.libutils.path_to_resource(project, filename)
t0 = time.time()
cts = rope.contrib.codeassist.get_calltip(
project, source_code, offset, resource)
doc_text = rope.contrib.codeassist.get_doc(
project, source_code, offset, resource)
def_loc = rope.contrib.codeassist.get_definition_location(
project, source_code, offset, resource)
msg = "Testing other rope instrospection features"
print msg
print "="*len(msg)
print ""
print "%s: %d ms" % ("elapsed time", 10*round(1e2*(time.time()-t0)))
print ""
print 'calltip:', cts
print 'definition location:', def_loc
print 'doc:'
print '*** DOCUMENTATION ***' + '*'*60
print doc_text
print '*********************' + '*'*60
if __name__ == '__main__':
# ropetest()
other_features()