Skip to content

Commit 9b73147

Browse files
committed
chore: only import brand for type checking
1 parent bda5054 commit 9b73147

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

shiny/ui/_theme_brand.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import os
44
import warnings
55
from pathlib import Path
6-
from typing import Any, Optional, Union
6+
from typing import TYPE_CHECKING, Any, Optional, Union
77

8-
from brand_yml import Brand
8+
if TYPE_CHECKING:
9+
from brand_yml import Brand
910
from htmltools import HTMLDependency
1011

1112
from .._versions import bootstrap as v_bootstrap
@@ -218,7 +219,7 @@ def __init__(
218219
self.rules = rules
219220

220221
@classmethod
221-
def from_brand(cls, brand: Brand):
222+
def from_brand(cls, brand: "Brand"):
222223
if not brand.defaults:
223224
return cls(version=v_bootstrap, preset="shiny")
224225

@@ -261,7 +262,7 @@ def join_str(x: str | None, y: str | None):
261262
class ThemeBrand(Theme):
262263
def __init__(
263264
self,
264-
brand: Brand,
265+
brand: "Brand",
265266
*,
266267
include_paths: Optional[str | Path | list[str | Path]] = None,
267268
):
@@ -287,12 +288,12 @@ def __init__(
287288
# Theme -----------------------------------------------------------------------
288289
# Defaults are added in reverse order, so each chunk appears above the next
289290
# layer of defaults. The intended order in the final output is:
290-
# 1. Brand Color palette
291-
# 2. Brand Bootstrap Sass vars
292-
# 3. Brand theme colors
293-
# 4. Brand typography
294-
# 5. Gray scale variables from Brand fg/bg or black/white
295-
# 6. Fallback vars needed by additional Brand rules
291+
# 1. "Brand" Color palette
292+
# 2. "Brand" Bootstrap Sass vars
293+
# 3. "Brand" theme colors
294+
# 4. "Brand" typography
295+
# 5. Gray scale variables from "Brand" fg/bg or black/white
296+
# 6. Fallback vars needed by additional "Brand" rules
296297

297298
self.add_defaults("", "// *---- brand: end of defaults ----* //", "")
298299
self._add_sass_ensure_variables()
@@ -303,20 +304,20 @@ def __init__(
303304
self._add_defaults_hdr("bootstrap defaults", **brand_bootstrap.defaults)
304305
self._add_defaults_hdr("brand colors", **sass_vars_brand_colors)
305306

306-
# Brand rules (now in forwards order)
307+
# "Brand" rules (now in forwards order)
307308
self._add_rules_brand_colors(css_vars_brand)
308309
self._add_sass_brand_rules()
309310
self._add_brand_bootstrap_other(brand_bootstrap)
310311

311-
def _get_theme_name(self, brand: Brand) -> str:
312+
def _get_theme_name(self, brand: "Brand") -> str:
312313
if not brand.meta or not brand.meta.name:
313314
return "brand"
314315

315316
return brand.meta.name.short or brand.meta.name.full or "brand"
316317

317318
@staticmethod
318319
def _prepare_color_vars(
319-
brand: Brand,
320+
brand: "Brand",
320321
) -> tuple[dict[str, str], dict[str, str], list[str]]:
321322
"""Colors: create a dictionary of Sass variables and a list of brand CSS variables"""
322323
if not brand.color:
@@ -348,12 +349,12 @@ def _prepare_color_vars(
348349
# => CSS var: `--brand-{name}: {value}`
349350
brand_css_vars.append(f"--brand-{pal_name}: {pal_color};")
350351

351-
# We keep Sass and Brand vars separate so we can ensure Brand Sass vars come
352+
# We keep Sass and "Brand" vars separate so we can ensure "Brand" Sass vars come
352353
# first in the compiled Sass definitions.
353354
return mapped, brand_sass_vars, brand_css_vars
354355

355356
@staticmethod
356-
def _prepare_typography_vars(brand: Brand) -> dict[str, str]:
357+
def _prepare_typography_vars(brand: "Brand") -> dict[str, str]:
357358
"""Typography: Create a list of Bootstrap Sass variables"""
358359
mapped: dict[str, str] = {}
359360

@@ -474,7 +475,7 @@ def _add_sass_brand_grays(self):
474475
)
475476

476477
def _add_sass_brand_rules(self):
477-
"""Additional rules to fill in Bootstrap styles for Brand parameters"""
478+
"""Additional rules to fill in Bootstrap styles for "Brand" parameters"""
478479
self.add_rules(
479480
"""
480481
// *---- brand: brand rules to augment Bootstrap rules ----* //

0 commit comments

Comments
 (0)