From cb67a4e112ff52c9b36ee2478d3e2ccb39786f54 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Sun, 15 Dec 2024 10:38:11 -0800 Subject: [PATCH] Python: add logic to dump parser stats --- pylib/aoc.py | 1 + runner.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pylib/aoc.py b/pylib/aoc.py index dc9fe37..37ff8dc 100644 --- a/pylib/aoc.py +++ b/pylib/aoc.py @@ -618,6 +618,7 @@ def raw_data(self, filename: Optional[str]) -> str: @functools.cache def _parser(self) -> parsers.BaseParser: + # print("Code defined" if self.INPUT_PARSER is not None else "Heuristic determined") if self.INPUT_PARSER is not None: if not isinstance(self.INPUT_PARSER, BaseParser): raise ValueError(f"{self.INPUT_PARSER!r} is a class and not an instance!") diff --git a/runner.py b/runner.py index bbc4599..0359756 100755 --- a/runner.py +++ b/runner.py @@ -333,6 +333,26 @@ def update_solutions(self, day: int, solutions: Optional[dict[int, int | str]] = self.solution_path.write_text("\n".join(lines) + "\n") +def show_parsers(): + for year_dir in pathlib.Path(__file__).parent.glob("20*"): + sys.path.append(str(year_dir)) + days = sorted(int(p.stem.removeprefix("d")) for p in year_dir.glob("d[0-2][0-9].py")) + year = year_dir.name + for day in days: + try: + c = ChallengeRunner(year, day) + p = c.challenge()._parser() + try: + print(p.__class__.__name__) + except Exception: + print(p) + except Exception: + pass + sys.path.remove(str(year_dir)) + return + + + @click.command() @click.option("--date", "-d", type=str, required=False, help="YYYY/dd") @click.option("--day", type=int, required=False, help="AoC day")