diff --git a/src/jcloud_docsgen/core/python/_core.py b/src/jcloud_docsgen/core/python/_core.py index 73b6b26..af783b3 100644 --- a/src/jcloud_docsgen/core/python/_core.py +++ b/src/jcloud_docsgen/core/python/_core.py @@ -22,7 +22,13 @@ from typing import TypeAlias import docstring_parser -from ...exceptions import InvalidNamespaceError, PythonArgumentStructureError +import shutil + +from ...exceptions import ( + DirectoryNotEmptyError, + InvalidNamespaceError, + PythonArgumentStructureError, +) from ...utils import get_relative_path_segments, non_empty_str from .arguments import PythonArgumentKind, PythonFunctionArgument from .definitions import ( @@ -1114,12 +1120,29 @@ class PythonDocumentationGenerator: return self._namespace(self.project_directory) - def generate_documentation(self) -> None: + def generate_documentation(self, force: bool = False) -> None: """ Generates the full project documentation and writes it to the documentation directory. + + :param force: Indicates whether existing contents of the output + directory shall be overwritten. If ``True``, all + contents of the output directory will be deleted + first. + :type force: bool + + :raises DirectoryNotEmptyError: If ``force`` is ``False`` and + the output directory is not + empty. """ + if self.docs_directory.exists() and list( + self.docs_directory.iterdir() + ): + if force: + shutil.rmtree(self.docs_directory) + else: + raise DirectoryNotEmptyError(str(self.docs_directory)) self.docs_directory.mkdir(parents=True, exist_ok=True) _generate_package_namespace_documentation(