Skip to content

Commit f571fc9

Browse files
committed
Use PrintBar instead of 'message()' fn
1 parent 0cf22fe commit f571fc9

File tree

7 files changed

+174
-250
lines changed

7 files changed

+174
-250
lines changed

bin/export.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
has_substitute,
2424
inc_label,
2525
log,
26-
message,
27-
MessageType,
2826
normalize_yaml_value,
2927
parse_yaml,
3028
PrintBar,
@@ -138,6 +136,8 @@ def build_problem_zip(problem: Problem, output: Path) -> bool:
138136
error("zip needs the ruamel.yaml python3 library. Install python[3]-ruamel.yaml.")
139137
return False
140138

139+
bar = PrintBar("Zip", len(problem.name) + 4, item=problem)
140+
141141
from ruamel.yaml.comments import CommentedMap
142142

143143
languages = select_languages([problem])
@@ -167,7 +167,7 @@ def build_problem_zip(problem: Problem, output: Path) -> bool:
167167
if problem.custom_output:
168168
files.append((f"{OutputValidator.source_dir}/**/*", True))
169169

170-
message("preparing zip file content", "Zip", problem.path, color_type=MessageType.LOG)
170+
bar.log("preparing zip file content")
171171

172172
# prepare files inside dir
173173
export_dir = problem.tmpdir / "export"
@@ -257,11 +257,13 @@ def add_testcase(in_file: Path) -> None:
257257
text,
258258
problem.settings.constants,
259259
pattern=config.CONSTANT_SUBSTITUTE_REGEX,
260-
bar=PrintBar("Zip"),
260+
bar=bar,
261261
)
262262
f.unlink()
263263
f.write_text(text)
264264

265+
bar = bar.start(output)
266+
265267
# move pdfs
266268
if config.args.legacy and languages:
267269
for type in PdfType:
@@ -277,7 +279,7 @@ def add_testcase(in_file: Path) -> None:
277279
if not file.exists():
278280
continue
279281
if out.exists():
280-
warn(f"can't add {path} (already exists).")
282+
bar.warn(f"can't add {path} (already exists).")
281283
file.unlink()
282284
continue
283285
out.parent.mkdir(parents=True, exist_ok=True)
@@ -370,12 +372,7 @@ def add_testcase(in_file: Path) -> None:
370372
if f.is_file():
371373
out = Path("problem_statement") / f.relative_to(problem.path / d)
372374
if out.exists():
373-
message(
374-
f"Can not export {f.relative_to(problem.path)} as {out}",
375-
"Zip",
376-
output,
377-
color_type=MessageType.WARN,
378-
)
375+
bar.warn(f"Cannot export {f.relative_to(problem.path)} as {out}")
379376
else:
380377
add_file(out, f)
381378
shutil.rmtree(export_dir / d)
@@ -397,7 +394,7 @@ def add_testcase(in_file: Path) -> None:
397394
write_yaml(yaml_data, yaml_path)
398395

399396
# Build .ZIP file.
400-
message("writing zip file", "Zip", output, color_type=MessageType.LOG)
397+
bar.log("writing zip file")
401398
try:
402399
zf = zipfile.ZipFile(output, mode="w", compression=zipfile.ZIP_DEFLATED, allowZip64=False)
403400

@@ -410,7 +407,7 @@ def add_testcase(in_file: Path) -> None:
410407

411408
# Done.
412409
zf.close()
413-
message("done", "Zip", color_type=MessageType.LOG)
410+
bar.log("done")
414411
eprint()
415412
except Exception:
416413
return False

bin/fuzz.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
error,
1717
fatal,
1818
has_ryaml,
19-
message,
20-
MessageType,
19+
PrintBar,
2120
ProgressBar,
2221
read_yaml,
2322
ryaml_get_or_add,
@@ -261,8 +260,6 @@ def run(self) -> bool:
261260
error("No submissions found.")
262261
return False
263262

264-
message("Press CTRL+C to stop\n", "Fuzz", color_type=MessageType.LOG)
265-
266263
def runner(task: GeneratorTask | SubmissionTask) -> None:
267264
task.run(bar)
268265

@@ -286,6 +283,9 @@ def runner(task: GeneratorTask | SubmissionTask) -> None:
286283
],
287284
)
288285
max_len += len(f"{self.tmp_ids}: ")
286+
# we use a PrintBar after an aboard
287+
printbar = PrintBar("Fuzz", max_len=max_len)
288+
printbar.log("Press CTRL+C to stop\n")
289289
bar = FuzzProgressBar(self.queue, "Fuzz", max_len=max_len)
290290

291291
def soft_exit(sig: Any, frame: Any) -> None:
@@ -295,11 +295,7 @@ def soft_exit(sig: Any, frame: Any) -> None:
295295
self.queue.abort()
296296
with bar:
297297
eprint(bar.carriage_return)
298-
message(
299-
"Running interrupted (waiting on remaining tasks)\n",
300-
"\nFuzz",
301-
color_type=MessageType.ERROR,
302-
)
298+
printbar.error("Running interrupted (waiting on remaining tasks)\n")
303299

304300
old_handler = signal.signal(signal.SIGINT, soft_exit)
305301

@@ -315,8 +311,8 @@ def soft_exit(sig: Any, frame: Any) -> None:
315311

316312
for submission, verdicts in self.summary.items():
317313
msg = ", ".join(f"{v.color()}{v.short()}{Style.RESET_ALL}" for v in sorted(verdicts))
318-
message(msg, "Fuzz", submission.name)
319-
message(f"Found {self.added} testcases in total.", "Fuzz")
314+
printbar.start(submission).log(msg, color="")
315+
printbar.log(f"Found {self.added} testcases in total.", color="")
320316

321317
if self.queue.aborted:
322318
fatal("Running interrupted")

0 commit comments

Comments
 (0)