From 077ab0d1859d4baa6baebe69f9000ab00982ea86 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:05:41 +0000 Subject: [PATCH 1/2] Bump codecov/codecov-action from 4 to 5 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4 to 5. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v4...v5) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index fca86bb..5f1f113 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -44,7 +44,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 }} From 77b7c3e9ba3dbc31c4c6bd343d7db165d684d71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20D=C3=B6rrer?= Date: Wed, 26 Feb 2025 20:02:03 +0100 Subject: [PATCH 2/2] update type hints to use BasePath and Path for better clarity --- .github/workflows/pytest.yml | 2 -- pathlibutil/base.py | 6 ++---- pathlibutil/path.py | 40 ++++++++++++++++++------------------ 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index fca86bb..ad75635 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 }} 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.