feat(generate): accept YAML in --input alongside JSON
`tsr generate --input <file>` previously only understood JSON, which was
awkward for hand-authored template libraries (e.g. ~/Projects/draw/templates/
ships *.yml scene files with embedded newlines and unquoted keys that mirror
the `tsr template` output shape).
Behavior:
- Files with .yml / .yaml extension parse as YAML; .json (or unknown
extensions whose first non-whitespace char is '{' or '[') parse as JSON.
- Inline strings starting with '{' still parse as JSON (regression-safe).
- Inline strings without leading '{' now parse as YAML, enabling
`tsr generate --input 'prompt: foo\nmodel: bar.safetensors'` without
shell-quoting a JSON object.
- All downstream key-mapping / CLI-override / character / scene / lora
/ count handling is identical to the JSON path — parsing only differs.
Implementation:
- New `_parse_generate_input(value)` helper in tensors/cli.py centralizes
source detection (file vs inline), format selection (extension or
content sniff), and rich-formatted error reporting via typer.Exit(1).
- The pre-existing inline JSON merge block in `generate` is reduced to a
single call to the helper.
- Adds pyyaml>=6.0 as a runtime dep. It was already transitively pulled
in by huggingface_hub, but we depend on it directly so the surface
contract is explicit and survives a hub re-pin.
- mypy override added for the yaml module (no upstream stubs in tree).
Tests:
- 20 new tests in tests/test_generate_input.py covering inline JSON,
inline YAML, file by extension (.json/.yml/.yaml), unknown extension
content sniffing, non-mapping rejection, malformed input handling,
CLI-flag-wins-over-input precedence, and a full smoke against the
exact draw template shape (with embedded newlines in the scene list).
- 359 -> 379 total tests. Lint clean on changed lines.
Co-Authored-By: OpenCode <noreply@anomaly.co>
This commit is contained in:
@@ -886,6 +886,7 @@ source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "httpx" },
|
||||
{ name = "huggingface-hub" },
|
||||
{ name = "pyyaml" },
|
||||
{ name = "rich" },
|
||||
{ name = "safetensors" },
|
||||
{ name = "sqlmodel" },
|
||||
@@ -924,6 +925,7 @@ requires-dist = [
|
||||
{ name = "httpx", specifier = ">=0.27.0" },
|
||||
{ name = "huggingface-hub", specifier = ">=0.25.0" },
|
||||
{ name = "python-multipart", marker = "extra == 'server'", specifier = ">=0.0.9" },
|
||||
{ name = "pyyaml", specifier = ">=6.0" },
|
||||
{ name = "rich", specifier = ">=13.0.0" },
|
||||
{ name = "safetensors", specifier = ">=0.4.0" },
|
||||
{ name = "scalar-fastapi", marker = "extra == 'server'", specifier = ">=1.6" },
|
||||
|
||||
Reference in New Issue
Block a user