Skip to content

Instantly share code, notes, and snippets.

@mogproject
Last active October 6, 2023 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogproject/cec1dfc7b61fc8928ca08e8632e1e25c to your computer and use it in GitHub Desktop.
Save mogproject/cec1dfc7b61fc8928ca08e8632e1e25c to your computer and use it in GitHub Desktop.
How to set up PyPy 3 for problemtools/icpc on Docker

0. Assumptions

  • This document is about Method 2 on https://github.com/Kattis/problemtools
  • Replace REPO with the path to your local clone of the GitHub repository.
  • Assume the REPO contains the problems directory.

1. Set up Docker image

  • Install and start Docker Desktop
  • Download image: docker pull problemtools/icpc

2. Install PyPy

  • Download PyPy 7.3.9 for Python 3.8: https://downloads.python.org/pypy/
  • Move the downloaded file (pypy3.8-v7.3.9-linux64.tar.bz2) to the REPO/problems directory
  • Run container in the REPO directory: docker run --rm -it -v ${PWD}/problems:/kattis_work_dir problemtools/icpc
  • Run the following commands inside the container (do not terminate until you save as image):
# mv -i /kattis_work_dir/pypy3.8-v7.3.9-linux64.tar.bz2 /tmp
# cd /tmp
# tar xf pypy3.8-v7.3.9-linux64.tar.bz2
# mv -i pypy3.8-v7.3.9-linux64 /usr/share
# ln -s /usr/share/pypy3.8-v7.3.9-linux64/bin/pypy3.8 /usr/bin/pypy3
# rm -i pypy3.8-v7.3.9-linux64.tar.bz2
# pypy3 --version
Warning: cannot find your CPU L2 cache size in /proc/cpuinfo
Python 3.8.13 (4b1398fe9d76ad762155d03684c2a153d230b2ef, Mar 29 2022, 07:08:24)
[PyPy 7.3.9 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)]

3. Language settings

  • Continue to work inside the container:
# mkdir -p /etc/kattis/problemtools
# cat >> /etc/kattis/problemtools/languages.yaml

python3:
    name: 'Python 3 w/PyPy'
    run: '/usr/bin/pypy3 "{mainfile}"'

(press Ctrl-D)

(The image does not include an editor.)

  • Save the updated container as an image:
    • docker ps: check for CONTAINER_ID
    • docker commit <CONTAINER_ID> problemtools/icpc

4. Use PyPy for testing submissions

  • The first line of your Python submission code should be: #!/usr/bin/env python3
  • In the container, run: verifyproblem <PROBLEM_NAME>
    • You should see: Checking submissions ... Running <PROBLEM_NAME>.py (Python 3 w/PyPy) on test case...
    • Check only submissions: verifyproblem <PROBLEM_NAME> -p submissions
    • See verifyproblem --help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment