generated from jCloud/repository-template
Add PythonDocumentationGenerator method to collect all namespaces
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from ...utils import ExistingDirectory, assert_that_is_instance
|
||||
from .namespaces import PythonModuleNamespace, PythonPackageNamespace, PythonNamespace
|
||||
import pathlib
|
||||
|
||||
__all__ = [
|
||||
'PythonDocumentationGenerator'
|
||||
@@ -34,4 +36,25 @@ class PythonDocumentationGenerator:
|
||||
assert_that_is_instance(docs_directory, ExistingDirectory)
|
||||
|
||||
self.project_directory = project_directory
|
||||
self.docs_directory = docs_directory
|
||||
self.docs_directory = docs_directory
|
||||
|
||||
def _namespace(self, directory: pathlib.Path) -> dict[str, PythonNamespace]:
|
||||
namespaces = dict()
|
||||
|
||||
for entry in directory.iterdir():
|
||||
if entry.is_dir():
|
||||
namespaces[entry.name] = PythonPackageNamespace(entry.name, self._namespace(entry))
|
||||
elif entry.suffix == '.py':
|
||||
namespaces[entry.stem] = PythonModuleNamespace(entry.stem)
|
||||
|
||||
return namespaces
|
||||
|
||||
def namespace(self) -> PythonPackageNamespace:
|
||||
'''
|
||||
Returns the project as a namespace.
|
||||
|
||||
:return: The project as a namespace.
|
||||
:rtype: PythonPackageNamespace
|
||||
'''
|
||||
|
||||
return PythonPackageNamespace('src', self._namespace(pathlib.Path((self.project_directory / 'src').as_posix())))
|
||||
Reference in New Issue
Block a user