generated from jCloud/repository-template
feat(python-generator): add force argument to generator
Added a force argument to PythonDocumentationGenerator.generate_documentation to control whether the content of the output directory should be overwritten or not, if it is not empty. If the force argument is True, the output directory content will first be deleted recursively. If it is False and the output directory is not empty, a DirectoryNotEmptyError will be raised.
This commit is contained in:
1 file changed
+25
-2
@@ -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(
|
||||||
|
|||||||
Reference in new issue
Block a user