Skip to content

Commit 8e5991a

Browse files
sjquantclaude
andcommitted
✨ Guard CLI entrypoint, fix tempfile default, widen typer pin
- Add quickthumb/_entry.py as the script entrypoint so a missing typer install prints a helpful pip install hint instead of a raw ImportError - Replace hardcoded "/tmp" with tempfile.gettempdir() for Windows compat - Widen typer version pin from <0.25.0 to <1.0 to reduce resolver conflicts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6c33ca0 commit 8e5991a

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ rembg = [
4646
"rembg>=2.0.50,<3.0.0",
4747
]
4848
cli = [
49-
"typer>=0.24.1,<0.25.0",
49+
"typer>=0.24.1,<1.0",
5050
"watchfiles>=1.0.0,<2.0.0",
5151
]
5252

5353
[project.scripts]
54-
quickthumb = "quickthumb.cli:main"
54+
quickthumb = "quickthumb._entry:main"
5555

5656
[dependency-groups]
5757
docs = [

quickthumb/_entry.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
6+
def main() -> None:
7+
try:
8+
import typer as _ # noqa: F401
9+
except ImportError:
10+
print(
11+
"typer is not installed. Install it with:\n pip install 'quickthumb[cli]'",
12+
file=sys.stderr,
13+
)
14+
sys.exit(1)
15+
16+
from quickthumb.cli import main as _main
17+
18+
_main()

quickthumb/canvas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import hashlib
33
import math
44
import os
5+
import tempfile
56
import warnings
67
from collections.abc import Callable
78
from dataclasses import dataclass, field
@@ -2328,7 +2329,7 @@ def _download_and_cache_font(self, url: str) -> str:
23282329
url_hash = hashlib.md5(url.encode()).hexdigest()
23292330
extension = os.path.splitext(url)[1] or ".ttf"
23302331
cache_filename = f"quickthumb_font_{url_hash}{extension}"
2331-
cache_dir = os.environ.get("QUICKTHUMB_FONT_CACHE_DIR", "/tmp")
2332+
cache_dir = os.environ.get("QUICKTHUMB_FONT_CACHE_DIR", tempfile.gettempdir())
23322333
os.makedirs(cache_dir, exist_ok=True)
23332334
cache_path = os.path.join(cache_dir, cache_filename)
23342335

specs/TASKS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@
5959
- [DONE] CLI `render`: catch `FileNotFoundError` / `PermissionError` from `spec.read_text()` and exit with code 1
6060
- [DONE] CLI `render`: catch `json.JSONDecodeError` from `Canvas.from_json()` and exit with code 1
6161
- [DONE] `_substitute_vars`: raise `ValidationError` on unresolved `$VAR` / `${VAR}` placeholders (currently passes them through silently)
62-
- [TODO] Guard CLI entrypoint import: print a helpful message and exit if `typer` is not installed instead of crashing with `ImportError`
62+
- [REVIEW] Guard CLI entrypoint import: print a helpful message and exit if `typer` is not installed instead of crashing with `ImportError`
6363
- [DONE] CLI `render`: validate `--var` entries contain `=`; raise a clear error when `--var keyonly` is passed (currently silently maps to empty string)
6464
- [DONE] CLI `render`: replace bare `except Exception` with `except (RenderingError, OSError)` to avoid masking real bugs
6565
- [DONE] CLI `render`: validate `--quality` is in `1–95` range (`typer.Option(..., min=1, max=95)`)
6666
- [DONE] CLI `render`: validate `--format` is one of `PNG`, `JPEG`, `WEBP`; reject unknown values early
6767

6868
### P2 — Font Cache Hardening (from code review)
6969

70-
- [TODO] Use `tempfile.gettempdir()` instead of hardcoded `"/tmp"` as the default font cache dir (fixes Windows compatibility)
70+
- [REVIEW] Use `tempfile.gettempdir()` instead of hardcoded `"/tmp"` as the default font cache dir (fixes Windows compatibility)
7171
- [TODO] Validate downloaded font content before writing to cache (currently writes arbitrary data from any URL)
7272
- [DONE] Call `os.makedirs(cache_dir, exist_ok=True)` before writing cached font; `QUICKTHUMB_FONT_CACHE_DIR` pointing to a non-existent dir currently crashes with `FileNotFoundError`
7373

7474
### P2 — CLI Polish (from code review)
7575

76-
- [TODO] Rename `format` parameter to `fmt` or `output_format` internally — currently shadows Python's built-in `format()`
77-
- [TODO] Widen typer version pin from `>=0.24.1,<0.25.0` to `>=0.24.1,<1.0` to avoid unnecessary resolver conflicts
76+
- [DONE] Rename `format` parameter to `fmt` or `output_format` internally — currently shadows Python's built-in `format()`
77+
- [REVIEW] Widen typer version pin from `>=0.24.1,<0.25.0` to `>=0.24.1,<1.0` to avoid unnecessary resolver conflicts
7878

7979
### P3 — Lower Priority
8080

0 commit comments

Comments
 (0)