generated from jCloud/repository-template
Add Python project documentation generator
This commit is contained in:
+2
-1
@@ -25,4 +25,5 @@
|
||||
- Add function to ensure a non-empty string.
|
||||
- Add Python definition documentation generator
|
||||
- Add function to get the path segments of a path relative to another
|
||||
- Add Python module documentation generator
|
||||
- Add Python module documentation generator
|
||||
- Add Python project documentation generator
|
||||
@@ -749,7 +749,7 @@ class PythonModuleDocumentationGenerator:
|
||||
:type src_directory: Union[ExistingDirectory, None]
|
||||
:param include_sections: The sections that will be included.
|
||||
:type include_sections: PythonDefinitionDocumentationIncludeSections
|
||||
:kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
||||
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
||||
'''
|
||||
|
||||
def __init__(
|
||||
@@ -835,7 +835,14 @@ class PythonModuleDocumentationGenerator:
|
||||
|
||||
return md.strip()
|
||||
|
||||
def _generate_package_namespace_documentation(namespace: PythonPackageNamespace, documentation_directory: ExistingDirectory, root_directory: ExistingDirectory) -> None:
|
||||
def _generate_package_namespace_documentation(
|
||||
namespace: PythonPackageNamespace,
|
||||
documentation_directory: pathlib.Path,
|
||||
root_directory: pathlib.Path,
|
||||
dir: pathlib.Path,
|
||||
include_sections: PythonDefinitionDocumentationIncludeSections = PythonDefinitionDocumentationIncludeSections(),
|
||||
kwargs: dict = {}
|
||||
) -> None:
|
||||
'''
|
||||
Generates the documentation for a package namespace and writes it to
|
||||
the documentation directory.
|
||||
@@ -843,25 +850,37 @@ def _generate_package_namespace_documentation(namespace: PythonPackageNamespace,
|
||||
:param namespace: The namespace.
|
||||
:type namespace: PythonPackageNamespace
|
||||
:param documentation_directory: The directory for the documentation.
|
||||
:type documentation_directory: ExistingDirectory
|
||||
:type documentation_directory: pathlib.Path
|
||||
:param root_directory: The root directory.
|
||||
:type root_directory: ExistingDirectory
|
||||
:type root_directory: pathlib.Path
|
||||
:param dir: The directory of the namespace.
|
||||
:type dir: pathlib.Path
|
||||
:param include_sections: The sections to be included in the documentation.
|
||||
:type include_sections: PythonDefinitionDocumentationIncludeSections
|
||||
:param kwargs: The options for the documentation generator.
|
||||
'''
|
||||
|
||||
assert_that_is_instance(documentation_directory, ExistingDirectory)
|
||||
|
||||
documentation_directory = pathlib.Path(str(documentation_directory))
|
||||
|
||||
for sub_namespace in namespace.sub_namespaces:
|
||||
if isinstance(sub_namespace, PythonPackageNamespace):
|
||||
_generate_package_namespace_documentation(sub_namespace, documentation_directory / sub_namespace.name, root_directory)
|
||||
(documentation_directory / sub_namespace.name).mkdir(mode = 0o700, exist_ok = True)
|
||||
_generate_package_namespace_documentation(
|
||||
sub_namespace,
|
||||
documentation_directory / sub_namespace.name,
|
||||
root_directory, dir / sub_namespace.name,
|
||||
include_sections,
|
||||
kwargs
|
||||
)
|
||||
elif isinstance(sub_namespace, PythonModuleNamespace):
|
||||
(
|
||||
documentation_directory / (sub_namespace.name + '.py')
|
||||
documentation_directory / (sub_namespace.name + '.md')
|
||||
).write_text(
|
||||
PythonModuleDocumentationGenerator(
|
||||
documentation_directory / sub_namespace.name,
|
||||
root_directory
|
||||
ExistingFile(str(dir / (sub_namespace.name + '.py'))),
|
||||
ExistingDirectory(str(root_directory)),
|
||||
include_sections,
|
||||
**kwargs
|
||||
).generate_documentation()
|
||||
)
|
||||
|
||||
@@ -873,14 +892,25 @@ class PythonDocumentationGenerator:
|
||||
:type project_directory: ExistingDirectory
|
||||
:param docs_directory: The directory for the generated documentation.
|
||||
:type docs_directory: ExistingDirectory
|
||||
:param include_sections: The sections to be included in the documentation.
|
||||
:type include_sections: PythonDefinitionDocumentationIncludeSections
|
||||
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
||||
'''
|
||||
|
||||
def __init__(self, project_directory: ExistingDirectory, docs_directory: ExistingDirectory) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
project_directory: ExistingDirectory,
|
||||
docs_directory: ExistingDirectory,
|
||||
include_sections: PythonDefinitionDocumentationIncludeSections = PythonDefinitionDocumentationIncludeSections(),
|
||||
**kwargs
|
||||
) -> None:
|
||||
assert_that_is_instance(project_directory, ExistingDirectory)
|
||||
assert_that_is_instance(docs_directory, ExistingDirectory)
|
||||
|
||||
self.project_directory = pathlib.Path(str(project_directory))
|
||||
self.docs_directory = pathlib.Path(str(docs_directory))
|
||||
self.include_sections = include_sections
|
||||
self.kwargs = kwargs
|
||||
|
||||
def _namespace(self, directory: pathlib.Path) -> PythonPackageNamespace:
|
||||
namespace = PythonPackageNamespace(directory.name, [])
|
||||
@@ -914,9 +944,11 @@ class PythonDocumentationGenerator:
|
||||
documentation directory.
|
||||
'''
|
||||
|
||||
namespaces = self.namespace()
|
||||
|
||||
for namespace in namespaces:
|
||||
namespace_documentation_directory = self.docs_directory / namespace.name
|
||||
namespace_documentation_directory.mkdir()
|
||||
_generate_package_namespace_documentation(namespace, namespace_documentation_directory, self.project_directory / 'src' / namespace.name)
|
||||
_generate_package_namespace_documentation(
|
||||
PythonPackageNamespace('src', self.namespace()),
|
||||
self.docs_directory,
|
||||
self.project_directory / 'src',
|
||||
self.project_directory / 'src',
|
||||
self.include_sections,
|
||||
self.kwargs
|
||||
)
|
||||
Reference in New Issue
Block a user