Skip to main content

Simple python script converting polygon package to domjudge(kattis) package

Project description

Polygon2DOMjudge

Test GitHub release

中文

What is this

It is a simple python script converting polygon package to DOMjudge (kattis) package.

Install

From PyPI (stable release, has been used in some contests)

pipx install p2d

From source (latest version, under development with new features)

pipx install git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge

CLI Example

First, you should build full package from Polygon and download the Linux package to your local.

[!WARNING] If you download the standard package and then run doall.sh to build the full package by yourself, the linebreaks will be CRLF. Make sure you convert the linebreaks to LF before running the script because DOMjudge is running on Linux.

# Download the full package from Polygon to /path/to/polygon-package.zip
$ p2d --code A --color "#FF0000" -o /path/to/domjudge-package.zip /path/to/polygon-package.zip

Run this command to make a package from /path/to/polygon-package.zip to /path/to/domjudge-package.zip and set code and color.

You can omit the output path, and the default output path will be in the current working directory and named as {{ code }}.zip.

All available parameters are:

  • --code: problem short name in DOMjudge contest.
  • --color: problem color in DOMjudge.
  • --default: force use the default output validator.
  • --validator-flags: add some flags to the output validator, only works when --default is set.
  • --auto: use the default output validator if the checker is defined in config and can be replaced by the default one.
  • --memory-limit: override the memory limit for DOMjudge package (in MB), default is using the memory limit defined in polygon package.
  • --output-limit: override the output limit for DOMjudge package (in MB), default is using the default output limit in DOMjudge setting.
  • --hide-sample: hide the sample input and output from the problem statement, no sample data will be available for the contestants (force True if this is an interactive problem). When this is not set to True and the sample output is different from the main and correct solution (usually both are correct answers), the sample output will be replaced with the one shipped with problem statement. But the sample input will not be replaced because DOMjudge does not support different sample input from the one downloaded.
  • --keep-sample: keep the sample output from the main and correct solution, this is useful when the sample output from problem statement is a placeholder. (By default, all sample output will be replaced with the one shipped with problem statement)
  • --external-id: specify the external id of the problem in DOMjudge, default is using the problem short-name in polygon.
  • --with-statement: include the pdf statement in the DOMjudge package.
  • --with-attachments: include attachments (e.g. local testing tools for interactive problem) in the DOMjudge package.
  • --testset: specify the testset to convert, must specify the testset name if the problem has multiple testsets.

Convert the whole contest

You can use p2d-contest to get a script to convert all problems in a contest.

# Download the contest.xml from Polygon first
$ p2d-contest /path/to/contest.xml > convert.sh

Config

In config.toml, you can change some special checker's validator's flags, which will be used to replace the checker with the default output validator when --auto is set.

[!NOTE] You should create a new file named config.toml or something else and pass it to the script with --config parameter. The script will merge the default config with your config.

Environment Variable

Don't change them unless you know what you are doing.

  • TESTLIB_PATH

API Example

[!WARNING] The API is not stable and may change in the future.

This is an example to convert all problems in a contest defined in problems.yaml to DOMjudge package.

import yaml
from pathlib import Path

from p2d import convert

polygon = Path('/path/to/polygon-packages')
domjudge = Path('/path/to/domjudge-packages')

with open(domjudge / 'problems.yaml') as f:
    problems = yaml.safe_load(f)

for problem in problems:
    prob_id = problem['id']
    convert(
        polygon / f'{prob_id}.zip',
        domjudge / f'{prob_id}.zip',
        short_name=problem['label'],
        color=problem['rgb'],
    )

Known Issues

  • For interactive problems, you must validate the output in the interactors, because DOMjudge cannot handle tout stream like Polygon.
  • For multi-pass problems
    • Some logic are different from Polygon, you may need to modify it to fit the DOMjudge environment, DOMjudge will use -DDOMJUDGE macro to distinguish whether it is in DOMjudge environment, so you can use it to adapt your code.
    • You may need to call tout.open(make_new_file_in_a_dir(argv[3], "nextpass.in")) to get the next pass input file when there exists a next pass.

Development

# install
uv sync

# build
uv build

# run unittest
uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p2d-0.4.0rc1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

p2d-0.4.0rc1-py3-none-any.whl (57.8 kB view details)

Uploaded Python 3

File details

Details for the file p2d-0.4.0rc1.tar.gz.

File metadata

  • Download URL: p2d-0.4.0rc1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for p2d-0.4.0rc1.tar.gz
Algorithm Hash digest
SHA256 19c4f382932090fe800963e692081d432b2fe7b909e561bb52ba98bfedbaf952
MD5 5097d73824d93f108b1a2d1eca9182e9
BLAKE2b-256 e992d2e4dc58c7a69530374fccfbc69a9ac9a10b6dcab9a74af9dd6b42e2b547

See more details on using hashes here.

File details

Details for the file p2d-0.4.0rc1-py3-none-any.whl.

File metadata

  • Download URL: p2d-0.4.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 57.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for p2d-0.4.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 f19f2a25607d18f0fc1dc105fafb0e06dc8bf679d75cc9ac9b245f877a17bbc2
MD5 c5fb42bd0d6564d67198cf9c883de38b
BLAKE2b-256 ab3f984b3398405820a6de7d24cb5e0c8dbe35728b91d617343fc40ebc2960f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page