|
5 | 5 | import re |
6 | 6 | import tempfile |
7 | 7 | import textwrap |
8 | | -from typing import Any, Literal, Optional, Sequence, TypeVar |
| 8 | +from typing import TYPE_CHECKING, Any, Literal, Optional, Sequence, TypeVar |
9 | 9 |
|
10 | | -from brand_yml import Brand |
| 10 | +if TYPE_CHECKING: |
| 11 | + from brand_yml import Brand |
11 | 12 | from htmltools import HTMLDependency |
12 | 13 |
|
13 | 14 | from .._docstring import add_example |
@@ -410,7 +411,7 @@ def to_css( |
410 | 411 | self._css = self._read_precompiled_css() |
411 | 412 | return self._css |
412 | 413 |
|
413 | | - check_libsass_installed() |
| 414 | + check_theme_pkg_installed("libsass", "sass") |
414 | 415 | import sass |
415 | 416 |
|
416 | 417 | args: SassCompileArgs = {} if compile_args is None else compile_args |
@@ -525,6 +526,10 @@ def from_brand(cls, brand: str | pathlib.Path | Brand): |
525 | 526 | A :class:`shiny.ui.Theme` instance with a custom Shiny theme created from |
526 | 527 | the brand guidelines (see :class:`brand_yml.Brand`). |
527 | 528 | """ |
| 529 | + check_theme_pkg_installed("brand_yml") |
| 530 | + |
| 531 | + from brand_yml import Brand |
| 532 | + |
528 | 533 | from ._theme_brand import ThemeBrand # avoid circular import |
529 | 534 |
|
530 | 535 | if not isinstance(brand, Brand): |
@@ -559,13 +564,16 @@ def check_is_valid_preset(preset: ShinyThemePreset) -> None: |
559 | 564 | ) |
560 | 565 |
|
561 | 566 |
|
562 | | -def check_libsass_installed() -> None: |
| 567 | +def check_theme_pkg_installed(pkg: str, spec: str | None = None) -> None: |
563 | 568 | import importlib.util |
564 | 569 |
|
565 | | - if importlib.util.find_spec("sass") is None: |
| 570 | + if spec is None: |
| 571 | + spec = pkg |
| 572 | + |
| 573 | + if importlib.util.find_spec(spec) is None: |
566 | 574 | raise ImportError( |
567 | | - "The 'libsass' package is required to compile custom themes. " |
568 | | - 'Please install it with `pip install libsass` or `pip install "shiny[theme]"`.', |
| 575 | + f"The '{pkg}' package is required to compile custom themes. " |
| 576 | + 'Please install it with `pip install {pkg}` or `pip install "shiny[theme]"`.', |
569 | 577 | ) |
570 | 578 |
|
571 | 579 |
|
|
0 commit comments