Coverage for src / competitive_verifier / oj / verify / models.py: 100%
25 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
1# Python Version: 3.x
2import abc
3import pathlib
4from collections.abc import Sequence
5from typing import Any
7from pydantic import BaseModel, ConfigDict
9from competitive_verifier.models import ShellCommandLike
10from competitive_verifier.oj.verify.languages import special_comments
13class LanguageEnvironment(abc.ABC):
14 @property
15 @abc.abstractmethod
16 def name(self) -> str: ...
18 def get_compile_command(
19 self, path: pathlib.Path, *, basedir: pathlib.Path, tempdir: pathlib.Path
20 ) -> ShellCommandLike | None:
21 return None
23 @abc.abstractmethod
24 def get_execute_command(
25 self, path: pathlib.Path, *, basedir: pathlib.Path, tempdir: pathlib.Path
26 ) -> ShellCommandLike: ...
29class Language:
30 def list_attributes(
31 self, path: pathlib.Path, *, basedir: pathlib.Path
32 ) -> dict[str, Any]:
33 attributes: dict[str, Any] = dict(special_comments.list_special_comments(path))
34 attributes.setdefault("links", [])
35 attributes["links"].extend(special_comments.list_embedded_urls(path))
36 return attributes
38 @abc.abstractmethod
39 def list_dependencies(
40 self, path: pathlib.Path, *, basedir: pathlib.Path
41 ) -> list[pathlib.Path]: ...
43 def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path) -> bytes | None:
44 return None
46 @abc.abstractmethod
47 def list_environments(
48 self, path: pathlib.Path, *, basedir: pathlib.Path
49 ) -> Sequence[LanguageEnvironment]: ...
52class OjVerifyLanguageConfig(BaseModel):
53 model_config = ConfigDict(extra="allow")
56class OjVerifyUserDefinedConfig(OjVerifyLanguageConfig):
57 execute: ShellCommandLike
58 compile: ShellCommandLike | None = None
59 bundle: ShellCommandLike | None = None
60 list_attributes: ShellCommandLike | None = None
61 list_dependencies: ShellCommandLike | None = None