paces 0.0.24__tar.gz → 0.0.25__tar.gz
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.
- {paces-0.0.24 → paces-0.0.25}/PKG-INFO +1 -1
- {paces-0.0.24 → paces-0.0.25}/paces/ask.py +38 -53
- paces-0.0.25/paces/ask_contract.py +142 -0
- {paces-0.0.24 → paces-0.0.25}/pyproject.toml +1 -1
- {paces-0.0.24 → paces-0.0.25}/tests/test_ask.py +11 -0
- {paces-0.0.24 → paces-0.0.25}/.gitignore +0 -0
- {paces-0.0.24 → paces-0.0.25}/LICENSE +0 -0
- {paces-0.0.24 → paces-0.0.25}/README.md +0 -0
- {paces-0.0.24 → paces-0.0.25}/docs/README.md +0 -0
- {paces-0.0.24 → paces-0.0.25}/docs/alignment/README.md +0 -0
- {paces-0.0.24 → paces-0.0.25}/docs/poc-reference/README.md +0 -0
- {paces-0.0.24 → paces-0.0.25}/docs/poc-reference/artifacts/clips.json +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/__init__.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/__main__.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/bodies/__init__.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/bodies/_base.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/bodies/derivation.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/bodies/document.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/bodies/signal.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/bodies/step.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/corrections.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/cues.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/data/ask/ask.css +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/data/ask/ask.html +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/data/ask/ask.js +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/derivation.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/edits.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/evidence.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/excerpts.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/measure.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/model.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/pose.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/projection.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/render.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/segmentation.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/segmenters.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/timed_text.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/paces/tools.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/audio_synth.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/data/body_schemas.json +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/data/routine.json +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/poc_fixture.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_chapters.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_cli_surface.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_corrections.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_cues.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_derivation.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_edit_protection_residuals.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_edits.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_evidence.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_evidence_schemas.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_excerpts.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_measure.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_pose.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_render_media.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_roundtrip_poc.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_segment.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_smoke.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/test_vertical_slice.py +0 -0
- {paces-0.0.24 → paces-0.0.25}/tests/video_synth.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: paces
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.25
|
|
4
4
|
Summary: Turn instructional media into structured, interactive learning material
|
|
5
5
|
Project-URL: Homepage, https://github.com/thorwhalen/paces
|
|
6
6
|
Project-URL: Repository, https://github.com/thorwhalen/paces
|
|
@@ -48,15 +48,19 @@ from paces.corrections import (
|
|
|
48
48
|
normalize_corrections,
|
|
49
49
|
time_str,
|
|
50
50
|
)
|
|
51
|
+
from paces.ask_contract import (
|
|
52
|
+
ANSWERS_KIND,
|
|
53
|
+
CONTRACT_VERSION,
|
|
54
|
+
PROPOSAL_KIND,
|
|
55
|
+
AnswersDocument,
|
|
56
|
+
Proposal,
|
|
57
|
+
ProposedStep,
|
|
58
|
+
Snap,
|
|
59
|
+
contract_schemas,
|
|
60
|
+
)
|
|
51
61
|
from paces.model import seconds_per_unit
|
|
52
62
|
from paces.segmentation import Segmentation
|
|
53
63
|
|
|
54
|
-
PROPOSAL_KIND = "PacesAskProposal"
|
|
55
|
-
ANSWERS_KIND = "PacesAskAnswers"
|
|
56
|
-
#: The proposal/answers contract version. Both documents carry it; a reader
|
|
57
|
-
#: refuses any other, so a page and a loader of different ages fail loudly.
|
|
58
|
-
CONTRACT_VERSION = 1
|
|
59
|
-
|
|
60
64
|
#: How far a tap may land from a snap target and still snap to it (§7.3 step
|
|
61
65
|
#: 3). It is the merge tolerance on purpose: both absorb the same thing, the
|
|
62
66
|
#: imprecision of a human tapping along, so one number serves both.
|
|
@@ -66,7 +70,6 @@ DFLT_SNAP_S = DFLT_MERGE_TOLERANCE_S
|
|
|
66
70
|
DFLT_MAX_GRID_TICKS = 2000
|
|
67
71
|
|
|
68
72
|
_ASSETS = files("paces") / "data" / "ask"
|
|
69
|
-
_ANSWERS_KEYS = {"kind", "version", "k", "corrections", "boundaries", "proposal"}
|
|
70
73
|
|
|
71
74
|
|
|
72
75
|
def _grid_ticks(seg: Segmentation, lo: float, hi: float, *, limit: int) -> list[str]:
|
|
@@ -117,32 +120,29 @@ def propose(
|
|
|
117
120
|
k, why = None, "nothing to count yet: the segmenter found no cuts"
|
|
118
121
|
extent = (cuts[0], cuts[-1]) if len(cuts) >= 2 else None
|
|
119
122
|
ticks = _grid_ticks(seg, *extent, limit=max_grid_ticks) if extent else []
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"name": step.name,
|
|
136
|
-
"spans": [[time_str(a), time_str(b)] for a, b in step.spans],
|
|
137
|
-
}
|
|
123
|
+
return Proposal(
|
|
124
|
+
title=title,
|
|
125
|
+
media=media,
|
|
126
|
+
method=seg.method,
|
|
127
|
+
flags=list(seg.flags),
|
|
128
|
+
k=k,
|
|
129
|
+
k_evidence=why,
|
|
130
|
+
extent=tuple(time_str(t) for t in extent) if extent else None,
|
|
131
|
+
cuts=[time_str(t) for t in interior],
|
|
132
|
+
steps=[
|
|
133
|
+
ProposedStep(
|
|
134
|
+
id=step.id,
|
|
135
|
+
name=step.name,
|
|
136
|
+
spans=[(time_str(a), time_str(b)) for a, b in step.spans],
|
|
137
|
+
)
|
|
138
138
|
for step in seg.steps
|
|
139
139
|
],
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
min_step_s=time_str(min_step_s),
|
|
141
|
+
snap=Snap(
|
|
142
|
+
window_s=time_str(snap_s),
|
|
143
|
+
targets=sorted({*map(time_str, interior), *ticks}, key=float),
|
|
144
|
+
),
|
|
145
|
+
).model_dump(by_alias=True, mode="json")
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
def render_ask_page(proposal: Mapping, *, author: str = "") -> str:
|
|
@@ -224,29 +224,14 @@ def load_answers(answers: Mapping) -> Answers:
|
|
|
224
224
|
... "corrections": [{"verb": "split", "anchorT": "15"}]})
|
|
225
225
|
Answers(k=4, corrections=(Correction(verb='split', anchor_t=15.0, span=None, step_id=None, author='', at='', media_key=None, reason=''),), boundaries=None)
|
|
226
226
|
"""
|
|
227
|
-
if not isinstance(answers, Mapping)
|
|
228
|
-
got = (
|
|
229
|
-
answers.get("kind")
|
|
230
|
-
if isinstance(answers, Mapping)
|
|
231
|
-
else type(answers).__name__
|
|
232
|
-
)
|
|
233
|
-
raise ValueError(
|
|
234
|
-
f"expected {ANSWERS_KIND} answers (from the ask page), got {got!r}"
|
|
235
|
-
)
|
|
236
|
-
unknown = sorted(set(answers) - _ANSWERS_KEYS)
|
|
237
|
-
if unknown:
|
|
238
|
-
raise ValueError(f"unknown answers keys {unknown}")
|
|
239
|
-
version = answers.get("version")
|
|
240
|
-
if version != CONTRACT_VERSION:
|
|
227
|
+
if not isinstance(answers, Mapping):
|
|
241
228
|
raise ValueError(
|
|
242
|
-
f"expected
|
|
243
|
-
"(
|
|
229
|
+
f"expected {ANSWERS_KIND} answers (from the ask page), "
|
|
230
|
+
f"got {type(answers).__name__!r}"
|
|
244
231
|
)
|
|
245
|
-
|
|
246
|
-
if k is not None and (isinstance(k, bool) or not isinstance(k, int) or k < 1):
|
|
247
|
-
raise ValueError(f"k must be a positive integer or null, got {k!r}")
|
|
232
|
+
doc = AnswersDocument.model_validate(dict(answers))
|
|
248
233
|
return Answers(
|
|
249
|
-
k=k,
|
|
250
|
-
corrections=normalize_corrections(
|
|
251
|
-
boundaries=_answered_boundaries(
|
|
234
|
+
k=doc.k,
|
|
235
|
+
corrections=normalize_corrections(doc.corrections),
|
|
236
|
+
boundaries=_answered_boundaries(doc.boundaries),
|
|
252
237
|
)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""The ask contract as types: the proposal a machine writes and the answers a human returns.
|
|
2
|
+
|
|
3
|
+
:mod:`paces.ask` produces and reads these two JSON documents (``docs/alignment/07
|
|
4
|
+
§7.4``), and every other UI (the real frontend, a CLI prompt, an agent) speaks
|
|
5
|
+
the same two. They are declared here as pydantic models, so the shape is
|
|
6
|
+
written once, ``load_answers`` validates against it, and the JSON Schema a
|
|
7
|
+
TypeScript side needs comes from :func:`contract_schemas` and not from a second
|
|
8
|
+
hand-written copy.
|
|
9
|
+
|
|
10
|
+
Field names are camelCase on the wire, as the page reads them. Times are
|
|
11
|
+
decimal strings, as everywhere on paces' wire.
|
|
12
|
+
|
|
13
|
+
>>> sorted(contract_schemas())
|
|
14
|
+
['answers', 'proposal']
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import Any, Literal
|
|
20
|
+
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
22
|
+
from pydantic.alias_generators import to_camel
|
|
23
|
+
|
|
24
|
+
PROPOSAL_KIND = "PacesAskProposal"
|
|
25
|
+
ANSWERS_KIND = "PacesAskAnswers"
|
|
26
|
+
#: The proposal/answers contract version. Both documents carry it; a reader
|
|
27
|
+
#: refuses any other, so a page and a loader of different ages fail loudly.
|
|
28
|
+
CONTRACT_VERSION = 1
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class _Wire(BaseModel):
|
|
32
|
+
model_config = ConfigDict(
|
|
33
|
+
alias_generator=to_camel, populate_by_name=True, frozen=True, extra="forbid"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ProposedStep(_Wire):
|
|
38
|
+
"""A step as the machine found it: its spans, as ``[start, end]`` time strings."""
|
|
39
|
+
|
|
40
|
+
id: str
|
|
41
|
+
name: str | None = None
|
|
42
|
+
spans: list[tuple[str, str]]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class Snap(_Wire):
|
|
46
|
+
"""Where a tap lands: within ``window_s`` of a target (a cut, or a grid tick)."""
|
|
47
|
+
|
|
48
|
+
window_s: str
|
|
49
|
+
targets: list[str]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class Proposal(_Wire):
|
|
53
|
+
"""What the machine pre-computes for a human to confirm (:func:`paces.ask.propose`)."""
|
|
54
|
+
|
|
55
|
+
kind: Literal["PacesAskProposal"] = PROPOSAL_KIND
|
|
56
|
+
version: Literal[1] = CONTRACT_VERSION
|
|
57
|
+
answers_kind: Literal["PacesAskAnswers"] = ANSWERS_KIND
|
|
58
|
+
title: str = ""
|
|
59
|
+
media: str | None = None
|
|
60
|
+
method: str | None = None
|
|
61
|
+
flags: list[str] = []
|
|
62
|
+
k: int | None
|
|
63
|
+
k_evidence: str
|
|
64
|
+
extent: tuple[str, str] | None
|
|
65
|
+
cuts: list[str]
|
|
66
|
+
steps: list[ProposedStep]
|
|
67
|
+
min_step_s: str
|
|
68
|
+
snap: Snap
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class AnswersDocument(_Wire):
|
|
72
|
+
"""What the page exports (:func:`paces.ask.load_answers` reads it).
|
|
73
|
+
|
|
74
|
+
``corrections`` is a :mod:`paces.corrections` log, each entry validated by
|
|
75
|
+
:func:`paces.corrections.normalize_corrections`. ``boundaries`` holds the
|
|
76
|
+
cuts tapped when the proposal had none to correct, from 0 to the media's
|
|
77
|
+
end, as time strings or seconds.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
kind: str = Field("", validate_default=True)
|
|
81
|
+
version: int
|
|
82
|
+
k: int | None = None
|
|
83
|
+
corrections: list[dict[str, Any]] = []
|
|
84
|
+
boundaries: list[Any] | None = None
|
|
85
|
+
proposal: Any = None
|
|
86
|
+
|
|
87
|
+
@model_validator(mode="before")
|
|
88
|
+
@classmethod
|
|
89
|
+
def _known_keys(cls, data: Any) -> Any:
|
|
90
|
+
if isinstance(data, dict):
|
|
91
|
+
known = set(cls.model_fields) | {
|
|
92
|
+
f.alias for f in cls.model_fields.values() if f.alias
|
|
93
|
+
}
|
|
94
|
+
unknown = sorted(set(data) - known)
|
|
95
|
+
if unknown:
|
|
96
|
+
raise ValueError(f"unknown answers keys {unknown}")
|
|
97
|
+
return data
|
|
98
|
+
|
|
99
|
+
@field_validator("kind")
|
|
100
|
+
@classmethod
|
|
101
|
+
def _kind(cls, v: str) -> str:
|
|
102
|
+
if v != ANSWERS_KIND:
|
|
103
|
+
raise ValueError(
|
|
104
|
+
f"expected {ANSWERS_KIND} answers (from the ask page), got {v!r}"
|
|
105
|
+
)
|
|
106
|
+
return v
|
|
107
|
+
|
|
108
|
+
@field_validator("version", mode="before")
|
|
109
|
+
@classmethod
|
|
110
|
+
def _version(cls, v: Any) -> Any:
|
|
111
|
+
if v != CONTRACT_VERSION or isinstance(v, bool):
|
|
112
|
+
raise ValueError(
|
|
113
|
+
f"expected version {CONTRACT_VERSION} answers, got version {v!r} "
|
|
114
|
+
"(re-export them from a page made by this paces)"
|
|
115
|
+
)
|
|
116
|
+
return v
|
|
117
|
+
|
|
118
|
+
@field_validator("k", mode="before")
|
|
119
|
+
@classmethod
|
|
120
|
+
def _k(cls, v: Any) -> Any:
|
|
121
|
+
if v is not None and (isinstance(v, bool) or not isinstance(v, int) or v < 1):
|
|
122
|
+
raise ValueError(f"k must be a positive integer or null, got {v!r}")
|
|
123
|
+
return v
|
|
124
|
+
|
|
125
|
+
@field_validator("boundaries", mode="before")
|
|
126
|
+
@classmethod
|
|
127
|
+
def _boundaries_is_a_list(cls, v: Any) -> Any:
|
|
128
|
+
if v is not None and (not isinstance(v, list) or len(v) < 2):
|
|
129
|
+
raise ValueError(f"boundaries must be a list of 2 or more times, got {v!r}")
|
|
130
|
+
return v
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def contract_schemas() -> dict[str, dict]:
|
|
134
|
+
"""The JSON Schema of both documents, for a UI written in another language.
|
|
135
|
+
|
|
136
|
+
>>> contract_schemas()["proposal"]["properties"]["kind"]["const"]
|
|
137
|
+
'PacesAskProposal'
|
|
138
|
+
"""
|
|
139
|
+
return {
|
|
140
|
+
"proposal": Proposal.model_json_schema(by_alias=True),
|
|
141
|
+
"answers": AnswersDocument.model_json_schema(by_alias=True),
|
|
142
|
+
}
|
|
@@ -542,3 +542,14 @@ def test_propose_takes_the_min_step_as_a_keyword():
|
|
|
542
542
|
def test_the_status_line_stays_on_screen():
|
|
543
543
|
css = (files("paces") / "data" / "ask" / "ask.css").read_text()
|
|
544
544
|
assert re.search(r"#status \{[^}]*position: sticky", css)
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
def test_the_contract_is_declared_as_models():
|
|
548
|
+
from paces.ask_contract import AnswersDocument, Proposal, contract_schemas
|
|
549
|
+
|
|
550
|
+
p = propose(segment(boundaries=CUTS), media="v.mp4", title="t")
|
|
551
|
+
assert Proposal.model_validate(p).model_dump(by_alias=True, mode="json") == p
|
|
552
|
+
schemas = contract_schemas()
|
|
553
|
+
assert schemas["proposal"]["properties"]["minStepS"]["type"] == "string"
|
|
554
|
+
assert schemas["answers"]["additionalProperties"] is False
|
|
555
|
+
assert AnswersDocument.model_validate(_answers()).k == 4
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|