codehood-cli 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codehood/__init__.py +0 -0
- codehood/__main__.py +4 -0
- codehood/actions/__init__.py +0 -0
- codehood/actions/base.py +119 -0
- codehood/actions/resources.py +30 -0
- codehood/api/__init__.py +0 -0
- codehood/api/base.py +256 -0
- codehood/api/generate.py +1370 -0
- codehood/api/generated.py +3818 -0
- codehood/api/openapi.py +134 -0
- codehood/api/pages.py +53 -0
- codehood/cli/__init__.py +64 -0
- codehood/cli/api.py +422 -0
- codehood/cli/attendance.py +136 -0
- codehood/cli/auth.py +106 -0
- codehood/cli/base.py +42 -0
- codehood/cli/chill.py +52 -0
- codehood/cli/exam.py +107 -0
- codehood/cli/grades.py +185 -0
- codehood/cli/init.py +161 -0
- codehood/cli/push.py +609 -0
- codehood/cli/show.py +77 -0
- codehood/cli/uitils.py +26 -0
- codehood/functional.py +40 -0
- codehood/globs.py +71 -0
- codehood/grades.py +74 -0
- codehood/hypothesis.py +274 -0
- codehood/models/__init__.py +0 -0
- codehood/models/base.py +15 -0
- codehood/models/repo.py +187 -0
- codehood/models/validators.py +177 -0
- codehood/push/__init__.py +225 -0
- codehood/push/base.py +216 -0
- codehood/push/calendar.py +664 -0
- codehood/push/errors.py +136 -0
- codehood/push/exam.py +636 -0
- codehood/push/exclude.py +60 -0
- codehood/push/grades.py +455 -0
- codehood/push/hook.py +48 -0
- codehood/push/links.py +614 -0
- codehood/push/ours.py +78 -0
- codehood/push/plan.py +1981 -0
- codehood/push/project.py +272 -0
- codehood/push/question.py +338 -0
- codehood/push/report.py +244 -0
- codehood/push/repository.py +326 -0
- codehood/push/resource.py +576 -0
- codehood/push/run.py +1275 -0
- codehood/push/unconsumed.py +208 -0
- codehood/push/wire.py +222 -0
- codehood/py.typed +0 -0
- codehood/repo/__init__.py +62 -0
- codehood/repo/_config.py +28 -0
- codehood/repo/_layout.py +132 -0
- codehood/repo/_scaffold.py +244 -0
- codehood/repo/diff.py +71 -0
- codehood/repo/file_tracker.py +124 -0
- codehood/theme.py +101 -0
- codehood/widgets/__init__.py +0 -0
- codehood/widgets/mascot.py +76 -0
- codehood/widgets/questions/__init__.py +65 -0
- codehood/widgets/questions/base.py +119 -0
- codehood/widgets/questions/controls.py +194 -0
- codehood/widgets/questions/fill_in.py +81 -0
- codehood/widgets/questions/responses.py +137 -0
- codehood/widgets/questions/simple.py +117 -0
- codehood_cli-0.5.0.dist-info/METADATA +294 -0
- codehood_cli-0.5.0.dist-info/RECORD +71 -0
- codehood_cli-0.5.0.dist-info/WHEEL +4 -0
- codehood_cli-0.5.0.dist-info/entry_points.txt +4 -0
- codehood_cli-0.5.0.dist-info/licenses/LICENSE +21 -0
codehood/cli/init.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""
|
|
2
|
+
`codehood init`: scaffold a course repository.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Annotated
|
|
10
|
+
|
|
11
|
+
import typer
|
|
12
|
+
from pydantic import ValidationError
|
|
13
|
+
|
|
14
|
+
from ..api.base import load_token, stored_servers
|
|
15
|
+
from ..models.repo import CourseIdentity, ServerConfig
|
|
16
|
+
from ..repo import RepoError, write_repo
|
|
17
|
+
from .base import app
|
|
18
|
+
from .uitils import require
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"init",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@app.command()
|
|
26
|
+
def init(
|
|
27
|
+
path: Annotated[
|
|
28
|
+
Path,
|
|
29
|
+
typer.Argument(help="Directory to initialize. Created if missing."),
|
|
30
|
+
] = Path("."),
|
|
31
|
+
discipline: Annotated[
|
|
32
|
+
str | None,
|
|
33
|
+
typer.Option("--discipline", help="Discipline slug, e.g. 'cs101'."),
|
|
34
|
+
] = None,
|
|
35
|
+
instructor: Annotated[
|
|
36
|
+
str | None,
|
|
37
|
+
typer.Option("--instructor", help="Instructor username, e.g. 'ada'."),
|
|
38
|
+
] = None,
|
|
39
|
+
edition: Annotated[
|
|
40
|
+
str | None,
|
|
41
|
+
typer.Option("--edition", help="Edition, e.g. '2026-1'."),
|
|
42
|
+
] = None,
|
|
43
|
+
server: Annotated[
|
|
44
|
+
str | None,
|
|
45
|
+
typer.Option("--server", help="Codehood server URL this course syncs with."),
|
|
46
|
+
] = None,
|
|
47
|
+
name: Annotated[
|
|
48
|
+
str | None,
|
|
49
|
+
typer.Option(
|
|
50
|
+
"--name",
|
|
51
|
+
help="Course name, written as README.md's H1. Defaults to the discipline slug.",
|
|
52
|
+
),
|
|
53
|
+
] = None,
|
|
54
|
+
git: Annotated[
|
|
55
|
+
bool,
|
|
56
|
+
typer.Option("--git/--no-git", help="Run `git init` in the new repository."),
|
|
57
|
+
] = True,
|
|
58
|
+
examples: Annotated[
|
|
59
|
+
bool,
|
|
60
|
+
typer.Option(
|
|
61
|
+
"--examples/--no-examples", help="Write the example question and exam."
|
|
62
|
+
),
|
|
63
|
+
] = True,
|
|
64
|
+
) -> None:
|
|
65
|
+
"""
|
|
66
|
+
Scaffold a course repository.
|
|
67
|
+
"""
|
|
68
|
+
interactive = sys.stdin.isatty()
|
|
69
|
+
discipline = require(
|
|
70
|
+
"discipline",
|
|
71
|
+
discipline,
|
|
72
|
+
interactive=interactive,
|
|
73
|
+
prompt="Discipline slug",
|
|
74
|
+
)
|
|
75
|
+
instructor = require(
|
|
76
|
+
"instructor",
|
|
77
|
+
instructor,
|
|
78
|
+
interactive=interactive,
|
|
79
|
+
prompt="Instructor username",
|
|
80
|
+
)
|
|
81
|
+
edition = require(
|
|
82
|
+
"edition",
|
|
83
|
+
edition,
|
|
84
|
+
interactive=interactive,
|
|
85
|
+
prompt="Edition",
|
|
86
|
+
)
|
|
87
|
+
server = require(
|
|
88
|
+
"server",
|
|
89
|
+
server,
|
|
90
|
+
interactive=interactive,
|
|
91
|
+
prompt="Server URL",
|
|
92
|
+
default=_default_server(),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
course_identity = CourseIdentity(
|
|
97
|
+
discipline=discipline, instructor=instructor, edition=edition
|
|
98
|
+
)
|
|
99
|
+
server_config = ServerConfig(url=server)
|
|
100
|
+
except ValidationError as exc:
|
|
101
|
+
for line in _format_errors(exc):
|
|
102
|
+
typer.echo(line, err=True)
|
|
103
|
+
raise typer.Exit(code=1)
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
reports = write_repo(
|
|
107
|
+
path,
|
|
108
|
+
course_identity,
|
|
109
|
+
server_config,
|
|
110
|
+
name=name,
|
|
111
|
+
git=git,
|
|
112
|
+
examples=examples,
|
|
113
|
+
)
|
|
114
|
+
except RepoError as exc:
|
|
115
|
+
typer.echo(f"error: {exc}", err=True)
|
|
116
|
+
raise typer.Exit(code=1)
|
|
117
|
+
|
|
118
|
+
for report in reports:
|
|
119
|
+
display = str(report.path)
|
|
120
|
+
if (path / report.path).is_dir():
|
|
121
|
+
display += "/"
|
|
122
|
+
typer.echo(f"{report.status:>9} {display}")
|
|
123
|
+
|
|
124
|
+
if not _has_credentials(server_config.url):
|
|
125
|
+
typer.echo("next: codehood login")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _format_errors(exc: ValidationError) -> list[str]:
|
|
129
|
+
"""
|
|
130
|
+
Render a validation failure as one `error:` line per offending field.
|
|
131
|
+
|
|
132
|
+
Pydantic's own `str(exc)` carries a type tag, the rejected value, and a
|
|
133
|
+
link to its docs. An instructor mistyping an edition slug needs the field
|
|
134
|
+
name and the rule, so that is all this keeps.
|
|
135
|
+
"""
|
|
136
|
+
lines = []
|
|
137
|
+
for error in exc.errors():
|
|
138
|
+
field = ".".join(str(part) for part in error["loc"]) or "value"
|
|
139
|
+
message = error["msg"].removeprefix("Value error, ")
|
|
140
|
+
lines.append(f"error: {field}: {message}")
|
|
141
|
+
return lines
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _default_server() -> str | None:
|
|
145
|
+
"""
|
|
146
|
+
The one server `codehood login` has stored a key for, when there's
|
|
147
|
+
exactly one.
|
|
148
|
+
|
|
149
|
+
Covers the common one-server case (see the spec's "Every value is a
|
|
150
|
+
flag" section) without guessing between several when there's more than
|
|
151
|
+
one, or prompting anyway when there's none.
|
|
152
|
+
"""
|
|
153
|
+
servers = stored_servers()
|
|
154
|
+
return servers[0] if len(servers) == 1 else None
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _has_credentials(server_url: str) -> bool:
|
|
158
|
+
"""
|
|
159
|
+
Whether `codehood login` has already stored a key for `server_url`.
|
|
160
|
+
"""
|
|
161
|
+
return load_token(server_url) is not None
|