Skip to content

Commit

Permalink
Quick fix to support changing what version of python to use
Browse files Browse the repository at this point in the history
  • Loading branch information
wil93 committed Dec 15, 2015
1 parent 354f577 commit a6136c9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions cms/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self):
self.temp_dir = "/tmp"
self.backdoor = False
self.file_log_debug = False
self.python_version = "2"

# Database.
self.database = "postgresql+psycopg2://cmsuser@localhost/cms"
Expand Down
25 changes: 15 additions & 10 deletions cms/grading/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,19 @@ def get_compilation_commands(language, source_filenames, executable_filename,
# The executable name is fixed, and there is no way to specify
# the name of the pyc, so we need to bundle together two
# commands (compilation and rename).
# In order to use Python 3 change them to:
# /usr/bin/python3 -m py_compile %s
# mv __pycache__/%s.*.pyc %s
py_command = ["/usr/bin/python2", "-m", "py_compile",
source_filenames[0]]
mv_command = ["/bin/mv", "%s.pyc" % os.path.splitext(os.path.basename(
source_filenames[0]))[0], executable_filename]
py_command = ["/usr/bin/python" + config.python_version, "-m",
"py_compile", source_filenames[0]]

basename = os.path.splitext(os.path.basename(
source_filenames[0]))[0]

if config.python_version == "3":
pyc_name = "__pycache__/%s.cpython-34.pyc" % basename
else:
pyc_name = "%s.pyc" % basename

mv_command = ["/bin/mv", pyc_name, executable_filename]

commands.append(py_command)
commands.append(mv_command)
elif language == LANG_PHP:
Expand Down Expand Up @@ -283,9 +289,8 @@ def get_evaluation_commands(language, executable_filename):
command = [os.path.join(".", executable_filename)]
commands.append(command)
elif language == LANG_PYTHON:
# In order to use Python 3 change it to:
# /usr/bin/python3 %s
command = ["/usr/bin/python2", executable_filename]
command = ["/usr/bin/python" + config.python_version,
executable_filename]
commands.append(command)
elif language == LANG_PHP:
command = ["/usr/bin/php5", executable_filename]
Expand Down
1 change: 1 addition & 0 deletions config/cms.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"_section": "System-wide configuration",

"temp_dir": "/tmp",
"python_version": "2",

"_help": "Whether to have a backdoor (see doc for the risks).",
"backdoor": false,
Expand Down
2 changes: 1 addition & 1 deletion docs/Configuring a contest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Language details

* Java programs are first compiled using ``gcj`` (optimized with ``-O3``), and then run as normal executables. Proper Java support using a JVM will most probably come in the next CMS version.

* Python submissions are interpreted using Python 2 (you need to have ``/usr/bin/python2``).
* Python submissions are interpreted using Python 2 (you need to have ``/usr/bin/python2``). If you want to use Python 3, you can set the ``python_version`` to ``"3"`` in your :file:`cms.conf` file.

* PHP submissions are interpreted by ``/usr/bin/php5``.

Expand Down

0 comments on commit a6136c9

Please sign in to comment.