grip_hook.platform¶
grip_hook.platform ¶
Talking to Keep A Grip, the problem platform: credentials, the HTTP client, solve state.
The platform only ever receives scores. Diffs, questions and answers stay on the machine, exactly as with every other grip command.
STATE_FILE
module-attribute
¶
Under the repository's git dir: written by grip solve, read by grip submit.
PlatformError ¶
Credentials ¶
Problem ¶
Bases: BaseModel
A problem as served by GET /api/problems/<slug>.
Source code in src/grip_hook/platform.py
SolveState ¶
Bases: BaseModel
Everything grip submit needs, kept in :data:STATE_FILE at the repo root.
Source code in src/grip_hook/platform.py
AttemptResult ¶
Bases: BaseModel
What the platform returns for a reported attempt.
Source code in src/grip_hook/platform.py
Client ¶
A tiny client for the platform's public API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Base URL of the site. |
required |
token
|
str | None
|
An API token ( |
None
|
opener
|
_Opener | None
|
Transport, replaced in tests. Defaults to :mod: |
None
|
Source code in src/grip_hook/platform.py
from_credentials
classmethod
¶
A client for the stored credentials, raising when there are none.
Source code in src/grip_hook/platform.py
whoami ¶
problems ¶
The public catalogue, optionally for one category.
Source code in src/grip_hook/platform.py
problem ¶
One approved problem.
Source code in src/grip_hook/platform.py
submit ¶
Report an attempt.
Source code in src/grip_hook/platform.py
DiffStats
dataclass
¶
credentials_path ¶
save_credentials ¶
Write the credentials file, readable by the owner only.
Source code in src/grip_hook/platform.py
load_credentials ¶
load_credentials(home: Path | None = None, env: Mapping[str, str] | None = None) -> Credentials | None
Credentials from the environment (KEEPAGRIP_TOKEN) or the credentials file.
Source code in src/grip_hook/platform.py
forget_credentials ¶
Delete the credentials file. Returns whether there was one.
diff_stats ¶
Parse the summary line of diff.stat. Missing pieces count as zero.
Source code in src/grip_hook/platform.py
problem_context ¶
The text handed to the quiz generator alongside the diff, as data.
Source code in src/grip_hook/platform.py
attempt_payload ¶
attempt_payload(state: SolveState, report: Report, diff: Diff, tests_passed: bool | None, now: datetime | None = None) -> dict[str, Any]
Build the JSON body for POST /api/attempts from a graded quiz.
Source code in src/grip_hook/platform.py
write_state ¶
Write :data:STATE_FILE under the git dir.
Source code in src/grip_hook/platform.py
read_state ¶
Read :data:STATE_FILE, raising a helpful error when this is not a solve repo.
Source code in src/grip_hook/platform.py
problem_markdown ¶
PROBLEM.md for a fresh solve repository.