@@ -92,6 +92,10 @@ def build_samples_zip(problems, output, statement_language):
92
92
def build_problem_zip (problem : Problem , output : Path ):
93
93
"""Make DOMjudge/Kattis ZIP file for specified problem."""
94
94
95
+ if not has_ryaml :
96
+ error ("zip needs the ruamel.yaml python3 library. Install python[3]-ruamel.yaml." )
97
+ return
98
+
95
99
# Add problem PDF for only one language to the zip file (note that Kattis export does not include PDF)
96
100
statement_language = None if config .args .kattis else force_single_language ([problem ])
97
101
@@ -121,7 +125,7 @@ def build_problem_zip(problem: Problem, output: Path):
121
125
]
122
126
123
127
if problem .custom_output :
124
- files .append (("output_validators /**/*" , True ))
128
+ files .append (("output_validator /**/*" , True ))
125
129
126
130
if config .args .kattis :
127
131
files .append (("input_validators/**/*" , True ))
@@ -170,33 +174,64 @@ def add_file(path, source):
170
174
out = f2 .relative_to (problem .path )
171
175
add_file (out , f2 )
172
176
173
- # DOMjudge does not support 'type' in problem.yaml nor 'output_validator_args' in testdata.yaml yet.
174
- # TODO: Remove this once it does.
175
- if not config .args .kattis :
176
- yaml_path = export_dir / "problem.yaml"
177
- yaml_data = [yaml_path .read_text (), "\n validation:" ]
178
- if problem .custom_output :
179
- yaml_data .append (" custom" )
180
- if problem .interactive :
181
- yaml_data .append (" interactive" )
182
- if problem .multi_pass :
183
- yaml_data .append (" multi-pass" )
184
- else :
185
- yaml_data .append (" default" )
186
- yaml_data .append ("\n " )
187
-
188
- validator_flags = " " .join (
189
- problem .get_testdata_yaml (
190
- problem .path / "data" ,
191
- "output_validator_args" ,
192
- PrintBar ("Getting validator_flags for legacy DOMjudge export" ),
193
- )
177
+ # DOMjudge and Kattis do not support 2023-07-draft yet.
178
+ # TODO: Remove once they do.
179
+ from ruamel .yaml .comments import CommentedMap
180
+
181
+ yaml_path = export_dir / "problem.yaml"
182
+ yaml_data = read_yaml (yaml_path )
183
+ # drop format version -> legacy
184
+ if "problem_format_version" in yaml_data :
185
+ ryaml_filter (yaml_data , "problem_format_version" )
186
+ # type -> validation
187
+ if "type" in yaml_data :
188
+ ryaml_filter (yaml_data , "type" )
189
+ validation = []
190
+ if problem .custom_output :
191
+ validation .append ("custom" )
192
+ if problem .interactive :
193
+ validation .append ("interactive" )
194
+ if problem .multi_pass :
195
+ validation .append ("multi-pass" )
196
+ else :
197
+ validation .append ("default" )
198
+ yaml_data ["validation" ] = " " .join (validation )
199
+ # credits -> author
200
+ if "credits" in yaml_data :
201
+ ryaml_filter (yaml_data , "credits" )
202
+ if problem .settings .credits .authors :
203
+ yaml_data ["author" ] = ", " .join (p .name for p in problem .settings .credits .authors )
204
+ # change source:
205
+ if problem .settings .source :
206
+ if len (problem .settings .source ) > 1 :
207
+ util .warn (f"Found multiple sources, using '{ problem .settings .source [0 ].name } '." )
208
+ yaml_data ["source" ] = problem .settings .source [0 ].name
209
+ yaml_data ["source_url" ] = problem .settings .source [0 ].url
210
+ # limits.time_multipliers -> time_multiplier / time_safety_margin
211
+ if "limits" not in yaml_data or not yaml_data ["limits" ]:
212
+ yaml_data ["limits" ] = CommentedMap ()
213
+ limits = yaml_data ["limits" ]
214
+ if "time_multipliers" in limits :
215
+ ryaml_filter (limits , "time_multipliers" )
216
+ limits ["time_multiplier" ] = problem .limits .ac_to_time_limit
217
+ limits ["time_safety_margin" ] = problem .limits .time_limit_to_tle
218
+ # drop explicit timelimit for kattis:
219
+ if "time_limit" in limits :
220
+ # keep this for kattis even when "time_limit" is supported
221
+ ryaml_filter (limits , "time_limit" )
222
+ # validator_flags
223
+ validator_flags = " " .join (
224
+ problem .get_testdata_yaml (
225
+ problem .path / "data" ,
226
+ "output_validator_args" ,
227
+ PrintBar ("Getting validator_flags for legacy export" ),
194
228
)
195
- if validator_flags :
196
- yaml_data .append (f"validator_flags: { validator_flags } \n " )
197
-
198
- yaml_path .unlink ()
199
- yaml_path .write_text ("" .join (yaml_data ))
229
+ )
230
+ if validator_flags :
231
+ yaml_data ["validator_flags" ] = validator_flags
232
+ # write legacy style yaml
233
+ yaml_path .unlink ()
234
+ write_yaml (yaml_data , yaml_path )
200
235
201
236
# DOMjudge does not support 'limits.time_limit' in problem.yaml yet.
202
237
# TODO: Remove this once it does.
@@ -224,7 +259,7 @@ def add_file(path, source):
224
259
if problem .settings .constants :
225
260
constants_supported = [
226
261
"data/**/testdata.yaml" ,
227
- "output_validators /**/*" ,
262
+ "output_validator /**/*" ,
228
263
"input_validators/**/*" ,
229
264
# "statement/*", uses \constants
230
265
# "submissions/*/**/*", removed support?
@@ -242,6 +277,13 @@ def add_file(path, source):
242
277
f .unlink ()
243
278
f .write_text (text )
244
279
280
+ # TODO: Remove this if we know others use the output_validator dir
281
+ if (export_dir / "output_validator" ).exists ():
282
+ (export_dir / "output_validators" ).mkdir (parents = True )
283
+ (export_dir / "output_validator" ).rename (
284
+ export_dir / "output_validators" / "output_validator"
285
+ )
286
+
245
287
# TODO: Remove this if we know others import the statement folder
246
288
if (export_dir / "statement" ).exists ():
247
289
(export_dir / "statement" ).rename (export_dir / "problem_statement" )
@@ -286,6 +328,10 @@ def add_file(path, source):
286
328
# solutions*.{lang}.pdf
287
329
# Output is <outfile>
288
330
def build_contest_zip (problems , zipfiles , outfile , statement_language ):
331
+ if not has_ryaml :
332
+ error ("zip needs the ruamel.yaml python3 library. Install python[3]-ruamel.yaml." )
333
+ return
334
+
289
335
print (f"writing ZIP file { outfile } " , file = sys .stderr )
290
336
291
337
if not config .args .kattis : # Kattis does not use problems.yaml.
0 commit comments