Refactor(utils): mark ExistingDirectory and ExistingFile as deprecated #14

Merged
jakob.scheid merged 4 commits from refactor/remove-existing-file-class into main 2026-09-05 14:44:21 +02:00
2 changed files with 13 additions and 21 deletions
Showing only changes of commit 36cedb390b - Show all commits

No files matched your search

+2 -3
View File
@@ -22,11 +22,10 @@ __all__ = [
import argparse
import pathlib
from .utils import ExistingDirectory
def existing_directory(path: str, *args, **kwargs) -> pathlib.Path:
def existing_directory(path: str) -> pathlib.Path:
try:
return ExistingDirectory(path, *args, **kwargs)
return pathlib.Path(path)
jakob.scheid marked this conversation as resolved Outdated
Outdated
Review

There is no check whether the directory exists.

There is no check whether the directory exists.
except (FileNotFoundError, NotADirectoryError) as e:
raise argparse.ArgumentTypeError(f'{e.filename}{": " + e.args[1] if len(e.args) > 1 else ""}')
+11 -18
View File
@@ -13,7 +13,7 @@
# limitations under the License.
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 .namespaces import PythonModuleNamespace, PythonPackageNamespace
from .definitions import PythonDefinition, PythonFunctionDefinition, PythonAsyncFunctionDefinition, PythonClassDefinition
@@ -742,11 +742,11 @@ class PythonModuleDocumentationGenerator:
A documentation generator for a Python module.
: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
optional and only used for making the module
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.
:type include_sections: PythonDefinitionDocumentationIncludeSections
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
@@ -754,15 +754,11 @@ class PythonModuleDocumentationGenerator:
def __init__(
self,
module_path: ExistingFile,
src_directory: Union[ExistingDirectory, None] = None,
module_path: pathlib.Path,
src_directory: Union[pathlib.Path, None] = None,
include_sections: PythonDefinitionDocumentationIncludeSections = PythonDefinitionDocumentationIncludeSections(),
**kwargs
) -> None:
assert_that_is_instance(module_path, ExistingFile)
assert_that_is_instance(src_directory, (ExistingDirectory, types.NoneType))
if module_path.name.count('.') > 1:
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')
).write_text(
PythonModuleDocumentationGenerator(
ExistingFile(str(dir / (sub_namespace.name + '.py'))),
ExistingDirectory(str(root_directory)),
pathlib.Path(str(dir / (sub_namespace.name + '.py'))),
pathlib.Path(str(root_directory)),
include_sections,
**kwargs
).generate_documentation()
@@ -889,9 +885,9 @@ class PythonDocumentationGenerator:
The class for the documentation generator.
: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.
:type docs_directory: ExistingDirectory
:type docs_directory: pathlib.Path
:param include_sections: The sections to be included in the documentation.
:type include_sections: PythonDefinitionDocumentationIncludeSections
:param kwargs: The options for ``PythonDefinitionDocumentationGenerator``.
@@ -899,14 +895,11 @@ class PythonDocumentationGenerator:
def __init__(
self,
project_directory: ExistingDirectory,
docs_directory: ExistingDirectory,
project_directory: pathlib.Path,
docs_directory: pathlib.Path,
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