Skip to content

Commit 13557e7

Browse files
Add deps and make linter happy
1 parent fafbeee commit 13557e7

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,20 @@ jobs:
6666
sudo apt-get update
6767
sudo apt-get install -y --no-install-recommends \
6868
libgdiplus \
69+
libc6-dev \
6970
libfontconfig1 \
7071
fontconfig \
7172
fonts-dejavu \
7273
fonts-liberation
74+
# Ubuntu installs libgdiplus as `libgdiplus.so.0` only — .NET's
75+
# System.Drawing.Common dlopen()s `libgdiplus` (no version suffix)
76+
# and fails with "Type initializer for 'Gdip' threw an exception"
77+
# without this alias. Idempotent: the package may install the
78+
# symlink directly on some releases.
79+
if [ ! -e /usr/lib/x86_64-linux-gnu/libgdiplus.so ]; then
80+
sudo ln -s /usr/lib/x86_64-linux-gnu/libgdiplus.so.0 \
81+
/usr/lib/x86_64-linux-gnu/libgdiplus.so
82+
fi
7383
7484
- run: pip install -e ".[dev]"
7585

pyproject.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ select = ["E", "F", "W", "I", "N", "UP", "B", "A", "C4", "SIM", "RUF"]
7979
ignore = ["E501"]
8080

8181
[tool.ruff.lint.per-file-ignores]
82-
# Typer's CLI pattern requires `typer.Option(...)` and `Path.cwd()` as
83-
# argument defaults — that's the canonical usage from the Typer docs.
84-
# B008 ("function call in default") is incompatible with the framework
85-
# here, not a real bug.
86-
"src/groupdocs_viewer_ui/cli.py" = ["B008"]
82+
# cli.py:
83+
# B008 — Typer's canonical pattern uses `typer.Option(...)` and `Path.cwd()`
84+
# as argument defaults; the rule is incompatible with the framework.
85+
# UP045 — Typer calls `typing.get_type_hints()` to introspect the signature,
86+
# which fails on Python 3.9 for PEP-604 `X | None` syntax. Forced to
87+
# stay on `Optional[X]` until the 3.9 floor moves.
88+
"src/groupdocs_viewer_ui/cli.py" = ["B008", "UP045"]
8789

8890
[tool.mypy]
8991
python_version = "3.9"

src/groupdocs_viewer_ui/cache/redis.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ def __init__(
3737
"RedisCache needs redis-py — install with "
3838
"`pip install groupdocs-viewer-net-ui[redis]`."
3939
) from exc
40-
client = redis.from_url(url) # type: ignore[no-untyped-call]
40+
# redis-py types vary by version — pair the suppression with
41+
# `unused-ignore` so this works whether or not the installed
42+
# release exposes a typed `from_url`.
43+
client = redis.from_url(url) # type: ignore[no-untyped-call, unused-ignore]
4144
self._redis = client
4245
self._prefix = key_prefix
4346

4447
async def try_get(self, cache_key: str, file_path: str) -> bytes | None:
45-
# redis-py is fully untyped at runtime; .get returns Any.
46-
return await self._redis.get(self._key(cache_key, file_path)) # type: ignore[no-any-return]
48+
# Same cross-version dance as the constructor: .get() may or may
49+
# not have a typed return depending on the installed redis-py.
50+
return await self._redis.get(self._key(cache_key, file_path)) # type: ignore[no-any-return, unused-ignore]
4751

4852
async def set(self, cache_key: str, file_path: str, data: bytes) -> None:
4953
await self._redis.set(self._key(cache_key, file_path), data)

src/groupdocs_viewer_ui/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import sys
55
from pathlib import Path
6+
from typing import Optional
67

78
import typer
89
import uvicorn
@@ -29,7 +30,11 @@ def serve(
2930
"-f",
3031
help="Directory containing documents to browse and view.",
3132
),
32-
cache: Path | None = typer.Option(
33+
# Optional[Path] (not `Path | None`) because Typer calls
34+
# ``typing.get_type_hints()`` to introspect the signature, and PEP-604
35+
# union syntax fails to evaluate on Python 3.9. ``eval_type_backport``
36+
# only patches pydantic, not typing in general.
37+
cache: Optional[Path] = typer.Option(
3338
None,
3439
"--cache",
3540
"-c",

0 commit comments

Comments
 (0)