Skip to main content

Polygon2DOMjudge

Test GitHub release

中文

What is this

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

Install

Run directly with uvx

# From PyPI (stable)
uvx p2d --help

# From GitHub (latest)
uvx --from git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge p2d --help

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

# Using uv (recommended)
uv tool install p2d

# Or using pipx
pipx install p2d

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

# Using uv (recommended)
uv tool install git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge

# Or using pipx
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.

# 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.

Environment Variable

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

  • TESTLIB_PATH

API Example

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"), std::ios_base::out) to create the next pass input file when there exists a next pass.

Development

# install
uv sync

# build
uv build

# run unittest
uv run pytest

Metadata

Release files for p2d 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for p2d 0.4.1
File Size Uploaded Provenance Actions
p2d-0.4.1.tar.gz 1.5 MB Without provenance Details for p2d-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for p2d 0.4.1
File Interpreter ABI Platform Actions
p2d-0.4.1-py3-none-any.whl Python 3 none any Details for p2d-0.4.1-py3-none-any.whl

Total release size: 1.5 MB

Release files / p2d-0.4.1.tar.gz

Download URL p2d-0.4.1.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
43b6d9a59cd7e6d757855b76876b0111aa92016d115dd60b65758b8ceb65a522
BLAKE2b-256 checksum
How to use checksums
16be3d53e2cac35bf63b59d1bca063686779c156c06bdced6935c3449afaf889
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / p2d-0.4.1-py3-none-any.whl

Download URL p2d-0.4.1-py3-none-any.whl
Size 68.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ec1977f25925cc721031e0c6e66d4ac9f2cc42173d73119aa61eef3aa37fb0f
BLAKE2b-256 checksum
How to use checksums
c1111a642a6116afb47d46a87ff15d316a64d8ad14457508024a1598f9c5a9bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for p2d 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page