Coverage for src / competitive_verifier / documents / main.py: 95%
37 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-05 16:00 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-05 16:00 +0000
1import pathlib
2from argparse import ArgumentParser
3from logging import getLogger
4from typing import Literal
6from pydantic import Field
8from competitive_verifier import config
9from competitive_verifier.arg import (
10 IgnoreErrorArguments,
11 IncludeExcludeArguments,
12 ResultJsonArguments,
13 VerboseArguments,
14 VerifyFilesJsonArguments,
15 WriteSummaryArguments,
16)
17from competitive_verifier.inout import MergeResult
18from competitive_verifier.models import (
19 VerificationInput,
20)
22from .builder import DocumentBuilder
24logger = getLogger(__name__)
27def get_default_docs_dir() -> pathlib.Path:
28 default_docs_dir = config.get_config_dir() / "docs"
29 oj_verify_docs_dir = pathlib.Path(".verify-helper/docs")
30 if not default_docs_dir.exists() and oj_verify_docs_dir.exists(): 30 ↛ 31line 30 didn't jump to line 31 because the condition on line 30 was never true
31 return oj_verify_docs_dir
32 return default_docs_dir
35class Docs(
36 IncludeExcludeArguments,
37 WriteSummaryArguments,
38 IgnoreErrorArguments,
39 ResultJsonArguments,
40 VerifyFilesJsonArguments,
41 VerboseArguments,
42):
43 subcommand: Literal["docs"] = Field(
44 default="docs",
45 description="Create documents",
46 )
47 docs: pathlib.Path | None = None
48 destination: pathlib.Path
50 @classmethod
51 def add_parser(cls, parser: ArgumentParser):
52 super().add_parser(parser)
53 destination = config.get_config_dir() / "_jekyll"
54 parser.add_argument(
55 "--docs",
56 type=pathlib.Path,
57 help=f"Document settings directory. default: {get_default_docs_dir().as_posix()}",
58 )
59 parser.add_argument(
60 "--destination",
61 type=pathlib.Path,
62 default=destination,
63 help=f"Output directory for markdown document. default: {destination.as_posix()}",
64 )
66 def _run(self) -> bool:
67 logger.debug("arguments:%s", self)
68 logger.info("path of verify_files_json=%s", self.verify_files_json)
69 logger.info("path of result_json=%s", [str(p) for p in self.result_json])
70 verifications = VerificationInput.parse_file_relative(self.verify_files_json)
72 result = MergeResult(
73 subcommand="merge-result",
74 result_json=self.result_json,
75 ).merge()
77 if self.write_summary:
78 self.write_result(result)
80 logger.debug("verifications=%s", verifications)
81 logger.debug("result=%s", result)
83 return DocumentBuilder(
84 verifications=verifications,
85 result=result,
86 docs_dir=self.docs or get_default_docs_dir(),
87 destination_dir=self.destination,
88 include=self.include,
89 exclude=self.exclude,
90 ).build()