generated from jCloud/repository-template
Refactor(utils): mark ExistingDirectory and ExistingFile as deprecated #14
No files matched your search
@@ -22,11 +22,10 @@ __all__ = [
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
from .utils import ExistingDirectory
|
|
||||||
|
|
||||||
def existing_directory(path: str, *args, **kwargs) -> pathlib.Path:
|
def existing_directory(path: str) -> pathlib.Path:
|
||||||
try:
|
try:
|
||||||
return ExistingDirectory(path, *args, **kwargs)
|
return pathlib.Path(path)
|
||||||
except (FileNotFoundError, NotADirectoryError) as e:
|
except (FileNotFoundError, NotADirectoryError) as e:
|
||||||
raise argparse.ArgumentTypeError(f'{e.filename}{": " + e.args[1] if len(e.args) > 1 else ""}')
|
raise argparse.ArgumentTypeError(f'{e.filename}{": " + e.args[1] if len(e.args) > 1 else ""}')
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from ...utils import ExistingDirectory, assert_that_is_instance, ExistingFile, non_empty_str, get_relative_path_segments
|
from ...utils import non_empty_str, get_relative_path_segments
|
||||||
from ...exceptions import PythonArgumentStructureError, InvalidNamespaceError
|
from ...exceptions import PythonArgumentStructureError, InvalidNamespaceError
|
||||||
from .namespaces import PythonModuleNamespace, PythonPackageNamespace
|
from .namespaces import PythonModuleNamespace, PythonPackageNamespace
|
||||||
from .definitions import PythonDefinition, PythonFunctionDefinition, PythonAsyncFunctionDefinition, PythonClassDefinition
|
from .definitions import PythonDefinition, PythonFunctionDefinition, PythonAsyncFunctionDefinition, PythonClassDefinition
|
||||||
@@ -742,11 +742,11 @@ class PythonModuleDocumentationGenerator:
|
|||||||
A documentation generator for a Python module.
|
A documentation generator for a Python module.
|
||||||
|
|
||||||
:param module_path: The path of the module file.
|
:param module_path: The path of the module file.
|
||||||
:type module_path: ExistingFile
|
:type module_path: pathlib.Path
|
||||||
:param src_directory: The directory of the source code. It is
|
:param src_directory: The directory of the source code. It is
|
||||||
optional and only used for making the module
|
optional and only used for making the module
|
||||||
identifiers in the documentation relative.
|
identifiers in the documentation relative.
|
||||||
:type src_directory: Union[ExistingDirectory, None]
|
:type src_directory: Union[pathlib.Path, 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
|
||||||
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
||||||
@@ -754,15 +754,11 @@ class PythonModuleDocumentationGenerator:
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
module_path: ExistingFile,
|
module_path: pathlib.Path,
|
||||||
src_directory: Union[ExistingDirectory, None] = None,
|
src_directory: Union[pathlib.Path, None] = None,
|
||||||
include_sections: PythonDefinitionDocumentationIncludeSections = PythonDefinitionDocumentationIncludeSections(),
|
include_sections: PythonDefinitionDocumentationIncludeSections = PythonDefinitionDocumentationIncludeSections(),
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
assert_that_is_instance(module_path, ExistingFile)
|
|
||||||
assert_that_is_instance(src_directory, (ExistingDirectory, types.NoneType))
|
|
||||||
|
|
||||||
if module_path.name.count('.') > 1:
|
if module_path.name.count('.') > 1:
|
||||||
raise InvalidNamespaceError('namespace identifier cannot contain more than one dot', namespace_identifier = module_path.name)
|
raise InvalidNamespaceError('namespace identifier cannot contain more than one dot', namespace_identifier = module_path.name)
|
||||||
|
|
||||||
@@ -877,8 +873,8 @@ def _generate_package_namespace_documentation(
|
|||||||
documentation_directory / (sub_namespace.name + '.md')
|
documentation_directory / (sub_namespace.name + '.md')
|
||||||
).write_text(
|
).write_text(
|
||||||
PythonModuleDocumentationGenerator(
|
PythonModuleDocumentationGenerator(
|
||||||
ExistingFile(str(dir / (sub_namespace.name + '.py'))),
|
pathlib.Path(str(dir / (sub_namespace.name + '.py'))),
|
||||||
ExistingDirectory(str(root_directory)),
|
pathlib.Path(str(root_directory)),
|
||||||
include_sections,
|
include_sections,
|
||||||
**kwargs
|
**kwargs
|
||||||
).generate_documentation()
|
).generate_documentation()
|
||||||
@@ -889,9 +885,9 @@ class PythonDocumentationGenerator:
|
|||||||
The class for the documentation generator.
|
The class for the documentation generator.
|
||||||
|
|
||||||
:param project_directory: The directory of the project.
|
:param project_directory: The directory of the project.
|
||||||
:type project_directory: ExistingDirectory
|
:type project_directory: pathlib.Path
|
||||||
: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: pathlib.Path
|
||||||
:param include_sections: The sections to be included in the documentation.
|
:param include_sections: The sections to be included in the documentation.
|
||||||
:type include_sections: PythonDefinitionDocumentationIncludeSections
|
:type include_sections: PythonDefinitionDocumentationIncludeSections
|
||||||
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
|
||||||
@@ -899,14 +895,11 @@ class PythonDocumentationGenerator:
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
project_directory: ExistingDirectory,
|
project_directory: pathlib.Path,
|
||||||
docs_directory: ExistingDirectory,
|
docs_directory: pathlib.Path,
|
||||||
include_sections: PythonDefinitionDocumentationIncludeSections = PythonDefinitionDocumentationIncludeSections(),
|
include_sections: PythonDefinitionDocumentationIncludeSections = PythonDefinitionDocumentationIncludeSections(),
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> None:
|
) -> None:
|
||||||
assert_that_is_instance(project_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.include_sections = include_sections
|
||||||
|
|||||||
Reference in new issue
Block a user