rimuruchan-p2d 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. rimuruchan_p2d-0.4.2/.github/workflows/release.yml +48 -0
  2. rimuruchan_p2d-0.4.2/.github/workflows/test.yml +56 -0
  3. rimuruchan_p2d-0.4.2/.gitignore +168 -0
  4. rimuruchan_p2d-0.4.2/.pre-commit-config.yaml +12 -0
  5. rimuruchan_p2d-0.4.2/.vscode/settings.json +30 -0
  6. rimuruchan_p2d-0.4.2/LICENSE +21 -0
  7. rimuruchan_p2d-0.4.2/PKG-INFO +166 -0
  8. rimuruchan_p2d-0.4.2/README.cn.md +133 -0
  9. rimuruchan_p2d-0.4.2/README.md +138 -0
  10. rimuruchan_p2d-0.4.2/config.example.toml +53 -0
  11. rimuruchan_p2d-0.4.2/p2d/__init__.py +11 -0
  12. rimuruchan_p2d-0.4.2/p2d/__main__.py +4 -0
  13. rimuruchan_p2d-0.4.2/p2d/_version.py +34 -0
  14. rimuruchan_p2d-0.4.2/p2d/cli.py +198 -0
  15. rimuruchan_p2d-0.4.2/p2d/contest.py +98 -0
  16. rimuruchan_p2d-0.4.2/p2d/models.py +60 -0
  17. rimuruchan_p2d-0.4.2/p2d/p2d.py +767 -0
  18. rimuruchan_p2d-0.4.2/p2d/testlib/LICENSE +21 -0
  19. rimuruchan_p2d-0.4.2/p2d/testlib/README.md +180 -0
  20. rimuruchan_p2d-0.4.2/p2d/testlib/patch/domjudge.patch +201 -0
  21. rimuruchan_p2d-0.4.2/p2d/testlib/read.me +19 -0
  22. rimuruchan_p2d-0.4.2/p2d/testlib/testlib.h +6304 -0
  23. rimuruchan_p2d-0.4.2/p2d/utils.py +49 -0
  24. rimuruchan_p2d-0.4.2/pyproject.toml +114 -0
  25. rimuruchan_p2d-0.4.2/test/__init__.py +0 -0
  26. rimuruchan_p2d-0.4.2/test/test_cli.py +55 -0
  27. rimuruchan_p2d-0.4.2/test/test_contest.py +26 -0
  28. rimuruchan_p2d-0.4.2/test/test_data/config-broken.toml +1 -0
  29. rimuruchan_p2d-0.4.2/test/test_data/config-broken2.toml +1 -0
  30. rimuruchan_p2d-0.4.2/test/test_data/contest-broken.xml +7 -0
  31. rimuruchan_p2d-0.4.2/test/test_data/contest.xml +13 -0
  32. rimuruchan_p2d-0.4.2/test/test_data/data.yaml +415 -0
  33. rimuruchan_p2d-0.4.2/test/test_data/guess-array-1$linux.zip +0 -0
  34. rimuruchan_p2d-0.4.2/test/test_data/little-h-reboot-7$linux.zip +0 -0
  35. rimuruchan_p2d-0.4.2/test/test_p2d.py +126 -0
  36. rimuruchan_p2d-0.4.2/test/test_utils.py +54 -0
  37. rimuruchan_p2d-0.4.2/test/utils/__init__.py +0 -0
  38. rimuruchan_p2d-0.4.2/test/utils/assertions.py +72 -0
  39. rimuruchan_p2d-0.4.2/test/utils/dataloader.py +119 -0
  40. rimuruchan_p2d-0.4.2/test/utils/models.py +57 -0
  41. rimuruchan_p2d-0.4.2/uv.lock +520 -0
