Skip to content

Commit

Permalink
Remove dependencies on python2, move to python3
Browse files Browse the repository at this point in the history
Also replace libmozjs with nodejs.
  • Loading branch information
ghamerly committed Jun 10, 2020
1 parent 307bcbf commit 47277d5
Show file tree
Hide file tree
Showing 28 changed files with 84 additions and 72 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- 2.7
- 3.7

script: py.test
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:18.04
FROM ubuntu:20.04

MAINTAINER [email protected]

Expand All @@ -14,10 +14,10 @@ RUN apt-get update && \
libgmp10 \
libgmpxx4ldbl \
openjdk-8-jdk \
python-minimal \
python-pip \
python-plastex \
python-yaml \
python3-minimal \
python3-pip \
python3-plastex \
python3-yaml \
sudo \
texlive-fonts-recommended \
texlive-lang-cyrillic \
Expand All @@ -26,4 +26,4 @@ RUN apt-get update && \
tidy \
vim

RUN pip install git+https://github.com/kattis/problemtools
RUN pip3 install git+https://github.com/ghamerly/problemtools@move-to-py3
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ There are four recommended ways of installing and running problemtools.

Run
```
pip install git+https://github.com/kattis/problemtools
pip3 install git+https://github.com/kattis/problemtools
```

Or if you don't want a system-wide installation,
```
pip install --user git+https://github.com/kattis/problemtools
pip3 install --user git+https://github.com/kattis/problemtools
```
With this second option, in order to get the command line scripts, you need
to make sure that the local user bin path used (e.g., on Linux,
Expand Down Expand Up @@ -153,18 +153,18 @@ problemtools' configuration:
1. `languages.yaml`. Use it to override problemtools' default
programming language configuration. For instance, while the
problemtools default is to use the CPython `/usr/bin/python2`
interpreter for Python 2, many contests, as well as the Kattis
online judge, use Pypy as the interpreter for Python 2. To change
problemtools default is to use the CPython `/usr/bin/python3`
interpreter for Python 3, many contests, as well as the Kattis
online judge, use Pypy as the interpreter for Python 3. To change
this on your machine, you can simply place a file
`/etc/kattis/problemtools/languages.yaml` (or
`~/.config/problemtools/languages.yaml` if you only want to make the
change for your user) containing the following:
```yaml
python2:
name: 'Python 2 w/Pypy'
run: '/usr/bin/pypy "{mainfile}"'
python3:
name: 'Python 3 w/Pypy'
run: '/usr/bin/pypy3 "{mainfile}"'
```
Here, overriding the name of the language is not strictly
necessary, but it is often helpful to clearly indicate that Pypy is
Expand Down Expand Up @@ -196,14 +196,14 @@ problemtools' configuration:
## Requirements and compatibility
To build and run the tools, you need Python 2 with the YAML and PlasTeX libraries,
To build and run the tools, you need Python 3 with the YAML and PlasTeX libraries,
and a LaTeX installation.
### Ubuntu
The dependencies needed to *build/install* problemtools can be installed with:
sudo apt install automake g++ make libboost-regex-dev libgmp-dev libgmp10 libgmpxx4ldbl python python-pytest python-setuptools python-yaml
sudo apt install automake g++ make libboost-regex-dev libgmp-dev libgmp10 libgmpxx4ldbl python3 python3-pytest python3-setuptools python3-yaml python3-plastex
And the dependencies needed to *run* problemtools can be installed with:
Expand All @@ -213,11 +213,11 @@ And the dependencies needed to *run* problemtools can be installed with:
On Fedora, these dependencies can be installed with:
sudo dnf install boost-regex gcc gmp-devel gmp-c++ python2 python2-pyyaml texlive-latex texlive-collection-fontsrecommended texlive-fancyhdr texlive-subfigure texlive-wrapfig texlive-import texlive-ulem texlive-xifthen texlive-overpic texlive-pbox tidy ghostscript
sudo dnf install boost-regex gcc gmp-devel gmp-c++ python3 python3-pyyaml texlive-latex texlive-collection-fontsrecommended texlive-fancyhdr texlive-subfigure texlive-wrapfig texlive-import texlive-ulem texlive-xifthen texlive-overpic texlive-pbox tidy ghostscript
Followed by:
pip2 install --user plastex
pip3 install --user plastex
### Other platforms
Expand Down
7 changes: 2 additions & 5 deletions admin/docker/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# version of problemtools to be built (default is latest version of
# develop branch on GitHub)

FROM ubuntu:18.04
FROM ubuntu:20.04

LABEL maintainer="[email protected]"

Expand All @@ -29,10 +29,7 @@ RUN apt update && \
python3-pytest \
python3-setuptools \
python3-yaml \
python \
python-pytest \
python-setuptools \
python-yaml
python3-setuptools

RUN mkdir -p /usr/local/problemtools_build

Expand Down
3 changes: 2 additions & 1 deletion admin/docker/Dockerfile.full
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RUN apt-get update && \
swi-prolog \
scala \
sbcl \
nodejs \
ocaml-nox \
rustc \
;
;
9 changes: 7 additions & 2 deletions admin/docker/Dockerfile.icpc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt update && \
g++ \
openjdk-11-jdk \
pypy \
python3
pypy3

# Install Kotlin
WORKDIR /usr/local
Expand All @@ -28,15 +28,20 @@ RUN ln -s /usr/local/kotlinc/bin/* bin/

# Reconfigure problemtools:
# - Use PyPy for Python 2
# - Use PyPy for Python 3
# - Use /usr/local/bin rather than /usr/bin for Kotlin
RUN mkdir -p /etc/kattis/problemtools
RUN echo " \n\
python2: \n\
name: 'Python 2 w/PyPy'\n\
run: '/usr/bin/pypy \"{mainfile}\"'\n\
\n\
python3: \n\
name: 'Python 3 w/PyPy'\n\
run: '/usr/bin/pypy3 \"{mainfile}\"'\n\
\n\
kotlin: \n\
compile: '/usr/local/bin/kotlinc -d {path}/ -- {files}' \n\
run: '/usr/local/bin/kotlin -Dfile.encoding=UTF-8 -J-XX:+UseSerialGC -J-Xss64m -J-Xms{memlim}m -J-Xmx{memlim}m -cp {path}/ {Mainclass}Kt' " > /etc/kattis/problemtools/languages.yaml

WORKDIR /
WORKDIR /
8 changes: 3 additions & 5 deletions admin/docker/Dockerfile.minimal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Minimalistic problemtools docker image, containing only problemtools
# and its dependencies, no languages (except whichever are
# dependencies of problemtools, e.g. Python 2)
# dependencies of problemtools, e.g. Python 3)
#
# Build requirements:
# - The problemtools .deb package must be available from the host file
Expand All @@ -10,7 +10,7 @@
# PROBLEMTOOLS_VERSION but this is not checked.)

ARG PROBLEMTOOLS_VERSION=develop
FROM ubuntu:18.04
FROM ubuntu:20.04

LABEL maintainer="[email protected]"

Expand All @@ -20,12 +20,10 @@ RUN apt update && \
apt install -y \
ghostscript \
libgmpxx4ldbl \
python-minimal \
python-pkg-resources \
python-plastex \
python-yaml \
python3-minimal \
python3-yaml \
python3-plastex \
texlive-fonts-recommended \
texlive-lang-cyrillic \
texlive-latex-extra \
Expand Down
2 changes: 1 addition & 1 deletion bin/problem2html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

export PYTHONPATH
PYTHONPATH="$(dirname "$(dirname "$(readlink -f "$0")")"):$PYTHONPATH"
exec python2 -m problemtools.problem2html "$@"
exec python3 -m problemtools.problem2html "$@"
2 changes: 1 addition & 1 deletion bin/problem2pdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

export PYTHONPATH
PYTHONPATH="$(dirname "$(dirname "$(readlink -f "$0")")"):$PYTHONPATH"
exec python2 -m problemtools.problem2pdf "$@"
exec python3 -m problemtools.problem2pdf "$@"
2 changes: 1 addition & 1 deletion bin/verifyproblem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

export PYTHONPATH
PYTHONPATH="$(dirname "$(dirname "$(readlink -f "$0")")"):$PYTHONPATH"
exec python2 -m problemtools.verifyproblem "$@"
exec python3 -m problemtools.verifyproblem "$@"
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Source: kattis-problemtools
Section: devel
Priority: optional
Maintainer: Per Austrin <[email protected]>
Build-Depends: debhelper (>= 8.0.0), g++ (>= 4.8), dh-python, python3, python3-setuptools, python3-pytest, python3-yaml, python (>= 2.6.6-3~), python-setuptools, python-pytest, python-yaml, libboost-regex-dev, libgmp-dev, automake, autoconf
Build-Depends: debhelper (>= 8.0.0), g++ (>= 4.8), dh-python, python3, python3-setuptools, python3-pytest, python3-yaml, python3-setuptools, python3-pytest, libboost-regex-dev, libgmp-dev, automake, autoconf
Standards-Version: 3.9.4
Homepage: https://github.com/Kattis/problemtools

Package: kattis-problemtools
Architecture: any
Depends: ${shlibs:Depends}, ${python:Depends}, ${python3:Depends}, ${misc:Depends}, python-yaml, plastex, python3-plastex, python-pkg-resources, texlive-plain-generic, texlive-fonts-recommended, texlive-latex-extra, texlive-lang-cyrillic, tidy, ghostscript
Depends: ${shlibs:Depends}, ${python3:Depends}, ${misc:Depends}, python3-plastex, python-pkg-resources, texlive-plain-generic, texlive-fonts-recommended, texlive-latex-extra, texlive-lang-cyrillic, tidy, ghostscript
Recommends: gcc, g++
Description: Kattis Problem Tools
These are tools to manage and verify problem packages in the
Expand Down
9 changes: 1 addition & 8 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,5 @@ export PYBUILD_AFTER_CLEAN=make -C support distclean
export PYBUILD_TEST_PYTEST=1
export no_proxy=github.com

# FIXME: while we're building for both py2 and py3, we get a clash
# with the CLI scripts. The following Workaround puts the py3 CLI
# scripts somewhere else where they don't do any harm, so that the
# main CLI scripts are the py2 ones for now. Once we drop py2 support
# we also drop this line.
export PYBUILD_INSTALL_ARGS_python3=--install-scripts=/usr/lib/problemtools/bin/

%:
dh $@ --with python3,python2 --buildsystem=pybuild
dh $@ --with python3 --buildsystem=pybuild
2 changes: 1 addition & 1 deletion examples/different/input_format_validators/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
from sys import stdin
import sys
import re
Expand Down
13 changes: 9 additions & 4 deletions examples/different/submissions/accepted/different.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
var line;
const readline = require('readline');

while (line = readline()) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.on('line', (line) => {
var nums = line.split(' ');
var a = parseInt(nums[0]);
var b = parseInt(nums[1]);
var res = Math.abs(a - b);
print(res);
}
console.log(res);
});
2 changes: 2 additions & 0 deletions examples/different/submissions/accepted/different.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python2

import sys

for line in sys.stdin:
Expand Down
2 changes: 1 addition & 1 deletion examples/different/submissions/accepted/different_py3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python3
#!/usr/bin/env python3

import sys

Expand Down
15 changes: 15 additions & 0 deletions examples/different/submissions/slow_accepted/different_slow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/python3

import sys

for line in sys.stdin:
ab = line.split()
a = int(ab[0])
b = int(ab[1])
# needless loop just to be slow
x = a
for _ in range(100000000):
x += 1
diff = abs(a-b) + x - x

print(diff)
2 changes: 1 addition & 1 deletion examples/guess/input_format_validators/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
from sys import stdin
import sys
import re
Expand Down
4 changes: 2 additions & 2 deletions examples/guess/submissions/wrong_answer/guess.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/python
#!/usr/bin/env python3

print "500"
print("500")
2 changes: 1 addition & 1 deletion examples/hello/input_format_validators/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
from sys import stdin
import sys

Expand Down
4 changes: 3 additions & 1 deletion examples/hello/submissions/accepted/hello.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
print 'Hello World!'
#!/usr/bin/env python3

print('Hello World!')
4 changes: 2 additions & 2 deletions problemtools/config/languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ javascript:
name: 'JavaScript'
priority: 500
files: '*.js'
compile: '/usr/bin/js24 -c {files}'
run: '/usr/bin/js24 "{mainfile}"'
compile: '/usr/bin/nodejs -c {files}'
run: '/usr/bin/nodejs "{mainfile}"'

kotlin:
name: 'Kotlin'
Expand Down
8 changes: 2 additions & 6 deletions problemtools/problem2html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python2
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import re
Expand Down Expand Up @@ -39,11 +39,7 @@ def convert(problem, options=None):

# Setup parser and renderer etc

# Python 2 compatibility: the second keyword argument for th TeX
# class changed name from file to myfile in Python 3 version. When
# Python 2 compatibility is dropped, change this to "tex =
# TeX(myfile=texfile)".
tex = TeX(None, texfile)
tex = TeX(myfile=texfile)

ProblemsetMacros.init(tex)

Expand Down
2 changes: 1 addition & 1 deletion problemtools/problem2pdf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python2
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import os.path
Expand Down
2 changes: 1 addition & 1 deletion problemtools/tests/test_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_missing_run(self):

def test_invalid_run(self):
vals = self.__language_dict()
vals['run'] = ['python2', '{mainfile}']
vals['run'] = ['python3', '{mainfile}']
with pytest.raises(languages.LanguageConfigError):
languages.Language('id', vals)
vals['run'] = 'echo {nonexistent}'
Expand Down
2 changes: 1 addition & 1 deletion problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python2
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import glob
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

from setuptools import setup, find_packages
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
Expand Down Expand Up @@ -81,7 +81,6 @@ def get_version():
include_package_data=True,
install_requires=[
'PyYAML',
'plasTeX<=1.0;python_version<"3"',
'plasTeX>=2.0;python_version>="3"'
],
# Temporarily disabled, see setup.cfg
Expand Down
Loading

0 comments on commit 47277d5

Please sign in to comment.