Feat(python-generator): remove implicit assumptions of project directory structure #39

Merged
jakob.scheid merged 3 commits from feature/no-src-dir-need into main 2026-09-22 19:28:50 +02:00
12 changed files with 13 additions and 18 deletions

No files matched your search

+1
View File
@@ -12,6 +12,7 @@
- Replaced the installation instructions, which used the old registry, with a reference to the Gitea Package Registry in README - Replaced the installation instructions, which used the old registry, with a reference to the Gitea Package Registry in README
- Made Python function signatures (argument default values) compliant with PEP 8 - Made Python function signatures (argument default values) compliant with PEP 8
- Removed implicit Python project directory structure assumptions
### Deprecated ### Deprecated
+1 -3
View File
@@ -78,6 +78,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
'-o', '-o',
'--output-dir', '--output-dir',
type=pathlib.Path, type=pathlib.Path,
default='docs/reference',
help='the output directory the documentation will be written to', help='the output directory the documentation will be written to',
) )
@@ -138,9 +139,6 @@ def main(argv=None) -> int:
argument_parser = create_argument_parser() argument_parser = create_argument_parser()
args = argument_parser.parse_args(argv) args = argument_parser.parse_args(argv)
if args.output_dir is None:
args.output_dir = args.project_directory / 'docs/reference'
try: try:
if args.language == _LANG_PYTHON: if args.language == _LANG_PYTHON:
from .languages.python import generate from .languages.python import generate
+6 -10
View File
@@ -1104,19 +1104,15 @@ class PythonDocumentationGenerator:
return namespace return namespace
def namespace(self) -> list[PythonPackageNamespace]: def namespace(self) -> PythonPackageNamespace:
""" """
Returns the project as a namespace. Returns the project as a namespace.
:return: The project as a namespace. :return: The project as a namespace.
:rtype: list[PythonPackageNamespace] :rtype: PythonPackageNamespace:
""" """
src_dir = self.project_directory / 'src' return self._namespace(self.project_directory)
return [
self._namespace(dir) for dir in src_dir.iterdir() if dir.is_dir()
]
def generate_documentation(self) -> None: def generate_documentation(self) -> None:
""" """
@@ -1127,10 +1123,10 @@ class PythonDocumentationGenerator:
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(
PythonPackageNamespace('src', self.namespace()), self.namespace(),
self.docs_directory, self.docs_directory,
self.project_directory / 'src', self.project_directory,
self.project_directory / 'src', self.project_directory,
self.include_sections, self.include_sections,
self.kwargs, self.kwargs,
) )
@@ -31,7 +31,7 @@ from src.jcloud_docsgen.core.python.namespaces import (
( (
PythonDocumentationGenerator( PythonDocumentationGenerator(
pathlib.Path( pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_1' 'tests/unit/core/python/_core/test_project_dirs/pdir_1/src'
), ),
pathlib.Path( pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_1/docs' 'tests/unit/core/python/_core/test_project_dirs/pdir_1/docs'
@@ -42,7 +42,7 @@ from src.jcloud_docsgen.core.python.namespaces import (
( (
PythonDocumentationGenerator( PythonDocumentationGenerator(
pathlib.Path( pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_2' 'tests/unit/core/python/_core/test_project_dirs/pdir_2/src'
), ),
pathlib.Path( pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_2/docs' 'tests/unit/core/python/_core/test_project_dirs/pdir_2/docs'
@@ -58,7 +58,7 @@ from src.jcloud_docsgen.core.python.namespaces import (
( (
PythonDocumentationGenerator( PythonDocumentationGenerator(
pathlib.Path( pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_3' 'tests/unit/core/python/_core/test_project_dirs/pdir_3/src'
), ),
pathlib.Path( pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_3/docs' 'tests/unit/core/python/_core/test_project_dirs/pdir_3/docs'
@@ -85,7 +85,7 @@ def test_PythonDocumentationGenerator_collect_modules(
python_documentation_generator: PythonDocumentationGenerator, python_documentation_generator: PythonDocumentationGenerator,
expected, expected,
): ):
assert python_documentation_generator.namespace() == expected assert python_documentation_generator.namespace().sub_namespaces == expected
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -130,7 +130,7 @@ def test_creates_directory():
project_dir = pathlib.Path(project_dir) project_dir = pathlib.Path(project_dir)
# The directory of the package # The directory of the package
package_dir = project_dir / 'src' / 'pkg' package_dir = project_dir / 'pkg'
assert not package_dir.exists() assert not package_dir.exists()
package_dir.mkdir(parents=True, exist_ok=True) package_dir.mkdir(parents=True, exist_ok=True)