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
Owner

Accidental output directory overwriting protection

This pull request adds a protection against accidental overwriting of the output directory.

Why this?

Previously, using a non-empty output directory could lead to an inconsistent state of it: When you generated the documentation, changed some code, and generated it again, the documentation directory could include some old files which are not included in the new documentation version (e. g. because a module was renamed). That is why a protection is important: Either the output directory is completely emptied first and the documentation is generated, or an error that the directory is not empty occurs.

Summary

  • DirectoryNotEmptyError exception class (handled by CLI)
  • core functionality: added force argument to the Python documentation generator method and tests
  • CLI option (-f, --force) and tests
  • changelog entry

Related issues

Closes #33

# Accidental output directory overwriting protection This pull request adds a protection against accidental overwriting of the output directory. ## Why this? Previously, using a non-empty output directory could lead to an inconsistent state of it: When you generated the documentation, changed some code, and generated it again, the documentation directory could include some old files which are not included in the new documentation version (e. g. because a module was renamed). That is why a protection is important: Either the output directory is completely emptied first and the documentation is generated, or an error that the directory is not empty occurs. ## Summary - `DirectoryNotEmptyError` exception class (handled by CLI) - core functionality: added `force` argument to the Python documentation generator method and tests - CLI option (`-f`, `--force`) and tests - changelog entry ## Related issues Closes #33
jakob.scheid added this to the 0.2.0 milestone 2026-09-27 21:17:25 +02:00
jakob.scheid added this to the Project Board project 2026-09-27 21:17:25 +02:00
jakob.scheid added 6 commits 2026-09-27 21:17:26 +02:00
Added an OSError subclass for indicating that the directory is not
empty. This exception is explicitly handled by the CLI now.
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.
Added tests to test new output directory deletion behavior:
  - output directory overwriting (not empty; force)
  - error (not empty; not force)
  - nothing (empty; force)
  - nothing (empty; not force)
One test was adapted to output directory emptiness check because the
.gitkeep file which is required for Git to track the directory makes it
non-empty.
Added a test to the CLI test file for the documentation generation
error.
Added a changelog entry for the protection against accidental
overwriting of the output directory.
jakob.scheid moved this to Review in Project Board on 2026-09-27 21:17:31 +02:00
jakob.scheid merged commit 934624fce3 into main 2026-09-27 21:56:40 +02:00
jakob.scheid deleted branch feature/protect-against-accidental-overwriting 2026-09-27 21:56:40 +02:00
jakob.scheid moved this to Done in Project Board on 2026-09-27 21:56:45 +02:00
Sign in to join this conversation.