From b771bb38796603dd96682d0bc1da80fbf1cb9624 Mon Sep 17 00:00:00 2001 From: Cubic Date: Mon, 7 Jul 2025 17:17:33 -0400 Subject: [PATCH] chore: fix watchfiles and copy function --- solstice/cli.py | 7 ++++++- solstice/sitegen.py | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/solstice/cli.py b/solstice/cli.py index 256ff03..c53d822 100644 --- a/solstice/cli.py +++ b/solstice/cli.py @@ -158,8 +158,13 @@ def hotreload(ssg: SiteGenerator, extra_watches: list[str]): import pygments.formatters import pygments.lexers import watchfiles # type: ignore (removes pyright hallucination) + from watchfiles.filters import DefaultFilter - it = watchfiles.watch(ssg.project_dir, *map(os.path.realpath, extra_watches)) + it = watchfiles.watch( + ssg.project_dir, + *map(os.path.realpath, extra_watches), + watch_filter=DefaultFilter(ignore_dirs=(ssg.output_path, *DefaultFilter.ignore_dirs)), + ) # wait for server to start while True: diff --git a/solstice/sitegen.py b/solstice/sitegen.py index e3ef01d..bbc41fd 100644 --- a/solstice/sitegen.py +++ b/solstice/sitegen.py @@ -165,18 +165,28 @@ def load_md(self, path: str) -> tuple[str, str, dict[str, Any]]: content, toc = self.md_to_html(content) return content, toc, meta - def copy(self, dir: str): + def copy(self, src: str, dest: str | None = None): """ - Copy a directory to the output path, without altering its contents. + Copy a file/directory to the output path, without altering its contents. Used for copying static assets like images, CSS, etc. # Arguments - - `dir`: The directory to copy. + - `src`: The path to copy from. + - `dest`: The path to copy to, relative to `self.output_path`. Defaults to `src`. """ - if path.exists(dir): - dist = self.output_path_for(dir) - with LogTimer(f"Copying directory '{dir}'..."): - shutil.copytree(dir, dist, dirs_exist_ok=True) + + if dest is None: + dest = src + + if not path.exists(src): + warn(f"Tried to copy nonexistent path {src}") + + dist_path = self.output_path_for(dest) + if path.isdir(src): + with LogTimer(f"Copying directory '{src}'..."): + shutil.copytree(src, dist_path, dirs_exist_ok=True) + else: + shutil.copy(src, dist_path) def clean(self): """Clean the output directory, removing it and all its contents."""