Skip to content

Commit

Permalink
Added python3 PyPy support
Browse files Browse the repository at this point in the history
  • Loading branch information
PPakalns committed Oct 26, 2023
1 parent 48f5758 commit 92d4d26
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
83 changes: 83 additions & 0 deletions cms/grading/languages/python3_pypy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3

# Contest Management System - http://cms-dev.github.io/
# Copyright © 2016-2018 Stefano Maggiolo <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Python programming language, version 3, definition."""

import os

from cms.grading import CompiledLanguage


__all__ = ["Python3PyPy"]


class Python3PyPy(CompiledLanguage):
"""This defines the Python programming language, version 3 (more
precisely, the subversion of Python 3 available on the system)
using the default interpeter in the system.
"""

MAIN_FILENAME = "__main__.py"

@property
def name(self):
"""See Language.name."""
return "Python 3 / PyPy"

@property
def source_extensions(self):
"""See Language.source_extensions."""
return [".py"]

@property
def executable_extension(self):
"""See Language.executable.extension."""
# Defined in PEP 441 (https://www.python.org/dev/peps/pep-0441/).
return ".pyz"

def get_compilation_commands(self,
source_filenames, executable_filename,
for_evaluation=True):
"""See Language.get_compilation_commands."""

commands = []
files_to_package = []

# The file with the entry point must be in first position.
if source_filename := source_filenames.get(0):
commands.append(["/bin/mv", source_filename, self.MAIN_FILENAME])

commands.append(["/usr/bin/python3", "-m", "compileall", "-b", "."])
for idx, source_filename in enumerate(source_filenames):
if idx == 0:
source_filename = self.MAIN_FILENAME
basename = os.path.splitext(os.path.basename(source_filename))[0]
pyc_filename = "%s.pyc" % basename
files_to_package.append(pyc_filename)

commands.append(["/usr/bin/zip", executable_filename]
+ files_to_package)

return commands

def get_evaluation_commands(
self, executable_filename, main=None, args=None):
"""See Language.get_evaluation_commands."""
args = args if args is not None else []
return [["/usr/bin/pypy3", executable_filename] + args]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def run(self):
"PHP=cms.grading.languages.php:Php",
"Python 2 / CPython=cms.grading.languages.python2_cpython:Python2CPython",
"Python 3 / CPython=cms.grading.languages.python3_cpython:Python3CPython",
"Python 3 / PyPy=cms.grading.languages.python3_pypy:Python3PyPy",
"Rust=cms.grading.languages.rust:Rust",
"Go=cms.grading.languages.go:Go",
],
Expand Down

0 comments on commit 92d4d26

Please sign in to comment.