mumuki-python-runner 1.5.2 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e7167e2bb88c00b9533ab2180a1e70ab4a328716ea3aa6a00d57ee59373c059
4
- data.tar.gz: cc200d20a917577925591f9c7aea6277c8c9cbbf859d5a3023fcc8eb24b64b6b
3
+ metadata.gz: f4a1cf971f4ce948e0e251e05f92672ca1c01e2b7f4441b60f57634c8cd89c68
4
+ data.tar.gz: 6bf96e4e38f596547ed4258c8447e8f6be826a8afedb75989fef278ea70a1664
5
5
  SHA512:
6
- metadata.gz: 440297a480a73a7906564e6f91e46ed4666c9f780028574a86d6a8b6616dc25ce16ca040fabc4f97dbfde656d1b874b17957f73decab044c3f1089155dbe1ede
7
- data.tar.gz: d2be4041b961a5b9ab90a99961b2813314c9ead96a13d37d065055b774d31e9814fae56e2da64ce584d316005f3cba5c11473b3bb74e82d3fa7a6cc6fba817e3
6
+ metadata.gz: f6340927de462b077cda6f61ea5dfb8b3bdc7ff1419abd8d59f623c33cac2f7c40eba7770a92b5a20c560b2e1e7b98d1343f668f93d9e6441e7c4d63c2b5669d
7
+ data.tar.gz: e5858f8ff89f2a13e1a1f65e265f4467a1e4017ed2c42bbbd92986e22436d54c46994c79e684384e1288a44ec3bb3dc492aaf305ab65adad08fc8223ceb5284b
@@ -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,31 +20,22 @@ 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 build_query(query)
24
- if query.match /print *(\(| ).*|^[a-zA-Z_]\w*\s*=.*|^raise\b/
25
- query
26
- else
27
- "print(string.Template(\"=> $result\").substitute(result = #{query}))"
28
- end
29
- end
30
-
31
- def build_state(cookie)
26
+ def compile_state(cookie)
32
27
  (cookie||[]).map do |statement|
33
- <<~python
34
- try:
35
- #{statement}
36
- except:
37
- pass
28
+ <<~python
29
+ try:
30
+ #{statement}
31
+ except:
32
+ pass
38
33
  python
39
34
  end
40
35
  end
41
36
 
42
37
  def compile_cookie(cookie)
43
- build_state(cookie).join("\n")
38
+ compile_state(cookie).join("\n")
44
39
  end
45
40
 
46
41
  def error_patterns
@@ -50,13 +45,6 @@ python
50
45
  end
51
46
 
52
47
  def syntax_error_regexp
53
- /\A File .*\n(?m)(?=.*(SyntaxError|IndentationError))/
48
+ /(SyntheticMumukiSyntaxError: )|((\A File .*\n)?(?m)(?=.*(SyntaxError|IndentationError)))/
54
49
  end
55
50
  end
56
-
57
-
58
-
59
-
60
-
61
-
62
-
data/lib/base/version.rb CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  module BasePythonVersionHook
2
- VERSION = '1.5.2'
3
+ VERSION = '1.8.0'
3
4
  end
@@ -1,4 +1,23 @@
1
1
  class Python2QueryHook < BasePythonQueryHook
2
+ def compile_query(query, output_prefix = "=> ")
3
+ if query.match /print *(\(| ).*|.*[^=><!]=[^=].*|^raise\b/
4
+ query
5
+ else
6
+ <<~python
7
+ __mumuki_error__ = None
8
+ try:
9
+ __mumuki_args__ = {'mumuki_query_result': eval("""#{query.gsub('"', '\"')}""")}
10
+ print(string.Template(\"\${mumuki_query_result}\").safe_substitute(**__mumuki_args__))
11
+ except SyntaxError as e:
12
+ __mumuki_error__ = SyntaxError(e.msg, ('<console>', e.lineno, e.offset, e.text))
13
+ if __mumuki_error__:
14
+ print(__mumuki_error__.text)
15
+ print(" "*(__mumuki_error__.offset - 1) + "^")
16
+ print('SyntheticMumukiSyntaxError: SyntaxError: ' + str(__mumuki_error__))
17
+ exit(1)
18
+ python
19
+ end
20
+ end
2
21
  end
3
22
 
4
23
  PythonQueryHook = Python2QueryHook
@@ -1,2 +1,24 @@
1
1
  class Python3QueryHook < BasePythonQueryHook
2
+ def compile_query(query, output_prefix = "=> ")
3
+ <<~python
4
+ import code
5
+ import itertools
6
+ import traceback
7
+ import sys
8
+
9
+ __mumuki_console__ = code.InteractiveConsole()
10
+
11
+ try:
12
+ __mumuki_result__ = __mumuki_console__.compile("""#{query.gsub('"', '\"')}""")
13
+ if __mumuki_result__ != None:
14
+ exec(__mumuki_result__)
15
+ else:
16
+ raise SyntaxError('unexpected EOF while parsing')
17
+ except:
18
+ error = sys.exc_info()
19
+ stack = traceback.format_exception(*error)
20
+ print(*itertools.dropwhile(lambda it: 'File "<input>"' not in it and not it.startswith("SyntaxError"), stack))
21
+ exit(1)
22
+ python
23
+ end
2
24
  end
@@ -0,0 +1,53 @@
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
+
49
+ def checker_options
50
+ { strip_mode: :right_only }
51
+ end
52
+
53
+ end
@@ -16,5 +16,6 @@ reload_python3_runner!
16
16
  require_relative './python3/version'
17
17
  require_relative './python3/test_hook'
18
18
  require_relative './python3/query_hook'
19
+ require_relative './python3/try_hook'
19
20
  require_relative './python3/expectations_hook'
20
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.5.2
4
+ version: 1.8.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: 2019-05-06 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -16,56 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.30'
19
+ version: '2.41'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.30'
27
- - !ruby/object:Gem::Dependency
28
- name: mulang
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '4.5'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '4.5'
26
+ version: '2.41'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '1.7'
33
+ version: '2.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '1.7'
40
+ version: '2.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '10.0'
47
+ version: '12.3'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '10.0'
54
+ version: '12.3'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +133,7 @@ files:
147
133
  - lib/python3/metadata_hook.rb
148
134
  - lib/python3/query_hook.rb
149
135
  - lib/python3/test_hook.rb
136
+ - lib/python3/try_hook.rb
150
137
  - lib/python3/version.rb
151
138
  - lib/python3_runner.rb
152
139
  - lib/python_runner.rb