Skip to content

Commit 39d272b

Browse files
melongistveluca93
andauthored
Add support for PyPy flavor of Python3 (#1206)
Co-authored-by: Luca Versari <[email protected]>
1 parent 9ef11a8 commit 39d272b

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
1717
openjdk-8-jdk-headless \
1818
php-cli \
1919
postgresql-client \
20+
pypy3 \
2021
python3-pip \
2122
python3.12 \
2223
python3.12-dev \
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__ = ["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]

cmstestsuite/Tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@
5050
LANG_PASCAL = "Pascal / fpc"
5151
LANG_PHP = "PHP"
5252
LANG_PYTHON3 = "Python 3 / CPython"
53+
LANG_PYPY3 = "Python 3 / PyPy"
5354
LANG_RUST = "Rust"
5455
LANG_C_SHARP = "C# / Mono"
5556
ALL_LANGUAGES = (
5657
LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_C, LANG_HS, LANG_JAVA, LANG_PASCAL,
57-
LANG_PHP, LANG_PYTHON3, LANG_RUST, LANG_C_SHARP
58+
LANG_PHP, LANG_PYTHON3, LANG_PYPY3, LANG_RUST, LANG_C_SHARP
5859
)
5960
NON_INTERPRETED_LANGUAGES = (
6061
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL
6162
)
6263
COMPILED_LANGUAGES = (
6364
LANG_C, LANG_CPP, LANG_CPP14, LANG_CPP17, LANG_CPP20, LANG_PASCAL, LANG_JAVA,
64-
LANG_PYTHON3, LANG_HS, LANG_RUST, LANG_C_SHARP
65+
LANG_PYTHON3, LANG_PYPY3, LANG_HS, LANG_RUST, LANG_C_SHARP
6566
)
6667

6768
ALL_TESTS = [

docs/Installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ On Ubuntu 24.04, one will need to run the following script to satisfy all depend
6464

6565
# Optional
6666
sudo apt-get install nginx-full php-cli texlive-latex-base \
67-
a2ps ghc rustc mono-mcs
67+
a2ps ghc rustc mono-mcs pypy3
6868

6969
The above commands provide a very essential Pascal environment. Consider installing the following packages for additional units: `fp-units-base`, `fp-units-fcl`, `fp-units-misc`, `fp-units-math` and `fp-units-rtl`.
7070

@@ -87,7 +87,7 @@ On Arch Linux, unofficial AUR packages can be found: `cms <http://aur.archlinux.
8787

8888
# Optional
8989
sudo pacman -S --needed nginx php php-fpm phppgadmin texlive-core \
90-
a2ps ghc rust mono
90+
a2ps ghc rust mono pypy3
9191

9292
Preparation steps
9393
=================

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def run(self):
193193
"Pascal / fpc=cms.grading.languages.pascal_fpc:PascalFpc",
194194
"PHP=cms.grading.languages.php:Php",
195195
"Python 3 / CPython=cms.grading.languages.python3_cpython:Python3CPython",
196+
"Python 3 / PyPy=cms.grading.languages.python3_pypy:Python3PyPy",
196197
"Rust=cms.grading.languages.rust:Rust",
197198
],
198199
},

0 commit comments

Comments
 (0)