Skip to content

Commit 91513b4

Browse files
mzuennimpsijm
andauthored
[validate] Remove {input,answer}_format_validators (#443)
* remove format_validators * rename folders * [problem] Problem._validators: remove `assert cls.source_dir` because all {Input,Answer,Output}Validator classes now only have source_dir, instead of source_dirs. --------- Co-authored-by: Maarten Sijm <[email protected]>
1 parent 1e0d2ec commit 91513b4

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

bin/problem.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,7 @@ def _validators(
911911
else:
912912
paths = [config.TOOLS_ROOT / "support" / "default_output_validator.cpp"]
913913
else:
914-
assert hasattr(cls, "source_dirs")
915-
paths = [
916-
p for source_dir in cls.source_dirs for p in glob(problem.path / source_dir, "*")
917-
]
914+
paths = list(glob(problem.path / cls.source_dir, "*"))
918915

919916
# TODO: Instead of checking file contents, maybe specify this in generators.yaml?
920917
def has_constraints_checking(f):

bin/stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def problem_stats(problems):
5151
("yaml", "problem.yaml"),
5252
("tex", str(latex.PdfType.PROBLEM.path("*")), 1),
5353
("sol", str(latex.PdfType.SOLUTION.path("*")), 1),
54-
(" val: I", ["input_validators/*", "input_format_validators/*"]),
54+
(" val: I", ["input_validators/*"]),
5555
("A", ["answer_validators/*"]),
5656
("O", ["output_validator/"]),
5757
(

bin/upgrade.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ def upgrade_statement(problem_path: Path, bar: ProgressBar) -> None:
151151
shutil.move(f, dest)
152152

153153

154+
def upgrade_format_validators(problem_path: Path, bar: ProgressBar) -> None:
155+
rename = [
156+
("input_format_validators", "input_validators"),
157+
("answer_format_validators", "answer_validators"),
158+
]
159+
for old_name, new_name in rename:
160+
old_path = problem_path / old_name
161+
new_path = problem_path / new_name
162+
if old_path.is_dir():
163+
if new_path.exists():
164+
bar.error(f"can't rename '{old_name}', '{new_name}' already exists", resume=True)
165+
continue
166+
bar.log(f"renaming '{old_name}' to '{new_name}'")
167+
old_path.rename(new_path)
168+
169+
154170
def upgrade_output_validators(problem_path: Path, bar: ProgressBar) -> None:
155171
if (problem_path / "output_validators").is_dir():
156172
if (problem_path / "output_validator").exists():
@@ -370,6 +386,7 @@ def _upgrade(problem_path: Path, bar: ProgressBar) -> None:
370386
upgrade_testdata_yaml(problem_path, bar)
371387
upgrade_generators_yaml(problem_path, bar)
372388
upgrade_statement(problem_path, bar)
389+
upgrade_format_validators(problem_path, bar)
373390
upgrade_output_validators(problem_path, bar)
374391
# update .in.statement?
375392
upgrade_problem_yaml(problem_path, bar)

bin/validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def __init__(self, problem, path, **kwargs):
229229

230230
validator_type: Final[str] = "input"
231231

232-
source_dirs: Final[list[str]] = ["input_validators", "input_format_validators"]
232+
source_dir: Final[str] = "input_validators"
233233

234234
def run(
235235
self,
@@ -289,7 +289,7 @@ def __init__(self, problem, path, **kwargs):
289289

290290
validator_type: Final[str] = "answer"
291291

292-
source_dirs: Final[list[str]] = ["answer_validators", "answer_format_validators"]
292+
source_dir: Final[str] = "answer_validators"
293293

294294
def run(
295295
self,

0 commit comments

Comments
 (0)