Feat(python-generator): protection against accidental overwriting of the output directory #40

Merged
jakob.scheid merged 6 commits from feature/protect-against-accidental-overwriting into main 2026-09-27 21:56:40 +02:00
Showing only changes of commit 5791358b41 - Show all commits
+25 -2
View File
@@ -22,7 +22,13 @@ from typing import TypeAlias
import docstring_parser 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 ...utils import get_relative_path_segments, non_empty_str
from .arguments import PythonArgumentKind, PythonFunctionArgument from .arguments import PythonArgumentKind, PythonFunctionArgument
from .definitions import ( from .definitions import (
@@ -1114,12 +1120,29 @@ class PythonDocumentationGenerator:
return self._namespace(self.project_directory) 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 Generates the full project documentation and writes it to the
documentation directory. 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) self.docs_directory.mkdir(parents=True, exist_ok=True)
_generate_package_namespace_documentation( _generate_package_namespace_documentation(