Simple python script converting polygon package to domjudge(kattis) package
Project description
Polygon2DOMjudge
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
# Unzip your polygon-package to /path/to/polygon-package first
$ p2d --code A --color "#FF0000" -o /path/to/domjudge-package /path/to/polygon-package
# Or you can use /path/to/polygon-package.zip directly
$ p2d --code A --color "#FF0000" -o /path/to/domjudge-package /path/to/polygon-package.zip
Run this command to make a package from /path/to/polygon-package
to /path/to/domjudge-package.zip
and set code
and color
.
All available parameters are:
--code
: problem short name in DOMjudge.--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, the sample output will be replaced with the one shipped with problem statement.--testset
: specify the testset to convert, must specify the testset name if the problem has multiple testsets.
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 not edit this file directly, instead, 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.
CONFIG_PATH
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',
code=problem['label'],
color=problem['rgb'],
)
Development
# install
poetry install
# build
poetry build
# run unittest
poetry run pytest
# release
./release.sh ${your version}
Polygon2DOMjudge
这是什么
这是一个简单的将 polygon 题目包转换成 DOMjudge (kattis) 题目包的 python 脚本。
安装
从 PyPI(稳定版本, 已经在一些比赛中使用过)
pipx install p2d
从源码(最新版本,正在开发中,有新的特性)
pipx install git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge
命令行使用示例
# 首先把你的 polygon-package 解压到 /path/to/polygon-package 位置
$ ./bin/p2d --code A --color "#FF0000" -o /path/to/domjudge-package /path/to/polygon-package
# 或者也可以不解压,直接使用 /path/to/polygon-package.zip
$ ./bin/p2d --code A --color "#FF0000" -o /path/to/domjudge-package /path/to/polygon-package.zip
运行此命令可以从 /path/to/polygon-package
处的转换题目包为 /path/to/domjudge-package.zip
,并设置 code
和 color
属性。
所有可用的命令行参数如下:
--code
: 题目在 DOMjudge 中的 short name。--color
: 题目在 DOMjudge 中的颜色。--default
: 强制使用 DOMjudge 默认的输出校验器。--validator-flags
: 为输出校验器添加一些命令行参数,仅在--default
被设置时生效。--auto
: 自动使用 DOMjudge 默认的输出校验器,即如果 checker 在配置文件中被定义,则使用默认的输出校验器与合适的命令行参数替代。--memory-limit
: 覆盖 DOMjudge 题目包的内存限制,如果不设置,则使用 Polygon 题目包中的内存限制。--output-limit
: 覆盖 DOMjudge 题目包的输出限制,如果不设置,则使用 DOMjudge 设置中默认的输出限制。--hide-sample
: 隐藏题面中的样例输入输出,不会为选手提供样例数据(如果是交互题,则此参数强制为 True)。 当此参数不设置为 True 且样例输出与标程的输出不同时,样例输出将会被替换为题面中提供的样例输出。--testset
: 指定要转换的测试点集,如果题目有多个测试点集,则必须指定测试点集的名称。
配置
在 config.toml 文件中,你可以设置一些特殊的 checker 的输出校验器参数,这会在 --auto
参数被设置时用来将 checker 替换为默认的输出校验器。
[!NOTE] 你不应该直接编辑这个文件,而是应该创建一个新的文件,命名为
config.toml
或其他名称,并使用--config
参数将其传递给脚本。脚本将会合并默认配置和你的配置。
环境变量
某些时候可能会有用。但如果你不知道你在干啥,请不要随便修改。
CONFIG_PATH
TESTLIB_PATH
API 使用示例
[!WARNING] API 不是稳定的,可能会在未来的版本中发生变化。
这是一个将 problems.yaml
中定义的比赛中的所有题目转换为 DOMjudge 题目包的示例。
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',
code=problem['label'],
color=problem['rgb'],
)
开发
# install
poetry install
# build
poetry build
# run unittest
poetry run pytest
# release
./release.sh ${your version}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file p2d-0.2.4.tar.gz
.
File metadata
- Download URL: p2d-0.2.4.tar.gz
- Upload date:
- Size: 57.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4749d9891be43e68603bf74f6f03a5363c6622067258a8afd09fe42ce34027f |
|
MD5 | 4dc8f3dae37f853914a049275f35b2c1 |
|
BLAKE2b-256 | 37dce383d42015c0b0d3b72d8f75e51fe3bb84f391147d4b9d29a9bfcee1fc51 |
File details
Details for the file p2d-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: p2d-0.2.4-py3-none-any.whl
- Upload date:
- Size: 58.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdbea8cfe9a5592345ac02613a5519e00a78da191f439c44a0e280754b02a3ff |
|
MD5 | 1f2bb083d219f172e63145dce5de45de |
|
BLAKE2b-256 | 17fb3755c4ec3874d3bf56ea8914593629f6f9d728254665540bf3b455155d13 |