Skip to content

Commit 5572b74

Browse files
committed
[skel] Read type instead of validation
1 parent 6362f63 commit 5572b74

File tree

7 files changed

+54
-43
lines changed

7 files changed

+54
-43
lines changed

bin/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
grep -Ev '^(h|jobs|time|verbose)$' | sed "s/^/'/;s/$/',/" | tr '\n' ' ' | sed 's/^/ARGS_LIST: Final = [/;s/, $/]\n/'
9797
"""
9898
# fmt: off
99-
ARGS_LIST: Final = ['1', 'add', 'all', 'answer', 'api', 'author', 'check_deterministic', 'clean', 'colors', 'contest', 'contest_id', 'contestname', 'cp', 'default_solution', 'depth', 'directory', 'error', 'force', 'force_build', 'input', 'interaction', 'interactive', 'invalid', 'kattis', 'language', 'memory', 'more', 'move_to', 'no_bar', 'no_generate', 'no_solution', 'no_solutions', 'no_testcase_sanity_checks', 'no_time_limit', 'no_validators', 'no_visualizer', 'open', 'order', 'order_from_ccs', 'overview', 'password', 'post_freeze', 'problem', 'problemname', 'remove', 'reorder', 'samples', 'sanitizer', 'skel', 'skip', 'sort', 'submissions', 'table', 'testcases', 'time_limit', 'timeout', 'token', 'tree', 'username', 'validation', 'watch', 'web', 'write']
99+
ARGS_LIST: Final = ['1', 'add', 'all', 'answer', 'api', 'author', 'check_deterministic', 'clean', 'colors', 'contest', 'contest_id', 'contestname', 'cp', 'default_solution', 'depth', 'directory', 'error', 'force', 'force_build', 'input', 'interaction', 'interactive', 'invalid', 'kattis', 'language', 'memory', 'more', 'move_to', 'no_bar', 'no_generate', 'no_solution', 'no_solutions', 'no_testcase_sanity_checks', 'no_time_limit', 'no_validators', 'no_visualizer', 'open', 'order', 'order_from_ccs', 'overview', 'password', 'post_freeze', 'problem', 'problemname', 'remove', 'reorder', 'samples', 'sanitizer', 'skel', 'skip', 'sort', 'submissions', 'table', 'testcases', 'time_limit', 'timeout', 'token', 'tree', 'type', 'username', 'watch', 'web', 'write']
100100
# fmt: on
101101

102102

bin/problem.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@
2222
from colorama import Fore, Style
2323

2424

25+
# Parse validation mode (only for legacy problem format version)
26+
def parse_legacy_validation(mode: str) -> set[str]:
27+
if mode == "default":
28+
return {mode}
29+
else:
30+
ok = True
31+
parsed = set()
32+
for part in mode.split():
33+
if part in ["custom", "interactive", "multi-pass"] and part not in parsed:
34+
parsed.add(part)
35+
else:
36+
ok = False
37+
if "custom" not in parsed or not ok:
38+
fatal(f"Unrecognised validation mode {mode}.")
39+
return parsed
40+
41+
2542
class ProblemLimits:
2643
def __init__(
2744
self,
@@ -127,7 +144,7 @@ def __init__(
127144
fatal(f"problem_format_version {self.problem_format_version} not supported")
128145

129146
if self.is_legacy():
130-
mode = parse_validation(parse_setting(yamldata, "validation", "default"))
147+
mode = parse_legacy_validation(parse_setting(yamldata, "validation", "default"))
131148
else:
132149
if "validation" in yamldata:
133150
warn(

bin/skel.py

+24-15
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,29 @@ def new_problem():
153153
author = config.args.author if config.args.author else _ask_variable_string("author")
154154

155155
validator_flags = ""
156-
if config.args.validation:
157-
parse_validation(config.args.validation)
158-
validation = config.args.validation
156+
custom_output = False
157+
if config.args.type:
158+
problem_type = config.args.type
159159
else:
160-
validation = _ask_variable_choice("validation", ["default", "float", "custom"])
161-
if validation == "float":
162-
validation = "default"
163-
validator_flags = "validator_flags:\n float_tolerance 1e-6\n"
164-
log("Using default float tolerance of 1e-6")
165-
if validation == "custom":
166-
if _ask_variable_bool("interactive", False):
167-
validation += " interactive"
168-
if _ask_variable_bool("multi-pass", False):
169-
validation += " multi-pass"
160+
problem_type = _ask_variable_choice("type", ["default", "float", "custom"])
161+
# TODO Maybe remove command-line option "default" and replace it with "pass-fail"?
162+
if problem_type == "default":
163+
problem_type = "pass-fail"
164+
if problem_type == "float":
165+
problem_type = "pass-fail"
166+
validator_flags = "validator_flags:\n float_tolerance 1e-6\n"
167+
log("Using default float tolerance of 1e-6")
168+
if problem_type == "custom":
169+
custom_output = True
170+
problem_type = "pass-fail"
171+
# If we're interactively determining the problem type, and the user selected "custom":
172+
if not config.args.type and problem_type == "custom":
173+
custom_types = []
174+
if _ask_variable_bool("interactive", False):
175+
custom_types.append("interactive")
176+
if _ask_variable_bool("multi-pass", False):
177+
custom_types.append("multi-pass")
178+
problem_type = " ".join(custom_types) if custom_types else "pass-fail"
170179

171180
# Read settings from the contest-level yaml file.
172181
variables = contest.contest_yaml()
@@ -175,7 +184,7 @@ def new_problem():
175184
"problemname": "\n".join(f" {lang}: {name}" for lang, name in problemname.items()),
176185
"dirname": dirname,
177186
"author": author,
178-
"validation": validation,
187+
"type": problem_type,
179188
"validator_flags": validator_flags,
180189
}.items():
181190
variables[k] = v
@@ -229,7 +238,7 @@ def new_problem():
229238
variables,
230239
exist_ok=True,
231240
preserve_symlinks=preserve_symlinks,
232-
skip=[skeldir / "output_validators"] if validation == "default" else None,
241+
skip=[skeldir / "output_validators"] if not custom_output else None,
233242
)
234243

235244
# Warn about missing problem statement skeletons for non-en languages

bin/tools.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,16 @@ def build_parser():
368368
problemparser.add_argument("problemname", nargs="?", help="The name of the problem,")
369369
problemparser.add_argument("--author", help="The author of the problem,")
370370
problemparser.add_argument(
371-
"--validation",
372-
help="Use validation to use for this problem.",
371+
"--type",
372+
help="The type of the problem.",
373373
choices=[
374374
"default",
375+
"pass-fail",
376+
"float",
375377
"custom",
376-
"custom interactive",
377-
"custom multi-pass",
378-
"custom interactive multi-pass",
378+
"interactive",
379+
"multi-pass",
380+
"interactive multi-pass",
379381
],
380382
)
381383
problemparser.add_argument("--skel", help="Skeleton problem directory to copy from.")

bin/util.py

-17
Original file line numberDiff line numberDiff line change
@@ -675,23 +675,6 @@ def parse_setting(yamldata: dict[str, Any], key: str, default: T) -> T:
675675
return default if value is None else value
676676

677677

678-
# Parse validation mode
679-
def parse_validation(mode: str) -> set[str]:
680-
if mode == "default":
681-
return {mode}
682-
else:
683-
ok = True
684-
parsed = set()
685-
for part in mode.split():
686-
if part in ["custom", "interactive", "multi-pass"] and part not in parsed:
687-
parsed.add(part)
688-
else:
689-
ok = False
690-
if "custom" not in parsed or not ok:
691-
fatal(f"Unrecognised validation mode {mode}.")
692-
return parsed
693-
694-
695678
# glob, but without hidden files
696679
def glob(path: Path, expression: str, include_hidden=False) -> list[Path]:
697680
def keep(p: Path):

skel/problem/problem.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ problem_format_version: 2023-07-draft
33
name:
44
#lang: name
55
{%problemname%}
6+
# 'pass-fail', 'interactive', 'multi-pass', or 'interactive multi-pass'
7+
type: {%type%}
68
author: {%author%}
79
# Contest name and year
810
source: {%source%}
@@ -11,8 +13,6 @@ source_url: {%source_url%}
1113
uuid: {%uuid%}
1214
license: {%license%}
1315
rights_owner: {%rights_owner%}
14-
# 'default', 'custom', or 'custom interactive'
15-
validation: {%validation%}
1616

1717
# One or more of:
1818
# case_sensitive

test/test_problems.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def test_new_contest_problem(self, monkeypatch):
192192
"Problem One",
193193
"--author",
194194
"Ragnar Groot Koerkamp",
195-
"--validation",
196-
"default",
195+
"--type",
196+
"pass-fail",
197197
]
198198
)
199199
os.chdir("contest_name")

0 commit comments

Comments
 (0)