From ce5221525e664fcc153c857ebdd06ee325797d1c Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Fri, 20 Jun 2025 17:02:49 +0100 Subject: [PATCH] inline typeshed stubs --- .github/workflows/ci.yml | 19 +++++++ src/dirhash-stubs/__init__.pyi | 93 ++++++++++++++++++++++++++++++++++ src/dirhash-stubs/cli.pyi | 5 ++ 3 files changed, 117 insertions(+) create mode 100644 src/dirhash-stubs/__init__.pyi create mode 100644 src/dirhash-stubs/cli.pyi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47e7d0d..a5698b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,3 +55,22 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} verbose: true + + stubtest: + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.x + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -e . mypy + - name: Run stubtest + run: python -m mypy.stubtest dirhash + diff --git a/src/dirhash-stubs/__init__.pyi b/src/dirhash-stubs/__init__.pyi new file mode 100644 index 0000000..5a24f69 --- /dev/null +++ b/src/dirhash-stubs/__init__.pyi @@ -0,0 +1,93 @@ +from _typeshed import Incomplete +from collections.abc import Generator, Iterable +from os import PathLike +from typing import TypeVar +from typing_extensions import TypeAlias + +_DirNode: TypeAlias = Incomplete # scantree.DirNode +_RecursionPath: TypeAlias = Incomplete # scantree.RecursionPath +_RP = TypeVar("_RP", bound=_RecursionPath) + +__all__ = [ + "__version__", + "algorithms_guaranteed", + "algorithms_available", + "dirhash", + "dirhash_impl", + "included_paths", + "Filter", + "get_match_patterns", + "Protocol", +] + +__version__: str +algorithms_guaranteed: set[str] +algorithms_available: set[str] + +def dirhash( + directory: str | PathLike[str], + algorithm: str, + match: Iterable[str] = ("*",), + ignore: Iterable[str] | None = None, + linked_dirs: bool = True, + linked_files: bool = True, + empty_dirs: bool = False, + entry_properties: Iterable[str] = ("name", "data"), + allow_cyclic_links: bool = False, + chunk_size: int = 1048576, + jobs: int = 1, +) -> str: ... +def dirhash_impl( + directory: str | PathLike[str], + algorithm: str, + filter_: Filter | None = None, + protocol: Protocol | None = None, + chunk_size: int = 1048576, + jobs: int = 1, +) -> str: ... +def included_paths( + directory: str | PathLike[str], + match: Iterable[str] = ("*",), + ignore: Iterable[str] | None = None, + linked_dirs: bool = True, + linked_files: bool = True, + empty_dirs: bool = False, + allow_cyclic_links: bool = False, +) -> list[str]: ... + +class Filter: + linked_dirs: bool + linked_files: bool + empty_dirs: bool + + def __init__( + self, + match_patterns: Iterable[str] | None = None, + linked_dirs: bool = True, + linked_files: bool = True, + empty_dirs: bool = False, + ) -> None: ... + @property + def match_patterns(self) -> tuple[str, ...]: ... + def include(self, recursion_path: _RecursionPath) -> bool: ... + def match_file(self, filepath: str | PathLike[str]) -> bool: ... + def __call__(self, paths: Iterable[_RP]) -> Generator[_RP, None, None]: ... + +def get_match_patterns( + match: Iterable[str] | None = None, + ignore: Iterable[str] | None = None, + ignore_extensions: Iterable[str] | None = None, + ignore_hidden: bool = False, +) -> list[str]: ... + +class Protocol: + class EntryProperties: + NAME: str + DATA: str + IS_LINK: str + options: set[str] + + entry_properties: Iterable[str] + allow_cyclic_links: bool + def __init__(self, entry_properties: Iterable[str] = ("name", "data"), allow_cyclic_links: bool = False) -> None: ... + def get_descriptor(self, dir_node: _DirNode) -> str: ... diff --git a/src/dirhash-stubs/cli.pyi b/src/dirhash-stubs/cli.pyi new file mode 100644 index 0000000..b822914 --- /dev/null +++ b/src/dirhash-stubs/cli.pyi @@ -0,0 +1,5 @@ +from collections.abc import Sequence +from typing import Any + +def main() -> None: ... +def get_kwargs(args: Sequence[str]) -> dict[str, Any]: ... # value depends on the key