Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
workflow_dispatch:
pull_request:
branches: ["main"]
push:
branches: ["main"]
jobs:
test:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -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 }}
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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$
Expand Down
6 changes: 2 additions & 4 deletions pathlibutil/base.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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.
Expand Down
40 changes: 20 additions & 20 deletions pathlibutil/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -130,7 +130,7 @@ def verify(

return True

def __enter__(self) -> _Path:
def __enter__(self) -> "Path":
"""
Contextmanager to changes the current working directory.
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand All @@ -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.
"""
Expand All @@ -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.

Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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).
"""
Expand All @@ -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.

Expand All @@ -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")
```
"""
Expand Down Expand Up @@ -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.
Expand Down
Loading