From d66e4fccc485ed50089468317d4220d2473e4741 Mon Sep 17 00:00:00 2001 From: Philipp Temminghoff Date: Thu, 24 Oct 2024 05:11:04 +0200 Subject: [PATCH] chore: add contains_files method --- mkdocs_mknodes/commands/build_page.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mkdocs_mknodes/commands/build_page.py b/mkdocs_mknodes/commands/build_page.py index 5ac5efe..8e1a1f0 100644 --- a/mkdocs_mknodes/commands/build_page.py +++ b/mkdocs_mknodes/commands/build_page.py @@ -4,6 +4,7 @@ import io import os +import pathlib from typing import TYPE_CHECKING, Any from urllib.parse import urljoin @@ -105,7 +106,7 @@ def _build( logger.warning("A 'dirty' build is being performed (for site dev purposes only)") if not live_server_url: # pragma: no cover logger.info("Building documentation to directory: %s", config.site_dir) - if dirty and mkdocs_build.site_directory_contains_stale_files(config.site_dir): + if dirty and contains_files(config.site_dir): logger.info("The directory contains stale files. Use --clean to remove them.") # First gather all data from all files/pages to ensure all data is # consistent across all pages. @@ -216,6 +217,16 @@ def _populate_page( config._current_page = None +def contains_files(folder: str | os.PathLike[str]) -> bool: + """Check if given path exists and contains any files or folders. + + Args: + folder: The folder to check + """ + path = pathlib.Path(folder) + return path.exists() and any(path.iterdir()) + + if __name__ == "__main__": config = mkdocsconfigfile.MkDocsConfigFile("mkdocs.yml") print(config.dump_config())