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