mumuki-python-runner 1.5.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/base/query_hook.rb +22 -7
- data/lib/base/test_hook.rb +1 -1
- data/lib/base/version.rb +2 -1
- data/lib/python2/expectations_hook.rb +2 -0
- data/lib/python2_runner.rb +3 -0
- data/lib/python3/try_hook.rb +48 -0
- data/lib/python3_runner.rb +3 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '039cd7e8daf34032853b80ad08223b1af629432395e1036d0c141bcd2a81cb4c'
|
4
|
+
data.tar.gz: eb45b266b689d2d13a18d54a1815a6d2f1b5d255c0dea700f67a17b5a34a5b40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a154c8202c04203bfd5a577d2a70d407ebfd98f24a3050fc524f97bbcb60c724f6944fd613911869160418590a80acf9abdf0aef3dd5b3a7e41904e752cb41f7
|
7
|
+
data.tar.gz: b609e0a9fa6624bb99e1e3b5a2db1ed63d5c131af554feee56e488eb6da67fcfb41abe607a8d2ada3ef0dbd38cfd583be8503388bcb1c658408cf64281b26dbc
|
data/lib/base/query_hook.rb
CHANGED
@@ -7,6 +7,10 @@ class BasePythonQueryHook < Mumukit::Templates::FileHook
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def compile_file_content(req)
|
10
|
+
"#{compile_file_header(req)}\n#{compile_query(req.query)}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def compile_file_header(req)
|
10
14
|
<<python
|
11
15
|
# -*- coding: UTF-8 -*-
|
12
16
|
import string, sys, os
|
@@ -16,19 +20,30 @@ import string, sys, os
|
|
16
20
|
sys.stdout = open(os.devnull, 'w')
|
17
21
|
#{compile_cookie(req.cookie)}
|
18
22
|
sys.stdout = sys.__stdout__
|
19
|
-
#{build_query req.query}
|
20
23
|
python
|
21
24
|
end
|
22
25
|
|
23
|
-
def
|
24
|
-
if query.match /print *(\(| ).*|^[a-zA-Z_]\w*\s
|
26
|
+
def compile_query(query, output_prefix = "=> ")
|
27
|
+
if query.match /print *(\(| ).*|^[a-zA-Z_]\w*\s*=[^=].*|^raise\b/
|
25
28
|
query
|
26
29
|
else
|
27
|
-
|
30
|
+
<<~python
|
31
|
+
__mumuki_error__ = None
|
32
|
+
try:
|
33
|
+
__mumuki_args__ = {'mumuki_query_result': eval("""#{query.gsub('"', '\"')}""")}
|
34
|
+
print(string.Template(\"#{output_prefix}\${mumuki_query_result}\").safe_substitute(**__mumuki_args__))
|
35
|
+
except SyntaxError as e:
|
36
|
+
__mumuki_error__ = SyntaxError(e.msg, ('<console>', e.lineno, e.offset, e.text))
|
37
|
+
if __mumuki_error__:
|
38
|
+
print(__mumuki_error__.text)
|
39
|
+
print(" "*(__mumuki_error__.offset - 1) + "^")
|
40
|
+
print('SyntheticMumukiSyntaxError: SyntaxError: ' + str(__mumuki_error__))
|
41
|
+
exit(1)
|
42
|
+
python
|
28
43
|
end
|
29
44
|
end
|
30
45
|
|
31
|
-
def
|
46
|
+
def compile_state(cookie)
|
32
47
|
(cookie||[]).map do |statement|
|
33
48
|
<<~python
|
34
49
|
try:
|
@@ -40,7 +55,7 @@ python
|
|
40
55
|
end
|
41
56
|
|
42
57
|
def compile_cookie(cookie)
|
43
|
-
|
58
|
+
compile_state(cookie).join("\n")
|
44
59
|
end
|
45
60
|
|
46
61
|
def error_patterns
|
@@ -50,7 +65,7 @@ python
|
|
50
65
|
end
|
51
66
|
|
52
67
|
def syntax_error_regexp
|
53
|
-
|
68
|
+
/(SyntheticMumukiSyntaxError: )|(\A File .*\n(?m)(?=.*(SyntaxError|IndentationError)))/
|
54
69
|
end
|
55
70
|
end
|
56
71
|
|
data/lib/base/test_hook.rb
CHANGED
data/lib/base/version.rb
CHANGED
data/lib/python2_runner.rb
CHANGED
@@ -4,7 +4,10 @@ def reload_python2_runner!
|
|
4
4
|
Mumukit.runner_name = 'python'
|
5
5
|
Mumukit.configure do |config|
|
6
6
|
config.docker_image = 'mumuki/mumuki-python2-worker:0.1'
|
7
|
+
# comment type should be Mumukit::Directives::CommentType::Ruby, but it is
|
8
|
+
# Mumukit::Directives::CommentType::Cpp for backward compatibility
|
7
9
|
config.stateful = true
|
10
|
+
config.structured = true
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Python3TryHook < Mumukit::Templates::TryHook
|
2
|
+
isolated true
|
3
|
+
attr_reader :query_hook
|
4
|
+
|
5
|
+
def initialize(config = nil)
|
6
|
+
super config
|
7
|
+
@query_hook = Python3QueryHook.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def compile_file_content(r)
|
11
|
+
<<python
|
12
|
+
#{query_hook.compile_file_header(r)}
|
13
|
+
print("#{query_separator}");
|
14
|
+
#{query_hook.compile_query(r.query, '')}
|
15
|
+
print("#{goal_separator}");
|
16
|
+
#{query_hook.compile_query(r.goal.indifferent_get(:query) || 'None', '')}
|
17
|
+
python
|
18
|
+
end
|
19
|
+
|
20
|
+
delegate :tempfile_extension, to: :query_hook
|
21
|
+
delegate :command_line, to: :query_hook
|
22
|
+
|
23
|
+
def query_separator
|
24
|
+
'!!!MUMUKI-QUERY-START!!!'
|
25
|
+
end
|
26
|
+
|
27
|
+
def goal_separator
|
28
|
+
'!!!MUMUKI-GOAL-START!!!'
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_structured_results(_file, result, status)
|
32
|
+
/#{query_separator}
|
33
|
+
?(.*)
|
34
|
+
#{goal_separator}
|
35
|
+
?(.*)
|
36
|
+
/m =~ result
|
37
|
+
|
38
|
+
{
|
39
|
+
query: to_query_result($1, status),
|
40
|
+
goal: $2,
|
41
|
+
status: status
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_query_result(result, status)
|
46
|
+
{ result: result, status: status }
|
47
|
+
end
|
48
|
+
end
|
data/lib/python3_runner.rb
CHANGED
@@ -4,6 +4,8 @@ def reload_python3_runner!
|
|
4
4
|
Mumukit.runner_name = 'python3'
|
5
5
|
Mumukit.configure do |config|
|
6
6
|
config.docker_image = 'mumuki/mumuki-python3-worker:0.1'
|
7
|
+
config.comment_type = Mumukit::Directives::CommentType::Ruby
|
8
|
+
config.structured = true
|
7
9
|
config.stateful = true
|
8
10
|
end
|
9
11
|
end
|
@@ -14,5 +16,6 @@ reload_python3_runner!
|
|
14
16
|
require_relative './python3/version'
|
15
17
|
require_relative './python3/test_hook'
|
16
18
|
require_relative './python3/query_hook'
|
19
|
+
require_relative './python3/try_hook'
|
17
20
|
require_relative './python3/expectations_hook'
|
18
21
|
require_relative './python3/metadata_hook'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-python-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumukit
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '12.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '12.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- lib/python3/metadata_hook.rb
|
148
148
|
- lib/python3/query_hook.rb
|
149
149
|
- lib/python3/test_hook.rb
|
150
|
+
- lib/python3/try_hook.rb
|
150
151
|
- lib/python3/version.rb
|
151
152
|
- lib/python3_runner.rb
|
152
153
|
- lib/python_runner.rb
|
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
171
172
|
requirements: []
|
172
|
-
rubygems_version: 3.0.
|
173
|
+
rubygems_version: 3.0.8
|
173
174
|
signing_key:
|
174
175
|
specification_version: 4
|
175
176
|
summary: Python Runner for Mumuki
|