diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index fca86bb..9bf1315 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -5,8 +5,6 @@ on: workflow_dispatch: pull_request: branches: ["main"] - push: - branches: ["main"] jobs: test: runs-on: ${{ matrix.os }} @@ -44,7 +42,7 @@ jobs: - name: Restore all Coverage Reports uses: actions/download-artifact@v4 - name: Upload Coverage Report - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: flags: unittests token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc824e8..d85d7cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,15 +11,15 @@ repos: hooks: - id: pyproject-fmt - repo: https://github.com/tox-dev/tox-ini-fmt - rev: 1.4.1 + rev: 1.5.0 hooks: - id: tox-ini-fmt - repo: https://github.com/rhysd/actionlint - rev: v1.7.3 + rev: v1.7.7 hooks: - id: actionlint - repo: https://github.com/psf/black - rev: 24.10.0 + rev: 25.1.0 hooks: - id: black - repo: https://github.com/adamchainz/blacken-docs @@ -28,26 +28,26 @@ repos: - id: blacken-docs files: pathlibutil/ - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 6.0.0 hooks: - id: isort - repo: https://github.com/python-poetry/poetry - rev: 1.8.0 + rev: 1.8.5 hooks: - id: poetry-check - id: poetry-lock args: ["--no-update"] - repo: https://github.com/google/yamlfmt - rev: v0.14.0 + rev: v0.16.0 hooks: - id: yamlfmt - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + rev: 7.1.2 hooks: - id: flake8 args: ["--max-line-length", "88", "--exclude=examples/**"] - repo: https://github.com/d-chris/jinja2_pdoc - rev: v1.2.0 + rev: v1.3.0 hooks: - id: jinja2pdoc files: docs/README\.md\.jinja2$ diff --git a/pathlibutil/base.py b/pathlibutil/base.py index 3d35437..cec965d 100644 --- a/pathlibutil/base.py +++ b/pathlibutil/base.py @@ -1,9 +1,7 @@ import os import pathlib import sys -from typing import Generator, TypeVar - -_Path = TypeVar("_Path", bound=pathlib.Path) +from typing import Generator class BasePath(pathlib.Path): @@ -19,7 +17,7 @@ class BasePath(pathlib.Path): ) @classmethod - def expand(cls, file: str) -> Generator[_Path, None, None]: + def expand(cls, file: str) -> Generator["BasePath", None, None]: """ yields only Path object of file names that exists. Supports glob patterns in filename as wildcards. diff --git a/pathlibutil/path.py b/pathlibutil/path.py index 5210550..c578e0e 100644 --- a/pathlibutil/path.py +++ b/pathlibutil/path.py @@ -9,7 +9,7 @@ from datetime import datetime, timedelta from typing import Callable, Dict, Generator, List, Literal, Set, Tuple, Union -from pathlibutil.base import BasePath, _Path +from pathlibutil.base import BasePath from pathlibutil.types import ByteInt, StatResult, TimeInt, _stat_result, byteint @@ -130,7 +130,7 @@ def verify( return True - def __enter__(self) -> _Path: + def __enter__(self) -> "Path": """ Contextmanager to changes the current working directory. """ @@ -175,7 +175,7 @@ def size(self, **kwargs) -> ByteInt: return super().stat(**kwargs).st_size - def copy(self, dst: str, exist_ok: bool = True, **kwargs) -> _Path: + def copy(self, dst: str, exist_ok: bool = True, **kwargs) -> "Path": """ Copies the file or directory to a destination directory, if it is missing it will be created. @@ -227,7 +227,7 @@ def delete( shutil.rmtree(self, **kwargs) - def move(self, dst: str) -> _Path: + def move(self, dst: str) -> "Path": """ Moves the file or directory into the destination directory. @@ -247,7 +247,7 @@ def move(self, dst: str) -> _Path: return self.__class__(_path) @staticmethod - def _find_archive_format(filename: _Path) -> str: + def _find_archive_format(filename: "Path") -> str: """ Searches for a file the correct archive format. """ @@ -273,7 +273,7 @@ def _register_format(cls, format: str) -> None: def make_archive( self, archivename: str, *, exists_ok: bool = False, **kwargs - ) -> _Path: + ) -> "Path": """ Creates an archive file (eg. zip) and returns the path to the archive. @@ -296,7 +296,7 @@ def make_archive( Path('test.zpy') """ - def _archive_exists(file: str, exists_ok: bool) -> _Path: + def _archive_exists(file: str, exists_ok: bool) -> "Path": """ Returns a `Path` object of the archive file or raises a `FileExistsError` If `exists_ok` is `True` the file will be deleted. @@ -311,7 +311,7 @@ def _archive_exists(file: str, exists_ok: bool) -> _Path: return file - def _archive_filename(expect: Path, real: str) -> _Path: + def _archive_filename(expect: Path, real: str) -> "Path": """ Check if the expected archive filename matches the real filename. If not try to rename the real filename. @@ -346,7 +346,7 @@ def _archive_filename(expect: Path, real: str) -> _Path: return _archive_filename(_filename, _archive) - def unpack_archive(self, extract_dir: str, **kwargs) -> _Path: + def unpack_archive(self, extract_dir: str, **kwargs) -> "Path": """ Unpacks an archive file (eg. zip) into a directory and returns the path to the extracted files. @@ -405,7 +405,7 @@ def stat(self, **kwargs) -> _stat_result: """ return StatResult(super().stat(**kwargs)) - def with_suffix(self, suffix: Union[str, List[str]]) -> _Path: + def with_suffix(self, suffix: Union[str, List[str]]) -> "Path": """ Return a new `Path` with changed suffix or remove it when its an empty string. @@ -444,8 +444,8 @@ def with_suffix(self, suffix: Union[str, List[str]]) -> _Path: return super(self.__class__, stem).with_suffix(suffix) def relative_to( - self, *other: Union[str, _Path], walk_up: Union[bool, int] = False - ) -> _Path: + self, *other: Union[str, "Path"], walk_up: Union[bool, int] = False + ) -> "Path": """ Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not @@ -485,7 +485,7 @@ def relative_to( return relative @classmethod - def cwd(cls, *, frozen: Literal[True, False, "_MEIPASS"] = False) -> _Path: + def cwd(cls, *, frozen: Literal[True, False, "_MEIPASS"] = False) -> "Path": """ Return a `Path` object representing the current working directory. @@ -536,7 +536,7 @@ def run(cmd: str) -> str: except Exception: return {} - def _resolve_unc(self) -> _Path: + def _resolve_unc(self) -> "Path": """ Resolve UNC paths to mapped network drives. """ @@ -549,7 +549,7 @@ def _resolve_unc(self) -> _Path: except KeyError: return self - def resolve(self, strict: bool = False, unc: bool = True) -> _Path: + def resolve(self, strict: bool = False, unc: bool = True) -> "Path": """ Make the path absolute, resolving all symlinks on the way and also normalizing it. @@ -579,7 +579,7 @@ def walk( top_down: bool = True, on_error: Callable[[OSError], object] = None, follow_symlinks: bool = False, - ) -> Generator[Tuple[_Path, List[str], List[str]], None, None]: + ) -> Generator[Tuple["Path", List[str], List[str]], None, None]: """ Walks the directory tree and yields a 3-tuple of (dirpath, dirnames, filenames). """ @@ -602,9 +602,9 @@ def iterdir( self, *, recursive: Union[bool, int] = False, - exclude_dirs: Callable[[_Path], bool] = None, + exclude_dirs: Callable[["Path"], bool] = None, **kwargs, - ) -> Generator[_Path, None, None]: + ) -> Generator["Path", None, None]: """ Iterates over the files in the directory. @@ -616,7 +616,7 @@ def iterdir( `exclude_dirs`, e.g. ```python - def exclude_version_control(dirpath: _Path) -> bool: + def exclude_version_control(dirpath: "Path") -> bool: return dirpath.name in (".git", ".svn", ".hg", ".bzr", "CVS") ``` """ @@ -660,7 +660,7 @@ def expand( cls, *files: str, duplicates: bool = True, - ) -> Generator[_Path, None, None]: + ) -> Generator["Path", None, None]: """ Yields only Path object of file names that exists. Supports glob patterns in filename as wildcards.