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.
Files changed (71) hide show
  1. codehood/__init__.py +0 -0
  2. codehood/__main__.py +4 -0
  3. codehood/actions/__init__.py +0 -0
  4. codehood/actions/base.py +119 -0
  5. codehood/actions/resources.py +30 -0
  6. codehood/api/__init__.py +0 -0
  7. codehood/api/base.py +256 -0
  8. codehood/api/generate.py +1370 -0
  9. codehood/api/generated.py +3818 -0
  10. codehood/api/openapi.py +134 -0
  11. codehood/api/pages.py +53 -0
  12. codehood/cli/__init__.py +64 -0
  13. codehood/cli/api.py +422 -0
  14. codehood/cli/attendance.py +136 -0
  15. codehood/cli/auth.py +106 -0
  16. codehood/cli/base.py +42 -0
  17. codehood/cli/chill.py +52 -0
  18. codehood/cli/exam.py +107 -0
  19. codehood/cli/grades.py +185 -0
  20. codehood/cli/init.py +161 -0
  21. codehood/cli/push.py +609 -0
  22. codehood/cli/show.py +77 -0
  23. codehood/cli/uitils.py +26 -0
  24. codehood/functional.py +40 -0
  25. codehood/globs.py +71 -0
  26. codehood/grades.py +74 -0
  27. codehood/hypothesis.py +274 -0
  28. codehood/models/__init__.py +0 -0
  29. codehood/models/base.py +15 -0
  30. codehood/models/repo.py +187 -0
  31. codehood/models/validators.py +177 -0
  32. codehood/push/__init__.py +225 -0
  33. codehood/push/base.py +216 -0
  34. codehood/push/calendar.py +664 -0
  35. codehood/push/errors.py +136 -0
  36. codehood/push/exam.py +636 -0
  37. codehood/push/exclude.py +60 -0
  38. codehood/push/grades.py +455 -0
  39. codehood/push/hook.py +48 -0
  40. codehood/push/links.py +614 -0
  41. codehood/push/ours.py +78 -0
  42. codehood/push/plan.py +1981 -0
  43. codehood/push/project.py +272 -0
  44. codehood/push/question.py +338 -0
  45. codehood/push/report.py +244 -0
  46. codehood/push/repository.py +326 -0
  47. codehood/push/resource.py +576 -0
  48. codehood/push/run.py +1275 -0
  49. codehood/push/unconsumed.py +208 -0
  50. codehood/push/wire.py +222 -0
  51. codehood/py.typed +0 -0
  52. codehood/repo/__init__.py +62 -0
  53. codehood/repo/_config.py +28 -0
  54. codehood/repo/_layout.py +132 -0
  55. codehood/repo/_scaffold.py +244 -0
  56. codehood/repo/diff.py +71 -0
  57. codehood/repo/file_tracker.py +124 -0
  58. codehood/theme.py +101 -0
  59. codehood/widgets/__init__.py +0 -0
  60. codehood/widgets/mascot.py +76 -0
  61. codehood/widgets/questions/__init__.py +65 -0
  62. codehood/widgets/questions/base.py +119 -0
  63. codehood/widgets/questions/controls.py +194 -0
  64. codehood/widgets/questions/fill_in.py +81 -0
  65. codehood/widgets/questions/responses.py +137 -0
  66. codehood/widgets/questions/simple.py +117 -0
  67. codehood_cli-0.5.0.dist-info/METADATA +294 -0
  68. codehood_cli-0.5.0.dist-info/RECORD +71 -0
  69. codehood_cli-0.5.0.dist-info/WHEEL +4 -0
  70. codehood_cli-0.5.0.dist-info/entry_points.txt +4 -0
  71. 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