mumuki-python-runner 1.4.0 → 1.6.1

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: e612f940397a2348ef6d4c158bcbed0a3717de566d041c14adcbf80e96dfef4a
4
- data.tar.gz: 7c54b548c81131d82db8ee1bdc57eb6cd11e416d9ba3096ef99740f245c19608
3
+ metadata.gz: 0275bf8b0f0c205ce0e5ceda01999f39a417013d9490750b91cf3b88ca57e437
4
+ data.tar.gz: d1ca4344541694ca5ed8ef244943f5e4fb1f8df94fac3d7cefc271c79db9608c
5
5
  SHA512:
6
- metadata.gz: fbf8986fe189ce8a4b7ece4d851aefd0db54ec44fb322085121a703b1acc62d4172fadd09d38eba19b972079c346035c30d800bf19b70c96f65463b208d19158
7
- data.tar.gz: 75fb4c21302155911644257a2738ce5cfd23f5d81fe3c02051c0a41d91f115cad1acc8e4047c496f140f1035dbba659f6cf99f8a1670e08ef7bb0c1191ab75a7
6
+ metadata.gz: 46f823c0f7034521637dd08853948ef34e114fd11be5fbd6293ad264a4318a42a764b3709f237a45b8b5ad90755ff28b9c3cbcd14af480320ffb71c60c76fa72
7
+ data.tar.gz: 78517e84935997c70ab4c8ff24728caf909c9f4e1109b031f33f5ec80ecb6165557d6150bcb9dd8f399f7642bcfc4c33f8f1d6e1ea8ecc4e252b388e7953676e
@@ -0,0 +1,10 @@
1
+ require 'mumukit'
2
+ require 'nokogiri'
3
+
4
+ I18n.load_translations_path File.join(__dir__, 'locales', '*.yml')
5
+
6
+ require_relative './base/version'
7
+ require_relative './base/test_hook'
8
+ require_relative './base/query_hook'
9
+ require_relative './base/expectations_hook'
10
+ require_relative './base/metadata_hook'
@@ -0,0 +1,15 @@
1
+ class BasePythonExpectationsHook < Mumukit::Templates::MulangExpectationsHook
2
+ include_smells true
3
+
4
+ def default_smell_exceptions
5
+ LOGIC_SMELLS + FUNCTIONAL_SMELLS
6
+ end
7
+
8
+ def domain_language
9
+ {
10
+ caseStyle: 'RubyCase',
11
+ minimumIdentifierSize: 3,
12
+ jargon: []
13
+ }
14
+ end
15
+ end
@@ -1,9 +1,9 @@
1
- class PythonMetadataHook < Mumukit::Hook
1
+ class BasePythonMetadataHook < Mumukit::Hook
2
2
  def metadata
3
3
  {language: {
4
4
  name: 'python',
5
5
  icon: {type: 'devicon', name: 'python'},
6
- version: '2.7.6',
6
+ version: version,
7
7
  extension: 'py',
8
8
  ace_mode: 'python'
9
9
  },
@@ -18,4 +18,6 @@ class Test(unittest.TestCase):
18
18
  python
19
19
  }}
20
20
  end
21
- end
21
+
22
+ required :version
23
+ end
@@ -1,4 +1,4 @@
1
- class PythonQueryHook < Mumukit::Templates::FileHook
1
+ class BasePythonQueryHook < Mumukit::Templates::FileHook
2
2
  with_error_patterns
3
3
  isolated true
4
4
 
@@ -7,7 +7,12 @@ class PythonQueryHook < 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
15
+ # -*- coding: UTF-8 -*-
11
16
  import string, sys, os
12
17
 
13
18
  #{req.extra}
@@ -15,19 +20,18 @@ import string, sys, os
15
20
  sys.stdout = open(os.devnull, 'w')
16
21
  #{compile_cookie(req.cookie)}
17
22
  sys.stdout = sys.__stdout__
18
- #{build_query req.query}
19
23
  python
20
24
  end
21
25
 
