Skip to content

Commit 165bd69

Browse files
melongistveluca93
authored andcommitted
Support for pypy3
- Python 3 / PyPy3 support At "Allowed programming languages" - To use "Python 3 / PyPy3"? pypy3 installation required! #PyPy3 installaion needed before run setup.py #Like below ... sudo add-apt-repository ppa:pypy/ppa sudo apt update sudo apt install pypy3 ...
1 parent 40c0ef4 commit 165bd69

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
3+
# Contest Management System - http://cms-dev.github.io/
4+
# Copyright © 2016-2018 Stefano Maggiolo <[email protected]>
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Affero General Public License as
8+
# published by the Free Software Foundation, either version 3 of the
9+
# License, or (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Affero General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Affero General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
"""Python programming language, version 3, definition."""
20+
21+
import os
22+
23+
from cms.grading import CompiledLanguage
24+
25+
26+
__all__ = ["Python3PyPy3"]
27+
28+
29+
class Python3PyPy3(CompiledLanguage):
30+
"""This defines the Python programming language, version 3 (more
31+
precisely, the subversion of Python 3 available on the system)
32+
using the default interpeter in the system.
33+
34+
"""
35+
36+
MAIN_FILENAME = "__main__.pyc"
37+
38+
@property
39+
def name(self):
40+
"""See Language.name."""
41+
return "Python 3 / PyPy3"
42+
43+
@property
44+
def source_extensions(self):
45+
"""See Language.source_extensions."""
46+
return [".py"]
47+
48+
@property
49+
def executable_extension(self):
50+
"""See Language.executable.extension."""
51+
# Defined in PEP 441 (https://www.python.org/dev/peps/pep-0441/).
52+
return ".pyz"
53+
54+
def get_compilation_commands(self,
55+
source_filenames, executable_filename,
56+
for_evaluation=True):
57+
"""See Language.get_compilation_commands."""
58+
59+
commands = []
60+
files_to_package = []
61+
commands.append(["/usr/bin/pypy3", "-m", "compileall", "-b", "."])
62+
for idx, source_filename in enumerate(source_filenames):
63+
basename = os.path.splitext(os.path.basename(source_filename))[0]
64+
pyc_filename = "%s.pyc" % basename
65+
# The file with the entry point must be in first position.
66+
if idx == 0:
67+
commands.append(["/bin/mv", pyc_filename, self.MAIN_FILENAME])
68+
files_to_package.append(self.MAIN_FILENAME)
69+
else:
70+
files_to_package.append(pyc_filename)
71+
72+
commands.append(["/usr/bin/zip", executable_filename]
73+
+ files_to_package)
74+
75+
return commands
76+
77+
def get_evaluation_commands(
78+
self, executable_filename, main=None, args=None):
79+
"""See Language.get_evaluation_commands."""
80+
args = args if args is not None else []
81+
return [["/usr/bin/pypy3", executable_filename] + args]

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def run(self):
192192
"Pascal / fpc=cms.grading.languages.pascal_fpc:PascalFpc",
193193
"PHP=cms.grading.languages.php:Php",
194194
"Python 3 / CPython=cms.grading.languages.python3_cpython:Python3CPython",
195+
"Python 3 / PyPy3=cms.grading.languages.python3_pypy3:Python3PyPy3",
195196
"Rust=cms.grading.languages.rust:Rust",
196197
],
197198
},

0 commit comments

Comments
 (0)