Skip to content

Commit 47277d5

Browse files
committed
Remove dependencies on python2, move to python3
Also replace libmozjs with nodejs.
1 parent 307bcbf commit 47277d5

File tree

28 files changed

+84
-72
lines changed

28 files changed

+84
-72
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: python
22
python:
3-
- 2.7
43
- 3.7
54

65
script: py.test

Dockerfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:18.04
1+
FROM ubuntu:20.04
22

33
44

@@ -14,10 +14,10 @@ RUN apt-get update && \
1414
libgmp10 \
1515
libgmpxx4ldbl \
1616
openjdk-8-jdk \
17-
python-minimal \
18-
python-pip \
19-
python-plastex \
20-
python-yaml \
17+
python3-minimal \
18+
python3-pip \
19+
python3-plastex \
20+
python3-yaml \
2121
sudo \
2222
texlive-fonts-recommended \
2323
texlive-lang-cyrillic \
@@ -26,4 +26,4 @@ RUN apt-get update && \
2626
tidy \
2727
vim
2828

29-
RUN pip install git+https://github.com/kattis/problemtools
29+
RUN pip3 install git+https://github.com/ghamerly/problemtools@move-to-py3

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ There are four recommended ways of installing and running problemtools.
3535

3636
Run
3737
```
38-
pip install git+https://github.com/kattis/problemtools
38+
pip3 install git+https://github.com/kattis/problemtools
3939
```
4040

