|
| 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__ = ["Python3PyPy"] |
| 27 | + |
| 28 | + |
| 29 | +class Python3PyPy(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 PyPy 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 / PyPy" |
| 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] |
0 commit comments