-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
97 lines (75 loc) · 2.67 KB
/
functions.py
File metadata and controls
97 lines (75 loc) · 2.67 KB
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
# import libraries
import pythonlab
import field
import sys
from math import *
# add actual directory to the path
sys.path.insert(0, ".")
# user functions
def sgn(number):
return (number >= 0) and 1 or -1
def test(text, value, normal, error = 0.03):
if ((normal == 0.0) and abs(value < 1e-14)):
return True
test = abs((value - normal)/value) < error
if (not test):
print(text + ": Agros2D: " + str(value) + ", correct: " + str(normal) + ")")
return test
setattr(agros2d, "test", test)
from rope.base.project import Project
pythonlab_rope_project = Project(".", ropefolder=None)
# get completion list
def python_engine_get_completion_string(code, offset):
from rope.contrib import codeassist
proposals = codeassist.code_assist(pythonlab_rope_project, code, offset, maxfixes=20)
# proposals = codeassist.sorted_proposals(proposals)
proposals_string = []
for p in proposals:
proposals_string.append(p.__str__())
return proposals_string
# return [proposal.name for proposal in proposals]
def python_engine_get_completion_string_dot(code):
try:
return dir(eval(code))
except:
return []
def python_engine_get_completion_file(filename, offset):
from rope.contrib import codeassist
f = open(filename, 'r')
code = ''.join(f.readlines())
proposals_string = []
try:
proposals = codeassist.code_assist(pythonlab_rope_project, code, offset, maxfixes=20)
# proposals = codeassist.sorted_proposals(proposals)
for p in proposals:
proposals_string.append(p.__str__())
return proposals_string
# return [proposal.name for proposal in proposals]
except:
return []
def python_engine_pyflakes_check(filename):
f = open(filename, 'r')
code = ''.join(f.readlines())
# first, compile into an AST and handle syntax errors.
try:
import _ast
tree = compile(code, "", "exec", _ast.PyCF_ONLY_AST)
except SyntaxError, value:
msg = value.args[0]
(lineno, offset, text) = value.lineno, value.offset, value.text
line = text.splitlines()[-1]
if offset is not None:
offset = offset - (len(text) - len(line))
return ['%s:%d: %s' % ("", lineno, msg)]
return 1
else:
# okay, it's syntactically valid. Now check it.
import pyflakes.checker as checker
w = checker.Checker(tree, "")
w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
return [warning.__str__() for warning in w.messages]
# redirect std output
class StdoutCatcher:
def write(self, str):
pythonlab.__stdout__(str)
sys.stdout = StdoutCatcher()