@@ -0,0 +1,48 @@
1
+ name: Release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ release:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ with:
12
+ fetch-depth: 0
13
+
14
+ - name: Set node
15
+ uses: actions/setup-node@v4
16
+ with:
17
+ node-version: 18.x
18
+
19
+ - run: npx changelogithub
20
+ env:
21
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22
+
23
+ release-pypi:
24
+ runs-on: ubuntu-latest
25
+
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+
29
+ - name: Checkout repository
30
+ uses: actions/checkout@v4
31
+ with:
32
+ fetch-depth: 0
33
+
34
+ - name: Install uv and set the python version
35
+ uses: astral-sh/setup-uv@v5
36
+ with:
37
+ enable-cache: true
38
+ cache-dependency-glob: "uv.lock"
39
+
40
+ - name: Build
41
+ run: |
42
+ uv build
43
+
44
+ - name: Publish
45
+ uses: pypa/gh-action-pypi-publish@release/v1
46
+ with:
47
+ user: __token__
48
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,56 @@
1
+ # yaml-language-server: $schema=https://json-schema.org/draft-07/schema#
2
+ name: Test
3
+
4
+ on:
5
+ push:
6
+ branches:
7
+ - master
8
+ paths:
9
+ - "uv.lock"
10
+ - "pyproject.toml"
11
+ - "p2d/**"
12
+ - "test/**"
13
+ - ".github/workflows/**"
14
+ pull_request:
15
+ types: [ opened, synchronize, reopened, ready_for_review ]
16
+ paths:
17
+ - "uv.lock"
18
+ - "pyproject.toml"
19
+ - "p2d/**"
20
+ - "test/**"
21
+ - ".github/workflows/**"
22
+ workflow_dispatch:
23
+
24
+ jobs:
25
+ test:
26
+ name: Test
27
+ runs-on: ${{ matrix.os }}
28
+ strategy:
29
+ matrix:
30
+ os: [ubuntu-latest, macos-latest, windows-latest]
31
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
32
+ fail-fast: false
33
+ steps:
34
+ - name: Checkout repository
35
+ uses: actions/checkout@v4
36
+ with:
37
+ fetch-depth: 0
38
+
39
+ - name: Install uv and set the python version
40
+ uses: astral-sh/setup-uv@v5
41
+ with:
42
+ python-version: ${{ matrix.python-version }}
43
+ enable-cache: true
44
+ cache-dependency-glob: "uv.lock"
45
+
46
+ - name: Install the project
47
+ run: |
48
+ uv sync --all-extras --dev
49
+
50
+ - name: Lint
51
+ run: |
52
+ uv tool run ruff check
53
+
54
+ - name: Unit Test
55
+ run: |
56
+ uv run --frozen pytest
@@ -0,0 +1,168 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+
5
+ # C extensions
6
+ *.so
7
+
8
+ # Distribution / packaging
9
+ .Python
10
+ build/
11
+ develop-eggs/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ share/python-wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ *.py,cover
49
+ .hypothesis/
50
+ .pytest_cache/
51
+ cover/
52
+
53
+ # Translations
54
+ *.mo
55
+ *.pot
56
+
57
+ # Django stuff:
58
+ *.log
59
+ local_settings.py
60
+ db.sqlite3
61
+ db.sqlite3-journal
62
+
63
+ # Flask stuff:
64
+ instance/
65
+ .webassets-cache
66
+
67
+ # Scrapy stuff:
68
+ .scrapy
69
+
70
+ # Sphinx documentation
71
+ docs/_build/
72
+
73
+ # PyBuilder
74
+ .pybuilder/
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ # For a library or package, you might want to ignore these files since the code is
86
+ # intended to run in multiple environments; otherwise, check them in:
87
+ # .python-version
88
+
89
+ # pipenv
90
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
91
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
92
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
93
+ # install all needed dependencies.
94
+ #Pipfile.lock
95
+
96
+ # poetry
97
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
98
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
99
+ # commonly ignored for libraries.
100
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
101
+ #poetry.lock
102
+
103
+ # pdm
104
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
105
+ #pdm.lock
106
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
107
+ # in version control.
108
+ # https://pdm.fming.dev/#use-with-ide
109
+ .pdm.toml
110
+
111
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
112
+ __pypackages__/
113
+
114
+ # Celery stuff
115
+ celerybeat-schedule
116
+ celerybeat.pid
117
+
118
+ # SageMath parsed files
119
+ *.sage.py
120
+
121
+ # Environments
122
+ .env
123
+ .venv
124
+ env/
125
+ venv/
126
+ ENV/
127
+ env.bak/
128
+ venv.bak/
129
+
130
+ # Spyder project settings
131
+ .spyderproject
132
+ .spyproject
133
+
134
+ # Rope project settings
135
+ .ropeproject
136
+
137
+ # mkdocs documentation
138
+ /site
139
+
140
+ # mypy
141
+ .mypy_cache/
142
+ .dmypy.json
143
+ dmypy.json
144
+
145
+ # Pyre type checker
146
+ .pyre/
147
+
148
+ # pytype static type analyzer
149
+ .pytype/
150
+
151
+ # Cython debug symbols
152
+ cython_debug/
153
+
154
+ # PyCharm
155
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
156
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
157
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
158
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
159
+ #.idea/
160
+
161
+ tmp/*
162
+ *.log
163
+ *.zip
164
+
165
+ !/test/test_data/*
166
+ /test/test_output
167
+
168
+ _version.py
@@ -0,0 +1,12 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.6.0
4
+ hooks:
5
+ - id: end-of-file-fixer
6
+ - id: trailing-whitespace
7
+ - id: mixed-line-ending
8
+ - repo: https://github.com/astral-sh/ruff-pre-commit
9
+ rev: v0.9.10
10
+ hooks:
11
+ - id: ruff
12
+ - id: ruff-format
@@ -0,0 +1,30 @@
1
+ {
2
+ "editor.tabSize": 4,
3
+ "editor.insertSpaces": true,
4
+ "editor.formatOnSave": true,
5
+ "files.trimTrailingWhitespace": true,
6
+ "files.insertFinalNewline": true,
7
+ "files.trimFinalNewlines": true,
8
+ "[python]": {
9
+ "editor.defaultFormatter": "charliermarsh.ruff"
10
+ },
11
+ "cSpell.words": [
12
+ "cubercsl",
13
+ "Domjudge",
14
+ "interactor",
15
+ "interactors",
16
+ "kattis",
17
+ "memorylimit",
18
+ "outputlimit",
19
+ "pypi",
20
+ "pyright",
21
+ "pytest",
22
+ "testlib",
23
+ "testset",
24
+ "timelimit"
25
+ ],
26
+ "python.testing.pytestArgs": [
27
+ "test"
28
+ ],
29
+ "python.testing.pytestEnabled": true,
30
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 cn-xcpc-tools contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: rimuruchan-p2d
3
+ Version: 0.4.2
4
+ Summary: Simple python script converting polygon package to domjudge(kattis) package
5
+ Project-URL: homepage, https://github.com/RimuruChan/Polygon2Domjudge
6
+ Project-URL: documentation, https://github.com/RimuruChan/Polygon2Domjudge
7
+ Project-URL: repository, https://github.com/RimuruChan/Polygon2Domjudge
8
+ Author-email: cubercsl <hi@cubercsl.site>, rimuruchan <RealSprite233@outlook.com>
9
+ Maintainer-email: rimuruchan <RealSprite233@outlook.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: Codeforces,DOMjudge,Kattis,Polygon
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Build Tools
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: deepmerge>=2.0
22
+ Requires-Dist: pydantic>=2.10.6
23
+ Requires-Dist: pyyaml>=6.0.2
24
+ Requires-Dist: rich>=13.9.4
25
+ Requires-Dist: tomli>=2.0.1; python_version < '3.11'
26
+ Requires-Dist: typer-slim[standard]>=0.12.5
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Polygon2DOMjudge
30
+
31
+ [![Test][gh-test-badge]][gh-test]
32
+ [![GitHub release][gh-release-badge]][gh-release]
33
+
34
+ [中文](README.cn.md)
35
+
36
+ ## What is this
37
+
38
+ It is a simple python script converting polygon package to DOMjudge (kattis) package.
39
+
40
+ ## Install
41
+
42
+ ### From PyPI (stable release, has been used in some contests)
43
+
44
+ ```bash
45
+ pipx install p2d
46
+ ```
47
+
48
+ ### From source (latest version, under development with new features)
49
+
50
+ ```bash
51
+ pipx install git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge
52
+ ```
53
+
54
+ ## CLI Example
55
+
56
+ First, you should build **full** package from Polygon and download the **Linux** package to your local.
57
+
58
+ > [!WARNING]
59
+ > If you download the standard package and then run `doall.sh` to build the full package by yourself, the linebreaks will be CRLF.
60
+ > Make sure you convert the linebreaks to LF before running the script because DOMjudge is running on Linux.
61
+
62
+ ```bash
63
+ # Download the full package from Polygon to /path/to/polygon-package.zip
64
+ $ p2d --code A --color "#FF0000" -o /path/to/domjudge-package.zip /path/to/polygon-package.zip
65
+ ```
66
+
67
+ Run this command to make a package from `/path/to/polygon-package.zip` to `/path/to/domjudge-package.zip` and set `code` and `color`.
68
+
69
+ You can omit the output path, and the default output path will be in the current working directory and named as `{{ code }}.zip`.
70
+
71
+ All available parameters are:
72
+
73
+ - `--code`: problem short name in DOMjudge contest.
74
+ - `--color`: problem color in DOMjudge.
75
+ - `--default`: force use the default output validator.
76
+ - `--validator-flags`: add some flags to the output validator, only works when `--default` is set.
77
+ - `--auto`: use the default output validator if the checker is defined in config and can be replaced by the default one.
78
+ - `--memory-limit`: override the memory limit for DOMjudge package (in MB), default is using the memory limit defined in polygon package.
79
+ - `--output-limit`: override the output limit for DOMjudge package (in MB), default is using the default output limit in DOMjudge setting.
80
+ - `--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).
81
+ When this is not set to True and the sample output is different from the main and correct solution (usually both are correct answers),
82
+ the sample output will be replaced with the one shipped with problem statement.
83
+ But the sample input will not be replaced because DOMjudge does not support different sample input from the one downloaded.
84
+ - `--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.
85
+ (By default, all sample output will be replaced with the one shipped with problem statement)
86
+ - `--external-id`: specify the external id of the problem in DOMjudge, default is using the problem short-name in polygon.
87
+ - `--with-statement`: include the pdf statement in the DOMjudge package.
88
+ - `--with-attachments`: include attachments (e.g. local testing tools for interactive problem) in the DOMjudge package.
89
+ - `--testset`: specify the testset to convert, must specify the testset name if the problem has multiple testsets.
90
+
91
+ ### Convert the whole contest
92
+
93
+ You can use `p2d-contest` to get a script to convert all problems in a contest.
94
+
95
+ ```bash
96
+ # Download the contest.xml from Polygon first
97
+ $ p2d-contest /path/to/contest.xml > convert.sh
98
+ ```
99
+
100
+ ## Config
101
+
102
+ In [config.toml](./config.example.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.
103
+
104
+ > [!NOTE]
105
+ > 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.
106
+
107
+ ## Environment Variable
108
+
109
+ Don't change them unless you know what you are doing.
110
+
111
+ - `TESTLIB_PATH`
112
+
113
+ ## API Example
114
+
115
+ > [!WARNING]
116
+ > The API is not stable and may change in the future.
117
+
118
+ This is an example to convert all problems in a contest defined in [`problems.yaml`](https://ccs-specs.icpc.io/draft/contest_package#problemsyaml) to DOMjudge package.
119
+
120
+ ```python
121
+ import yaml
122
+ from pathlib import Path
123
+
124
+ from p2d import convert
125
+
126
+ polygon = Path('/path/to/polygon-packages')
127
+ domjudge = Path('/path/to/domjudge-packages')
128
+
129
+ with open(domjudge / 'problems.yaml') as f:
130
+ problems = yaml.safe_load(f)
131
+
132
+ for problem in problems:
133
+ prob_id = problem['id']
134
+ convert(
135
+ polygon / f'{prob_id}.zip',
136
+ domjudge / f'{prob_id}.zip',
137
+ short_name=problem['label'],
138
+ color=problem['rgb'],
139
+ )
140
+ ```
141
+
142
+ ## Known Issues
143
+
144
+ - For interactive problems, you must validate the output in the interactors, because DOMjudge cannot handle `tout` stream like Polygon.
145
+ - For multi-pass problems
146
+ - 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.
147
+ - 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.
148
+
149
+ ## Development
150
+
151
+ ```bash
152
+ # install
153
+ uv sync
154
+
155
+ # build
156
+ uv build
157
+
158
+ # run unittest
159
+ uv run pytest
160
+
161
+ ```
162
+
163
+ [gh-test-badge]: https://github.com/cn-xcpc-tools/Polygon2DOMjudge/actions/workflows/test.yml/badge.svg
164
+ [gh-test]: https://github.com/cn-xcpc-tools/Polygon2DOMjudge/actions/workflows/test.yml
165
+ [gh-release-badge]: https://img.shields.io/github/release/cn-xcpc-tools/Polygon2DOMjudge.svg
166
+ [gh-release]: https://GitHub.com/cn-xcpc-tools/Polygon2DOMjudge/releases/
@@ -0,0 +1,133 @@
1
+ # Polygon2DOMjudge
2
+
3
+ [![Test][gh-test-badge]][gh-test]
4
+ [![GitHub release][gh-release-badge]][gh-release]
5
+
6
+ ## 这是什么
7
+
8
+ 这是一个简单的将 polygon 题目包转换成 DOMjudge (kattis) 题目包的 python 脚本。
9
+
10
+ ## 安装
11
+
12
+ ### 从 PyPI(稳定版本, 已经在一些比赛中使用过)
13
+
14
+ ```bash
15
+ pipx install p2d
16
+ ```
17
+
18
+ ### 从源码(最新版本,正在开发中,有新的特性)
19
+
20
+ ```bash
21
+ pipx install git+https://github.com/cn-xcpc-tools/Polygon2DOMjudge
22
+ ```
23
+
24
+ ## 命令行使用示例
25
+
26
+ 首先,你需要从 Polygon 构建 **完整的** 题目包并将 **Linux** 题目包下载到本地。
27
+
28
+ > [!WARNING]
29
+ > 如果你下载了标准的题目包并且运行 `doall.sh` 来构建完整的题目包,那么换行符将会是 CRLF。
30
+ > 在运行脚本之前,请确保将换行符转换为 LF,因为 DOMjudge 是在 Linux 上运行的。
31
+
32
+ ```bash
33
+ # 首先从 Polygon 下载完整的 Linux 题目包到本地
34
+ $ ./bin/p2d --code A --color "#FF0000" -o /path/to/domjudge-package.zip /path/to/polygon-package.zip
35
+ ```
36
+
37
+ 运行此命令可以从 `/path/to/polygon-package.zip` 处题目包转换为 `/path/to/domjudge-package.zip`,并设置 `code` 和 `color` 属性。
38
+
39
+ 你可以省略输出路径,输出路径将会在当前工作目录中,并命名为 `{{ code }}.zip`。
40
+
41
+ 所有可用的命令行参数如下:
42
+
43
+ - `--code`: 题目在 DOMjudge 比赛中的 short name。
44
+ - `--color`: 题目在 DOMjudge 中的颜色。
45
+ - `--default`: 强制使用 DOMjudge 默认的输出校验器。
46
+ - `--validator-flags`: 为输出校验器添加一些命令行参数,仅在 `--default` 被设置时生效。
47
+ - `--auto`: 自动使用 DOMjudge 默认的输出校验器,即如果 checker 在配置文件中被定义,则使用默认的输出校验器与合适的命令行参数替代。
48
+ - `--memory-limit`: 覆盖 DOMjudge 题目包的内存限制,如果不设置,则使用 Polygon 题目包中的内存限制。
49
+ - `--output-limit`: 覆盖 DOMjudge 题目包的输出限制,如果不设置,则使用 DOMjudge 设置中默认的输出限制。
50
+ - `--hide-sample`: 隐藏题面中的样例输入输出,不会为选手提供样例数据(如果是交互题,则此参数强制为 True)。
51
+ 当此参数不设置为 True 且样例输出与标程的输出不同时 (通常两者都是符合要求的答案),
52
+ 样例输出将会被替换为题面中提供的样例输出。但是样例输入不会被替换,因为 DOMjudge 不支持下载的样例输入与实际使用的不同。
53
+ - `--keep-sample`: 保持样例输出与标程的输出一致,当题面中的样例输出是一个占位符时,这个参数很有用。(默认情况下,所有的样例输出将会被替换为题面中提供的样例输出)
54
+ - `--external-id`: 指定题目在 DOMjudge 中的 external id,如果不设置,则使用 Polygon 中的题目 short-name。
55
+ - `--with-statement`: 在 DOMjudge 题目包中包含 pdf 题面。
56
+ - `--with-attachments`: 在 DOMjudge 题目包中包含附件(例如交互题的本地测试工具)。
57
+ - `--testset`: 指定要转换的测试点集,如果题目有多个测试点集,则必须指定测试点集的名称。
58
+
59
+ ### 转换整个比赛
60
+
61
+ 你可以使用 `p2d-contest` 来获取一个脚本来转换整个比赛中的题目。
62
+
63
+ ```bash
64
+ # 首先从 Polygon 下载 contest.xml
65
+ $ ./bin/p2d-contest /path/to/contest.xml > convert.sh
66
+ ```
67
+
68
+ ## 配置
69
+
70
+ 在 [config.toml](./config.example.toml) 文件中,你可以设置一些特殊的 checker 的输出校验器参数,这会在 `--auto` 参数被设置时用来将 checker 替换为默认的输出校验器。
71
+
72
+ > [!NOTE]
73
+ > 你应该创建一个新的文件,命名为 `config.toml` 或其他名称,并使用 `--config` 参数将其传递给脚本。脚本将会合并默认配置和你的配置。
74
+
75
+ ## 环境变量
76
+
77
+ 某些时候可能会有用。但如果你不知道你在干啥,请不要随便修改。
78
+
79
+ - `TESTLIB_PATH`
80
+
81
+ ## API 使用示例
82
+
83
+ > [!WARNING]
84
+ > API 不是稳定的,可能会在未来的版本中发生变化。
85
+
86
+ 这是一个将 [`problems.yaml`](https://ccs-specs.icpc.io/draft/contest_package#problemsyaml) 中定义的比赛中的所有题目转换为 DOMjudge 题目包的示例。
87
+
88
+ ```python
89
+ import yaml
90
+ from pathlib import Path
91
+
92
+ from p2d import convert
93
+
94
+ polygon = Path('/path/to/polygon-packages')
95
+ domjudge = Path('/path/to/domjudge-packages')
96
+
97
+ with open(domjudge / 'problems.yaml') as f:
98
+ problems = yaml.safe_load(f)
99
+
100
+ for problem in problems:
101
+ prob_id = problem['id']
102
+ convert(
103
+ polygon / f'{prob_id}.zip',
104
+ domjudge / f'{prob_id}.zip',
105
+ short_name=problem['label'],
106
+ color=problem['rgb'],
107
+ )
108
+ ```
109
+
110
+ ## 已知Issues
111
+
112
+ - 对于交互题,您必须在交互器中完成对输出的验证(即,在交互器中直接返回最终的结果,略去使用checker对`tout`文件内容进行验证的步骤),因为 DOMjudge 无法像 Polygon 那样处理 `tout` 流。
113
+ - 对于 multi-pass 问题
114
+ - 部分逻辑可能与 Polygon 不同,您可能需要调整一些逻辑来适应 DOMjudge 的要求。DOMjudge 会使用 `-DDOMJUDGE` 宏定义来区分是否为 DOMjudge 环境,您可以使用这个宏定义来调整您的代码。
115
+ - 您可能需要调用 `tout.open(make_new_file_in_a_dir(argv[3], "nextpass.in"))` 来获取下一次传递的输入文件。
116
+
117
+ ## 开发
118
+
119
+ ```bash
120
+ # install
121
+ uv sync
122
+
123
+ # build
124
+ uv build
125
+
126
+ # run unittest
127
+ uv run pytest
128
+ ```
129
+
130
+ [gh-test-badge]: https://github.com/cn-xcpc-tools/Polygon2DOMjudge/actions/workflows/test.yml/badge.svg
131
+ [gh-test]: https://github.com/cn-xcpc-tools/Polygon2DOMjudge/actions/workflows/test.yml
132
+ [gh-release-badge]: https://img.shields.io/github/release/cn-xcpc-tools/Polygon2DOMjudge.svg
133
+ [gh-release]: https://GitHub.com/cn-xcpc-tools/Polygon2DOMjudge/releases/