22
- def build_query(query)
23
- if query.match /print *(\(| ).*|^[a-zA-Z_]\w*\s*=.*|^raise\b/
26
+ def compile_query(query, output_prefix = "=> ")
27
+ if query.match /print *(\(| ).*|^[a-zA-Z_]\w*\s*=[^=].*|^raise\b/
24
28
  query
25
29
  else
26
- "print(string.Template(\"=> $result\").substitute(result = #{query}))"
30
+ "print(string.Template(\"#{output_prefix}\${mumuki_query_result}\").safe_substitute(mumuki_query_result = #{query}))"
27
31
  end
28
32
  end
29
33
 
30
- def build_state(cookie)
34
+ def compile_state(cookie)
31
35
  (cookie||[]).map do |statement|
32
36
  <<~python
33
37
  try:
@@ -39,7 +43,7 @@ python
39
43
  end
40
44
 
41
45
  def compile_cookie(cookie)
42
- build_state(cookie).join("\n")
46
+ compile_state(cookie).join("\n")
43
47
  end
44
48
 
45
49
  def error_patterns
@@ -1,4 +1,4 @@
1
- class PythonTestHook < Mumukit::Templates::FileHook
1
+ class BasePythonTestHook < Mumukit::Templates::FileHook
2
2
  isolated true
3
3
 
4
4
  def tempfile_extension
@@ -6,21 +6,23 @@ class PythonTestHook < Mumukit::Templates::FileHook
6
6
  end
7
7
 
8
8
  def command_line(filename)
9
- "python #{filename}"
9
+ "rununittest #{filename}"
10
10
  end
11
11
 
12
12
  def compile_file_content(request)
13
13
  <<python
14
+ # -*- coding: UTF-8 -*-
15
+
14
16
  import unittest
15
17
  import xmlrunner
16
18
  import sys
17
19
 
18
- #{request.content}
19
20
  #{request.extra}
21
+ #{request.content}
20
22
  #{test_class(request.test)}
21
23
 
22
24
  unittest.main(
23
- testRunner=xmlrunner.XMLTestRunner(output=sys.__stdout__),
25
+ testRunner=xmlrunner.XMLTestRunner(output='./xml-unittest-output'),
24
26
  failfast=False,
25
27
  buffer=False,
26
28
  catchbreak=False
@@ -0,0 +1,4 @@
1
+
2
+ module BasePythonVersionHook
3
+ VERSION = '1.6.1'
4
+ end
@@ -0,0 +1,7 @@
1
+ class Python2ExpectationsHook < BasePythonExpectationsHook
2
+ def language
3
+ 'Python2'
4
+ end
5
+ end
6
+
7
+ PythonExpectationsHook = Python2ExpectationsHook
@@ -0,0 +1,8 @@
1
+ class Python2MetadataHook < BasePythonMetadataHook
2
+ def version
3
+ '2.7.16'
4
+ end
5
+ end
6
+
7
+ PythonMetadataHook = Python2MetadataHook
8
+
@@ -0,0 +1,4 @@
1
+ class Python2QueryHook < BasePythonQueryHook
2
+ end
3
+
4
+ PythonQueryHook = Python2QueryHook
@@ -0,0 +1,4 @@
1
+ class Python2TestHook < BasePythonTestHook
2
+ end
3
+
4
+ PythonTestHook = Python2TestHook
@@ -0,0 +1,3 @@
1
+ Python2VersionHook = BasePythonVersionHook
2
+ PythonVersionHook = Python2VersionHook
3
+
@@ -0,0 +1,21 @@
1
+ require_relative './base'
2
+
3
+ def reload_python2_runner!
4
+ Mumukit.runner_name = 'python'
5
+ Mumukit.configure do |config|
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
9
+ config.stateful = true
10
+ config.structured = true
11
+ end
12
+ end
13
+
14
+ # for testing only
15
+ reload_python2_runner!
16
+
17
+ require_relative './python2/version'
18
+ require_relative './python2/test_hook'
19
+ require_relative './python2/query_hook'
20
+ require_relative './python2/expectations_hook'
21
+ require_relative './python2/metadata_hook'
@@ -0,0 +1,5 @@
1
+ class Python3ExpectationsHook < BasePythonExpectationsHook
2
+ def language
3
+ 'Python3'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class Python3MetadataHook < BasePythonMetadataHook
2
+ def version
3
+ '3.7.3'
4
+ end
5
+ end
6
+
@@ -0,0 +1,2 @@
1
+ class Python3QueryHook < BasePythonQueryHook
2
+ end
@@ -0,0 +1,2 @@
1
+ class Python3TestHook < BasePythonTestHook
2
+ 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', '')}
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
@@ -0,0 +1 @@
1
+ Python3VersionHook = BasePythonVersionHook
@@ -0,0 +1,21 @@
1
+ require_relative './base'
2
+
3
+ def reload_python3_runner!
4
+ Mumukit.runner_name = 'python3'
5
+ Mumukit.configure do |config|
6
+ config.docker_image = 'mumuki/mumuki-python3-worker:0.1'
7
+ config.comment_type = Mumukit::Directives::CommentType::Ruby
8
+ config.structured = true
9
+ config.stateful = true
10
+ end
11
+ end
12
+
13
+ # for testing only
14
+ reload_python3_runner!
15
+
16
+ require_relative './python3/version'
17
+ require_relative './python3/test_hook'
18
+ require_relative './python3/query_hook'
19
+ require_relative './python3/try_hook'
20
+ require_relative './python3/expectations_hook'
21
+ require_relative './python3/metadata_hook'
@@ -1,15 +1 @@
1
- require 'mumukit'
2
- require 'nokogiri'
3
-
4
- I18n.load_translations_path File.join(__dir__, 'locales', '*.yml')
5
-
6
- Mumukit.runner_name = 'python'
7
- Mumukit.configure do |config|
8
- config.docker_image = 'mumuki/mumuki-python-worker:1.1'
9
- config.stateful = true
10
- end
11
-
12
- require_relative 'version'
13
- require_relative 'test_hook'
14
- require_relative 'query_hook'
15
- require_relative 'metadata_hook'
1
+ require_relative './python2_runner'
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.0
4
+ version: 1.6.1
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-02-26 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '10.0'
61
+ version: '12.3'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: '12.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -115,14 +129,29 @@ executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
132
+ - lib/base.rb
133
+ - lib/base/expectations_hook.rb
134
+ - lib/base/metadata_hook.rb
135
+ - lib/base/query_hook.rb
136
+ - lib/base/test_hook.rb
137
+ - lib/base/version.rb
118
138
  - lib/locales/en.yml
119
139
  - lib/locales/es.yml
120
- - lib/metadata_hook.rb
140
+ - lib/python2/expectations_hook.rb
141
+ - lib/python2/metadata_hook.rb
142
+ - lib/python2/query_hook.rb
143
+ - lib/python2/test_hook.rb
144
+ - lib/python2/version.rb
145
+ - lib/python2_runner.rb
146
+ - lib/python3/expectations_hook.rb
147
+ - lib/python3/metadata_hook.rb
148
+ - lib/python3/query_hook.rb
149
+ - lib/python3/test_hook.rb
150
+ - lib/python3/try_hook.rb
151
+ - lib/python3/version.rb
152
+ - lib/python3_runner.rb
121
153
  - lib/python_runner.rb
122
- - lib/query_hook.rb
123
- - lib/test_hook.rb
124
- - lib/version.rb
125
- homepage: http://github.com/mumuki/mumuki-python-server
154
+ homepage: http://github.com/mumuki/mumuki-python-runner
126
155
  licenses:
127
156
  - MIT
128
157
  metadata: {}
@@ -141,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
170
  - !ruby/object:Gem::Version
142
171
  version: '0'
143
172
  requirements: []
144
- rubygems_version: 3.0.2
173
+ rubygems_version: 3.0.8
145
174
  signing_key:
146
175
  specification_version: 4
147
176
  summary: Python Runner for Mumuki
@@ -1,3 +0,0 @@
1
- module PythonVersionHook
2
- VERSION = '1.4.0'
3
- end