From 03fa81f0df5624189f72af21f31b6002950963a7 Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Sun, 4 Oct 2026 16:54:48 +0200 Subject: [PATCH] fix(python-generator): ignore invalid namespaces Python modules or packages are now ignored if their name is not a valid Python namespace name. --- src/jcloud_docsgen/core/python/_core.py | 18 ++++++++++++------ .../case02/expected/pkg/a/b.md | 9 +++++++++ .../case02/project/pkg/a-b/c-d.py | 1 + .../case02/project/pkg/a-b/c.d.py | 1 + .../case02/project/pkg/a-b/c.py | 1 + .../case02/project/pkg/a.b/c-d.py | 1 + .../case02/project/pkg/a.b/c.d.py | 1 + .../case02/project/pkg/a.b/c.py | 1 + .../case02/project/pkg/a/b-c.py | 1 + .../case02/project/pkg/a/b.c.py | 1 + .../case02/project/pkg/a/b.py | 1 + .../case02/project/pkg/b-c/.gitkeep | 0 .../case02/project/pkg/b.c/.gitkeep | 0 .../case02/project/pkg/c-d.py | 1 + .../case02/project/pkg/c.d.py | 1 + 15 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/expected/pkg/a/b.md create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c-d.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.d.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c-d.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.d.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b-c.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.c.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/b-c/.gitkeep create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/b.c/.gitkeep create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c-d.py create mode 100644 tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c.d.py diff --git a/src/jcloud_docsgen/core/python/_core.py b/src/jcloud_docsgen/core/python/_core.py index 5e2cd6b..2df4681 100644 --- a/src/jcloud_docsgen/core/python/_core.py +++ b/src/jcloud_docsgen/core/python/_core.py @@ -1114,12 +1114,18 @@ class PythonDocumentationGenerator: ) for entry in directory.iterdir(): - if entry.is_dir() and ( - entry.parent / (f'{entry.stem}.py') - ).resolve() not in [e.resolve() for e in entry.parent.iterdir()]: - namespace.add(self._namespace(entry)) - elif entry.suffix == '.py': - namespace.add(PythonModuleNamespace(entry.stem)) + try: + if entry.is_dir() and ( + entry.parent / (f'{entry.stem}.py') + ).resolve() not in [ + e.resolve() for e in entry.parent.iterdir() + ]: + namespace.add(self._namespace(entry)) + elif entry.suffix == '.py': + namespace.add(PythonModuleNamespace(entry.stem)) + except InvalidNamespaceError: + # the name of the directory or module is invalid; ignore. + pass return namespace diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/expected/pkg/a/b.md b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/expected/pkg/a/b.md new file mode 100644 index 0000000..3238719 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/expected/pkg/a/b.md @@ -0,0 +1,9 @@ +# Module `pkg.a.b` + +## Function `fn` + +### Function signature + +```python +fn() +``` \ No newline at end of file diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c-d.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c-d.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c-d.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.d.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.d.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.d.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a-b/c.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c-d.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c-d.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c-d.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.d.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.d.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.d.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a.b/c.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b-c.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b-c.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b-c.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.c.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.c.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.c.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/a/b.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/b-c/.gitkeep b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/b-c/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/b.c/.gitkeep b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/b.c/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c-d.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c-d.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c-d.py @@ -0,0 +1 @@ +def fn(): ... diff --git a/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c.d.py b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c.d.py new file mode 100644 index 0000000..9b7a678 --- /dev/null +++ b/tests/unit/core/python/_core/test_PythonDocumentationGenerator/test_generate_documentation/case02/project/pkg/c.d.py @@ -0,0 +1 @@ +def fn(): ...