Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions compile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Mapping
from typing import Any, Mapping

try: # pragma: no cover - optional dependency guard
from PIL import Image, ImageDraw, ImageFont # type: ignore
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = ImageDraw = ImageFont = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing aid
from PIL import Image as PILImage
from fonts import font_store
from imaging import load_image


def _require_pillow() -> None:
Expand All @@ -43,9 +43,6 @@ def _require_pillow() -> None:
"Install the 'Pillow' package to enable this feature."
)

from fonts import font_store
from imaging import load_image

__all__ = [
"Backend",
"Calibration",
Expand Down
21 changes: 9 additions & 12 deletions compile/tspl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Iterable, Mapping
from typing import Any, Iterable, Mapping

try: # pragma: no cover - optional dependency guard
from PIL import Image # type: ignore
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing only
from PIL import Image as PILImage


def _require_pillow() -> None:
if Image is None:
raise RuntimeError(
"Pillow must be installed to render TSPL bitmaps. "
"Install the 'Pillow' package to enable this feature."
)

from imaging.raster import (
fingerprint_image,
prepare_bitmap_for_tspl,
Expand All @@ -40,6 +29,14 @@ def _require_pillow() -> None:
render_text_bitmap,
)


def _require_pillow() -> None:
if Image is None:
raise RuntimeError(
"Pillow must be installed to render TSPL bitmaps. "
"Install the 'Pillow' package to enable this feature."
)

__all__ = ["TSPLBackend"]


Expand Down
21 changes: 9 additions & 12 deletions compile/zpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Iterable, Mapping
from typing import Any, Iterable, Mapping

try: # pragma: no cover - optional dependency guard
from PIL import Image # type: ignore
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing only
from PIL import Image as PILImage


def _require_pillow() -> None:
if Image is None:
raise RuntimeError(
"Pillow must be installed to render ZPL bitmaps. "
"Install the 'Pillow' package to enable this feature."
)

from imaging.raster import fingerprint_image, prepare_bitmap_for_tspl
from printing_utils import ZPLMediaParams, emit_zpl_footer, emit_zpl_media_setup

Expand All @@ -32,6 +21,14 @@ def _require_pillow() -> None:
render_text_bitmap,
)


def _require_pillow() -> None:
if Image is None:
raise RuntimeError(
"Pillow must be installed to render ZPL bitmaps. "
"Install the 'Pillow' package to enable this feature."
)

__all__ = ["ZPLBackend"]


Expand Down
7 changes: 2 additions & 5 deletions imaging/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import io
import uuid
from pathlib import Path
from typing import TYPE_CHECKING, Any, BinaryIO
from typing import Any, BinaryIO

try: # pragma: no cover - optional dependency guard
from PIL import Image # type: ignore
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing only
from PIL import Image as PILImage
from utils.fs import canonical_path, file_hash


def _require_pillow() -> None:
Expand All @@ -23,8 +22,6 @@ def _require_pillow() -> None:
"Install the 'Pillow' package to enable this feature."
)

from utils.fs import canonical_path, file_hash

__all__ = ["load_image"]


Expand Down
4 changes: 0 additions & 4 deletions imaging/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
import io
from collections.abc import Iterable, MutableMapping
from pathlib import Path
from typing import TYPE_CHECKING

try: # pragma: no cover - optional dependency guard
from PIL import Image, ImageFilter, ImageOps # type: ignore
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = ImageFilter = ImageOps = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing aid
from PIL import Image as PILImage

try: # pragma: no cover - optional Pillow component
from PIL import ImageCms # type: ignore
except Exception: # pragma: no cover - optional dependency
Expand Down
8 changes: 3 additions & 5 deletions printing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
import unicodedata
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Mapping, Protocol
from typing import Any, Callable, Mapping, Protocol

try: # pragma: no cover - optional dependency guard
from PIL import Image # type: ignore
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing only
from PIL import Image as PILImage

from compile import Calibration, CompilationError, SafeDict, get_backend
from db import store as db_store
from fonts import font_store
Expand All @@ -33,7 +30,8 @@
from utils import recurso_caminho
from utils.fs import canonical_path as canonical_file_path

from .queue import PrinterTarget, enqueue_job, wait_for_all as _queue_wait_for_all
from .queue import PrinterTarget, enqueue_job
from .queue import wait_for_all as _queue_wait_for_all

# ----------------------------------------------------------------------------

Expand Down
5 changes: 1 addition & 4 deletions render/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, Any, Iterable, Mapping
from typing import Any, Iterable, Mapping

try: # pragma: no cover - optional dependency during runtime
import qrcode
Expand All @@ -29,9 +29,6 @@
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = ImageDraw = ImageFont = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing aid
from PIL import Image as PILImage

try: # pragma: no cover - optional dependency during runtime
import barcode # type: ignore
from barcode.writer import ImageWriter # type: ignore
Expand Down
4 changes: 0 additions & 4 deletions utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@
import sys
from datetime import datetime
from functools import lru_cache
from typing import TYPE_CHECKING

try: # pragma: no cover - optional dependency guard
from PIL import Image # type: ignore
except ImportError: # pragma: no cover - Pillow missing at runtime
Image = None # type: ignore[assignment]

if TYPE_CHECKING: # pragma: no cover - typing aid
from PIL import Image as PILImage


def _base_dir() -> str:
"""Obtém o diretório base do aplicativo.
Expand Down
Loading