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
2 changed files with 20 additions and 1 deletions
Showing only changes of commit f0c271f8fd - Show all commits

No files matched your search

+10
View File
@@ -82,6 +82,15 @@ def create_argument_parser() -> argparse.ArgumentParser:
default='docs/reference', default='docs/reference',
help='the output directory the documentation will be written to', help='the output directory the documentation will be written to',
) )
common_parser.add_argument(
'-f',
'--force',
action='store_true',
help=(
'generate documentation even if the output directory is not '
'empty. Warning: data can be lost when setting this flag.'
),
)
argument_parser = argparse.ArgumentParser() argument_parser = argparse.ArgumentParser()
@@ -151,6 +160,7 @@ def main(argv=None) -> int:
exclude_sections=args.sections_exclude, exclude_sections=args.sections_exclude,
allow_html=args.allow_html, allow_html=args.allow_html,
allow_tables=args.allow_tables, allow_tables=args.allow_tables,
force=args.force,
) )
except FileNotFoundError as exc: except FileNotFoundError as exc:
return error(f'{exc.filename}: no such file or directory') return error(f'{exc.filename}: no such file or directory')
+10 -1
View File
@@ -78,6 +78,7 @@ def _generate(
), ),
allow_html: bool = False, allow_html: bool = False,
allow_tables: bool = False, allow_tables: bool = False,
force: bool = False,
) -> None: ) -> None:
""" """
Generates the documentation for a Python project. Generates the documentation for a Python project.
@@ -94,6 +95,9 @@ def _generate(
:type allow_html: bool :type allow_html: bool
:param allow_tables: Indicates whether Markdown tables are allowed. :param allow_tables: Indicates whether Markdown tables are allowed.
Warning: Markdown tables are not CommonMark. Warning: Markdown tables are not CommonMark.
:param force: Indicates whether the output directory shall be
overwritten if it is not empty.
:type force: bool
""" """
docs_generator = PythonDocumentationGenerator( docs_generator = PythonDocumentationGenerator(
@@ -103,7 +107,7 @@ def _generate(
allow_html=allow_html, allow_html=allow_html,
allow_tables=allow_tables, allow_tables=allow_tables,
) )
docs_generator.generate_documentation() docs_generator.generate_documentation(force)
def generate( def generate(
@@ -114,6 +118,7 @@ def generate(
exclude_sections: list[str] = [], exclude_sections: list[str] = [],
allow_html: bool = False, allow_html: bool = False,
allow_tables: bool = False, allow_tables: bool = False,
force: bool = False,
) -> None: ) -> None:
""" """
Generates the documentation for a Python project. Generates the documentation for a Python project.
@@ -133,6 +138,9 @@ def generate(
:type allow_html: bool :type allow_html: bool
:param allow_tables: Indicates whether Markdown tables are allowed. :param allow_tables: Indicates whether Markdown tables are allowed.
Warning: Markdown tables are not CommonMark. Warning: Markdown tables are not CommonMark.
:param force: Indicates whether the output directory shall be
overwritten if it is not empty.
:type force: bool
""" """
sections = parse_sections_list(include_sections, exclude_sections) sections = parse_sections_list(include_sections, exclude_sections)
@@ -143,4 +151,5 @@ def generate(
include_sections=sections, include_sections=sections,
allow_html=allow_html, allow_html=allow_html,
allow_tables=allow_tables, allow_tables=allow_tables,
force=force,
) )