Skip to content

Commit

Permalink
lazy-import pyconify
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Dec 31, 2024
1 parent 6a7a731 commit 48af284
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/superqt/iconify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
Flip = Literal["horizontal", "vertical", "horizontal,vertical"]
Rotation = Literal["90", "180", "270", 90, 180, 270, "-90", 1, 2, 3]

try:
from pyconify import svg_path
except ModuleNotFoundError: # pragma: no cover
svg_path = None


class QIconifyIcon(QIcon):
"""QIcon backed by an iconify icon.
Expand Down Expand Up @@ -74,12 +69,14 @@ def __init__(
rotate: Rotation | None = None,
dir: str | None = None,
):
if svg_path is None: # pragma: no cover
try:
import pyconify # noqa: F401
except ModuleNotFoundError: # pragma: no cover
raise ModuleNotFoundError(
"pyconify is required to use QIconifyIcon. "
"Please install it with `pip install pyconify` or use the "
"`pip install superqt[iconify]` extra."
)
) from None
super().__init__()
if key:
self.addKey(*key, color=color, flip=flip, rotate=rotate, dir=dir)
Expand Down Expand Up @@ -130,6 +127,8 @@ def addKey(
QIconifyIcon
This QIconifyIcon instance, for chaining.
"""
from pyconify import svg_path

try:
path = svg_path(*key, color=color, flip=flip, rotate=rotate, dir=dir)
except OSError as e:
Expand Down

0 comments on commit 48af284

Please sign in to comment.