Files
tensors/pyproject.toml
T
aladac c911abfe69 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>
2026-05-18 21:16:11 +02:00

135 lines
3.0 KiB
TOML

[project]
name = "tensors"
dynamic = ["version"]
description = "Read safetensor metadata and fetch CivitAI model information"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"safetensors>=0.4.0",
"httpx>=0.27.0",
"rich>=13.0.0",
"typer>=0.15.0",
"websocket-client>=1.9.0",
"huggingface_hub>=0.25.0",
"sqlmodel>=0.0.33",
"pyyaml>=6.0",
]
[project.optional-dependencies]
server = ["fastapi>=0.115", "uvicorn>=0.30", "scalar-fastapi>=1.6", "websockets>=12.0", "python-multipart>=0.0.9"]
[project.scripts]
tsr = "tensors:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.version]
path = "tensors/__init__.py"
[tool.hatch.build.targets.wheel]
packages = ["tensors"]
[dependency-groups]
dev = [
"nuitka>=2.0",
"ruff>=0.9.0",
"mypy>=1.14.0",
"pytest>=8.0",
"pytest-cov>=4.1",
"pre-commit>=3.6",
"respx>=0.22.0",
"fastapi>=0.115",
"uvicorn>=0.30",
"scalar-fastapi>=1.6",
"websockets>=12.0",
"python-multipart>=0.0.9",
]
[tool.ruff]
target-version = "py312"
line-length = 130
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
"ARG", # flake8-unused-arguments
"SIM", # flake8-simplify
"TCH", # flake8-type-checking
"PTH", # flake8-use-pathlib
"PL", # pylint
"RUF", # ruff-specific
]
ignore = [
"PLR0912", # Too many branches - search param building needs many conditionals
"PLR0913", # Too many arguments - CLI commands need many options
]
[tool.ruff.lint.per-file-ignores]
"tests/**" = ["PLR2004", "ARG001", "ARG002", "ARG005", "TC001", "TC003", "PLC0415", "F841"]
[tool.ruff.lint.isort]
known-first-party = ["tensors"]
[tool.mypy]
python_version = "3.12"
strict = true
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
disallow_untyped_decorators = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_no_return = true
follow_imports = "silent"
ignore_missing_imports = false
[[tool.mypy.overrides]]
module = ["safetensors.*"]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = ["uvicorn.*"]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = ["scalar_fastapi.*"]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = ["huggingface_hub.*"]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = ["websockets.*"]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = ["yaml.*"]
ignore_missing_imports = true
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-v --cov=tensors --cov-report=term-missing"
[tool.coverage.run]
source = ["tensors"]
branch = true
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"if TYPE_CHECKING:",
"if __name__ == .__main__.:",
]