feat: pre-create all essential directories in advanced context

This commit is contained in:
2026-08-27 13:04:12 +08:00
parent c54ae438c1
commit 80738d1254
@@ -100,9 +100,9 @@ _ART_MAC: str = "macos"
_DEFAULT_SVG_CONFIG = artrender.SvgConfig(VANILLA_ARTIFACT_HW, VANILLA_ARTIFACT_HW)
_DEFAULT_BLD_CONFIG = artrender.BlenderConfig(VANILLA_ARTIFACT_HW, VANILLA_ARTIFACT_HW)
# TODO: For easy testing, we only build 48x48.
# TODO: For easy testing, we only build 32x32 and 48x48.
# Enable full generation after testing.
_FD_THUMBNAIL_HWS: tuple[int, ...] = (48,)
_FD_THUMBNAIL_HWS: tuple[int, ...] = (32, 48)
# _FD_THUMBNAIL_HWS: tuple[int, ...] = (16, 32, 48, 64, 128, 256)
@@ -112,7 +112,30 @@ class AdvancedContext:
def __init__(self, ctx: Context) -> None:
self.__context = ctx
# construct basic layout of temporary directory and output directory.
# construct basic layout of temporary directory
self.__context.temporary_artifact(_TEMP_USER_DIR).mkdir(
parents=True, exist_ok=True
)
self.__context.temporary_artifact(_TEMP_LIB_DIR, _TEMP_LIB_ALLOC_DIR).mkdir(
parents=True, exist_ok=True
)
self.__context.temporary_artifact(_TEMP_LIB_DIR, _TEMP_LIB_STABLE_DIR).mkdir(
parents=True, exist_ok=True
)
# and output directory
for hw in _FD_THUMBNAIL_HWS:
for kind in FdContext:
self.__context.output_artifact(f"{hw}x{hw}", str(kind)).mkdir(
parents=True, exist_ok=True
)
for kind in WinCategory:
self.__context.output_artifact(_ART_WIN, str(kind)).mkdir(
parents=True, exist_ok=True
)
for kind in MacCategory:
self.__context.output_artifact(_ART_MAC, str(kind)).mkdir(
parents=True, exist_ok=True
)
def __enter__(self) -> "AdvancedContext":
return self
@@ -207,7 +230,10 @@ class AdvancedContext:
self.__intern_render_svg(src, dst, cfg)
def render_svg_then_load(
self, src: Path, dst: Optional[Path] = None, cfg: SvgConfig = _DEFAULT_SVG_CONFIG
self,
src: Path,
dst: Optional[Path] = None,
cfg: SvgConfig = _DEFAULT_SVG_CONFIG,
) -> Artifact:
"""
Render given SVG to PNG file, then load it directly.
@@ -248,7 +274,10 @@ class AdvancedContext:
self.__intern_render_blender(src, dst, cfg)
def render_blender_then_load(
self, src: Path, dst: Optional[Path] = None, cfg: BlenderConfig = _DEFAULT_BLD_CONFIG
self,
src: Path,
dst: Optional[Path] = None,
cfg: BlenderConfig = _DEFAULT_BLD_CONFIG,
) -> Artifact:
"""
Render given Blender composition to PNG file, then load it directly.