4141
Or if you don't want a system-wide installation,
4242
```
43-
pip install --user git+https://github.com/kattis/problemtools
43+
pip3 install --user git+https://github.com/kattis/problemtools
4444
```
4545
With this second option, in order to get the command line scripts, you need
4646
to make sure that the local user bin path used (e.g., on Linux,
@@ -153,18 +153,18 @@ problemtools' configuration:
153153
154154
1. `languages.yaml`. Use it to override problemtools' default
155155
programming language configuration. For instance, while the
156-
problemtools default is to use the CPython `/usr/bin/python2`
157-
interpreter for Python 2, many contests, as well as the Kattis
158-
online judge, use Pypy as the interpreter for Python 2. To change
156+
problemtools default is to use the CPython `/usr/bin/python3`
157+
interpreter for Python 3, many contests, as well as the Kattis
158+
online judge, use Pypy as the interpreter for Python 3. To change
159159
this on your machine, you can simply place a file
160160
`/etc/kattis/problemtools/languages.yaml` (or
161161
`~/.config/problemtools/languages.yaml` if you only want to make the
162162
change for your user) containing the following:
163163
164164
```yaml
165-
python2:
166-
name: 'Python 2 w/Pypy'
167-
run: '/usr/bin/pypy "{mainfile}"'
165+
python3:
166+
name: 'Python 3 w/Pypy'
167+
run: '/usr/bin/pypy3 "{mainfile}"'
168168
```
169169
Here, overriding the name of the language is not strictly
170170
necessary, but it is often helpful to clearly indicate that Pypy is
@@ -196,14 +196,14 @@ problemtools' configuration:
196196
197197
## Requirements and compatibility
198198
199-
To build and run the tools, you need Python 2 with the YAML and PlasTeX libraries,
199+
To build and run the tools, you need Python 3 with the YAML and PlasTeX libraries,
200200
and a LaTeX installation.
201201
202202
### Ubuntu
203203
204204
The dependencies needed to *build/install* problemtools can be installed with:
205205
206-
sudo apt install automake g++ make libboost-regex-dev libgmp-dev libgmp10 libgmpxx4ldbl python python-pytest python-setuptools python-yaml
206+
sudo apt install automake g++ make libboost-regex-dev libgmp-dev libgmp10 libgmpxx4ldbl python3 python3-pytest python3-setuptools python3-yaml python3-plastex
207207
208208
And the dependencies needed to *run* problemtools can be installed with:
209209
@@ -213,11 +213,11 @@ And the dependencies needed to *run* problemtools can be installed with:
213213
214214
On Fedora, these dependencies can be installed with:
215215
216-
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
216+
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
217217
218218
Followed by:
219219
220-
pip2 install --user plastex
220+
pip3 install --user plastex
221221
222222
### Other platforms
223223

admin/docker/Dockerfile.build

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# version of problemtools to be built (default is latest version of
66
# develop branch on GitHub)
77

8-
FROM ubuntu:18.04
8+
FROM ubuntu:20.04
99

1010
LABEL maintainer="[email protected]"
1111

@@ -29,10 +29,7 @@ RUN apt update && \
2929
python3-pytest \
3030
python3-setuptools \
3131
python3-yaml \
32-
python \
33-
python-pytest \
34-
python-setuptools \
35-
python-yaml
32+
python3-setuptools
3633

3734
RUN mkdir -p /usr/local/problemtools_build
3835

admin/docker/Dockerfile.full

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RUN apt-get update && \
2020
swi-prolog \
2121
scala \
2222
sbcl \
23+
nodejs \
2324
ocaml-nox \
2425
rustc \
25-
;
26+
;

admin/docker/Dockerfile.icpc

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN apt update && \
1818
g++ \
1919
openjdk-11-jdk \
2020
pypy \
21-
python3
21+
pypy3
2222

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

2929
# Reconfigure problemtools:
3030
# - Use PyPy for Python 2
31+
# - Use PyPy for Python 3
3132
# - Use /usr/local/bin rather than /usr/bin for Kotlin
3233
RUN mkdir -p /etc/kattis/problemtools
3334
RUN echo " \n\
3435
python2: \n\
3536
name: 'Python 2 w/PyPy'\n\
3637
run: '/usr/bin/pypy \"{mainfile}\"'\n\
3738
\n\
39+
python3: \n\
40+
name: 'Python 3 w/PyPy'\n\
41+
run: '/usr/bin/pypy3 \"{mainfile}\"'\n\
42+
\n\
3843
kotlin: \n\
3944
compile: '/usr/local/bin/kotlinc -d {path}/ -- {files}' \n\
4045
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
4146

42-
WORKDIR /
47+
WORKDIR /

admin/docker/Dockerfile.minimal

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Minimalistic problemtools docker image, containing only problemtools
22
# and its dependencies, no languages (except whichever are
3-
# dependencies of problemtools, e.g. Python 2)
3+
# dependencies of problemtools, e.g. Python 3)
44
#
55
# Build requirements:
66
# - The problemtools .deb package must be available from the host file
@@ -10,7 +10,7 @@
1010
# PROBLEMTOOLS_VERSION but this is not checked.)
1111

1212
ARG PROBLEMTOOLS_VERSION=develop
13-
FROM ubuntu:18.04
13+
FROM ubuntu:20.04
1414

1515
LABEL maintainer="[email protected]"
1616

@@ -20,12 +20,10 @@ RUN apt update && \
2020
apt install -y \
2121
ghostscript \
2222
libgmpxx4ldbl \
23-
python-minimal \
2423
python-pkg-resources \
25-
python-plastex \
26-
python-yaml \
2724
python3-minimal \
2825
python3-yaml \
26+
python3-plastex \
2927
texlive-fonts-recommended \
3028
texlive-lang-cyrillic \
3129
texlive-latex-extra \

bin/problem2html.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
export PYTHONPATH
99
PYTHONPATH="$(dirname "$(dirname "$(readlink -f "$0")")"):$PYTHONPATH"
10-
exec python2 -m problemtools.problem2html "$@"
10+
exec python3 -m problemtools.problem2html "$@"

bin/problem2pdf.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
export PYTHONPATH
99
PYTHONPATH="$(dirname "$(dirname "$(readlink -f "$0")")"):$PYTHONPATH"
10-
exec python2 -m problemtools.problem2pdf "$@"
10+
exec python3 -m problemtools.problem2pdf "$@"

bin/verifyproblem.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
export PYTHONPATH
99
PYTHONPATH="$(dirname "$(dirname "$(readlink -f "$0")")"):$PYTHONPATH"
10-
exec python2 -m problemtools.verifyproblem "$@"
10+
exec python3 -m problemtools.verifyproblem "$@"

debian/control

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ Source: kattis-problemtools
22
Section: devel
33
Priority: optional
44
Maintainer: Per Austrin <[email protected]>
5-
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
5+
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
66
Standards-Version: 3.9.4
77
Homepage: https://github.com/Kattis/problemtools
88

99
Package: kattis-problemtools
1010
Architecture: any
11-
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
11+
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
1212
Recommends: gcc, g++
1313
Description: Kattis Problem Tools
1414
These are tools to manage and verify problem packages in the

debian/rules

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,5 @@ export PYBUILD_AFTER_CLEAN=make -C support distclean
1111
export PYBUILD_TEST_PYTEST=1
1212
export no_proxy=github.com
1313

14-
# FIXME: while we're building for both py2 and py3, we get a clash
15-
# with the CLI scripts. The following Workaround puts the py3 CLI
16-
# scripts somewhere else where they don't do any harm, so that the
17-
# main CLI scripts are the py2 ones for now. Once we drop py2 support
18-
# we also drop this line.
19-
export PYBUILD_INSTALL_ARGS_python3=--install-scripts=/usr/lib/problemtools/bin/
20-
2114
%:
22-
dh $@ --with python3,python2 --buildsystem=pybuild
15+
dh $@ --with python3 --buildsystem=pybuild

examples/different/input_format_validators/validate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python3
22
from sys import stdin
33
import sys
44
import re
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
var line;
1+
const readline = require('readline');
22

3-
while (line = readline()) {
3+
const rl = readline.createInterface({
4+
input: process.stdin,
5+
output: process.stdout
6+
});
7+
8+
rl.on('line', (line) => {
49
var nums = line.split(' ');
510
var a = parseInt(nums[0]);
611
var b = parseInt(nums[1]);
712
var res = Math.abs(a - b);
8-
print(res);
9-
}
13+
console.log(res);
14+
});

examples/different/submissions/accepted/different.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python2
2+
13
import sys
24

35
for line in sys.stdin:

examples/different/submissions/accepted/different_py3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/python3
1+
#!/usr/bin/env python3
22

33
import sys
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#! /usr/bin/python3
2+
3+
import sys
4+
5+
for line in sys.stdin:
6+
ab = line.split()
7+
a = int(ab[0])
8+
b = int(ab[1])
9+
# needless loop just to be slow
10+
x = a
11+
for _ in range(100000000):
12+
x += 1
13+
diff = abs(a-b) + x - x
14+
15+
print(diff)

examples/guess/input_format_validators/validate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python3
22
from sys import stdin
33
import sys
44
import re
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python3
22

3-
print "500"
3+
print("500")

examples/hello/input_format_validators/validate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
from sys import stdin
33
import sys
44

Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
print 'Hello World!'
1+
#!/usr/bin/env python3
2+
3+
print('Hello World!')

problemtools/config/languages.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ javascript:
154154
name: 'JavaScript'
155155
priority: 500
156156
files: '*.js'
157-
compile: '/usr/bin/js24 -c {files}'
158-
run: '/usr/bin/js24 "{mainfile}"'
157+
compile: '/usr/bin/nodejs -c {files}'
158+
run: '/usr/bin/nodejs "{mainfile}"'
159159

160160
kotlin:
161161
name: 'Kotlin'

problemtools/problem2html.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env python2
1+
#! /usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
from __future__ import print_function
44
import re
@@ -39,11 +39,7 @@ def convert(problem, options=None):
3939

4040
# Setup parser and renderer etc
4141

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

4844
ProblemsetMacros.init(tex)
4945

problemtools/problem2pdf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env python2
1+
#! /usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
import re
44
import os.path

problemtools/tests/test_languages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_missing_run(self):
145145

146146
def test_invalid_run(self):
147147
vals = self.__language_dict()
148-
vals['run'] = ['python2', '{mainfile}']
148+
vals['run'] = ['python3', '{mainfile}']
149149
with pytest.raises(languages.LanguageConfigError):
150150
languages.Language('id', vals)
151151
vals['run'] = 'echo {nonexistent}'

problemtools/verifyproblem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env python2
1+
#! /usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
from __future__ import print_function
44
import glob

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22

33
from setuptools import setup, find_packages
44
from setuptools.command.bdist_egg import bdist_egg as _bdist_egg
@@ -81,7 +81,6 @@ def get_version():
8181
include_package_data=True,
8282
install_requires=[
8383
'PyYAML',
84-
'plasTeX<=1.0;python_version<"3"',
8584
'plasTeX>=2.0;python_version>="3"'
8685
],
8786
# Temporarily disabled, see setup.cfg

0 commit comments

Comments
 (0)