generated from jCloud/repository-template
Feat(python-generator): protection against accidental overwriting of the output directory #40
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user