mumuki-python-runner 1.5.2 → 1.6.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: dcb623be34bb249818161740a8eeb299fb3d8db1c0513c76769a5379f3c959e6
4
+ data.tar.gz: ec5e53117030aa1228715ae86a43f9670b0878aa0c1db16f7a49f9b3d2689a4c
5
5
  SHA512:
6
- metadata.gz: 440297a480a73a7906564e6f91e46ed4666c9f780028574a86d6a8b6616dc25ce16ca040fabc4f97dbfde656d1b874b17957f73decab044c3f1089155dbe1ede
7
- data.tar.gz: d2be4041b961a5b9ab90a99961b2813314c9ead96a13d37d065055b774d31e9814fae56e2da64ce584d316005f3cba5c11473b3bb74e82d3fa7a6cc6fba817e3
6
+ metadata.gz: 6e4610071f25ff2e3d50825c745fad561247375c63e8edcbde1ece7cbc9665f82583612fa01a264bc79226c5fc37e55713af7e38e577bba40ba9ddb3213aaf51
7
+ data.tar.gz: c82f05190f3a999bdbbf0bcc1b531398b649912b1f3db61835a9e9ee0fa6cceee5741514e225b0a04ca92833bf0edfc9d18530be4a70bc72294965ab0badea18
@@ -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,18 @@ 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)
26
+ def compile_query(query, output_prefix = "=> ", output_var = "__mumuki_query_result__")
24
27
  if query.match /print *(\(| ).*|^[a-zA-Z_]\w*\s*=.*|^raise\b/
25
28
  query
26
29
  else
27
- "print(string.Template(\"=> $result\").substitute(result = #{query}))"
30
+ "print(string.Template(\"#{output_prefix}$#{output_var}\").substitute(#{output_var} = #{query}))"
28
31
  end
29
32
  end
30
33
 
31
- def build_state(cookie)
34
+ def compile_state(cookie)
32
35
  (cookie||[]).map do |statement|
33
36
  <<~python
34
37
  try:
@@ -40,7 +43,7 @@ python
40
43
  end
41
44
 
42
45
  def compile_cookie(cookie)
43
- build_state(cookie).join("\n")
46
+ compile_state(cookie).join("\n")
44
47
  end
45
48
 
46
49
  def error_patterns
data/lib/base/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BasePythonVersionHook
2
- VERSION = '1.5.2'
2
+ VERSION = '1.6.0'
3
3
  end
@@ -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', '', '__mumuki_goal_query_result__')}
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
@@ -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.6.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: 2020-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -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,8 @@ 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.3
173
+ rubyforge_project:
174
+ rubygems_version: 2.7.7
173
175
  signing_key:
174
176
  specification_version: 4
175
177
  summary: Python Runner for Mumuki