Skip to content

Commit 919a634

Browse files
authored
Merge pull request #23 from d-chris/develop
Update codecov-action and improve type hints
2 parents 858b7e7 + bd10d96 commit 919a634

4 files changed

Lines changed: 31 additions & 35 deletions

File tree

.github/workflows/pytest.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
workflow_dispatch:
66
pull_request:
77
branches: ["main"]
8-
push:
9-
branches: ["main"]
108
jobs:
119
test:
1210
runs-on: ${{ matrix.os }}
@@ -44,7 +42,7 @@ jobs:
4442
- name: Restore all Coverage Reports
4543
uses: actions/download-artifact@v4
4644
- name: Upload Coverage Report
47-
uses: codecov/codecov-action@v4
45+
uses: codecov/codecov-action@v5
4846
with:
4947
flags: unittests
5048
token: ${{ secrets.CODECOV_TOKEN }}

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ repos:
1111
hooks:
1212
- id: pyproject-fmt
1313
- repo: https://github.com/tox-dev/tox-ini-fmt
14-
rev: 1.4.1
14+
rev: 1.5.0
1515
hooks:
1616
- id: tox-ini-fmt
1717
- repo: https://github.com/rhysd/actionlint
18-
rev: v1.7.3
18+
rev: v1.7.7
1919
hooks:
2020
- id: actionlint
2121
- repo: https://github.com/psf/black
22-
rev: 24.10.0
22+
rev: 25.1.0
2323
hooks:
2424
- id: black
2525
- repo: https://github.com/adamchainz/blacken-docs
@@ -28,26 +28,26 @@ repos:
2828
- id: blacken-docs
2929
files: pathlibutil/
3030
- repo: https://github.com/pycqa/isort
31-
rev: 5.13.2
31+
rev: 6.0.0
3232
hooks:
3333
- id: isort
3434
- repo: https://github.com/python-poetry/poetry
35-
rev: 1.8.0
35+
rev: 1.8.5
3636
hooks:
3737
- id: poetry-check
3838
- id: poetry-lock
3939
args: ["--no-update"]
4040
- repo: https://github.com/google/yamlfmt
41-
rev: v0.14.0
41+
rev: v0.16.0
4242
hooks:
4343
- id: yamlfmt
4444
- repo: https://github.com/PyCQA/flake8
45-
rev: 7.1.1
45+
rev: 7.1.2
4646
hooks:
4747
- id: flake8
4848
args: ["--max-line-length", "88", "--exclude=examples/**"]
4949
- repo: https://github.com/d-chris/jinja2_pdoc
50-
rev: v1.2.0
50+
rev: v1.3.0
5151
hooks:
5252
- id: jinja2pdoc
5353
files: docs/README\.md\.jinja2$

pathlibutil/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import os
22
import pathlib
33
import sys
4-
from typing import Generator, TypeVar
5-
6-
_Path = TypeVar("_Path", bound=pathlib.Path)
4+
from typing import Generator
75

86

97
class BasePath(pathlib.Path):
@@ -19,7 +17,7 @@ class BasePath(pathlib.Path):
1917
)
2018

2119
@classmethod
22-
def expand(cls, file: str) -> Generator[_Path, None, None]:
20+
def expand(cls, file: str) -> Generator["BasePath", None, None]:
2321
"""
2422
yields only Path object of file names that exists. Supports glob patterns in
2523
filename as wildcards.

pathlibutil/path.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from datetime import datetime, timedelta
1010
from typing import Callable, Dict, Generator, List, Literal, Set, Tuple, Union
1111

12-
from pathlibutil.base import BasePath, _Path
12+
from pathlibutil.base import BasePath
1313
from pathlibutil.types import ByteInt, StatResult, TimeInt, _stat_result, byteint
1414

1515

@@ -130,7 +130,7 @@ def verify(
130130

131131
return True
132132

133-
def __enter__(self) -> _Path:
133+
def __enter__(self) -> "Path":
134134
"""
135135
Contextmanager to changes the current working directory.
136136
"""
@@ -175,7 +175,7 @@ def size(self, **kwargs) -> ByteInt:
175175

176176
return super().stat(**kwargs).st_size
177177

178-
def copy(self, dst: str, exist_ok: bool = True, **kwargs) -> _Path:
178+
def copy(self, dst: str, exist_ok: bool = True, **kwargs) -> "Path":
179179
"""
180180
Copies the file or directory to a destination directory, if it is missing it
181181
will be created.
@@ -227,7 +227,7 @@ def delete(
227227

228228
shutil.rmtree(self, **kwargs)
229229

230-
def move(self, dst: str) -> _Path:
230+
def move(self, dst: str) -> "Path":
231231
"""
232232
Moves the file or directory into the destination directory.
233233
@@ -247,7 +247,7 @@ def move(self, dst: str) -> _Path:
247247
return self.__class__(_path)
248248

249249
@staticmethod
250-
def _find_archive_format(filename: _Path) -> str:
250+
def _find_archive_format(filename: "Path") -> str:
251251
"""
252252
Searches for a file the correct archive format.
253253
"""
@@ -273,7 +273,7 @@ def _register_format(cls, format: str) -> None:
273273

274274
def make_archive(
275275
self, archivename: str, *, exists_ok: bool = False, **kwargs
276-
) -> _Path:
276+
) -> "Path":
277277
"""
278278
Creates an archive file (eg. zip) and returns the path to the archive.
279279
@@ -296,7 +296,7 @@ def make_archive(
296296
Path('test.zpy')
297297
"""
298298

299-
def _archive_exists(file: str, exists_ok: bool) -> _Path:
299+
def _archive_exists(file: str, exists_ok: bool) -> "Path":
300300
"""
301301
Returns a `Path` object of the archive file or raises a `FileExistsError`
302302
If `exists_ok` is `True` the file will be deleted.
@@ -311,7 +311,7 @@ def _archive_exists(file: str, exists_ok: bool) -> _Path:
311311

312312
return file
313313

314-
def _archive_filename(expect: Path, real: str) -> _Path:
314+
def _archive_filename(expect: Path, real: str) -> "Path":
315315
"""
316316
Check if the expected archive filename matches the real filename.
317317
If not try to rename the real filename.
@@ -346,7 +346,7 @@ def _archive_filename(expect: Path, real: str) -> _Path:
346346

347347
return _archive_filename(_filename, _archive)
348348

349-
def unpack_archive(self, extract_dir: str, **kwargs) -> _Path:
349+
def unpack_archive(self, extract_dir: str, **kwargs) -> "Path":
350350
"""
351351
Unpacks an archive file (eg. zip) into a directory and returns the path to the
352352
extracted files.
@@ -405,7 +405,7 @@ def stat(self, **kwargs) -> _stat_result:
405405
"""
406406
return StatResult(super().stat(**kwargs))
407407

408-
def with_suffix(self, suffix: Union[str, List[str]]) -> _Path:
408+
def with_suffix(self, suffix: Union[str, List[str]]) -> "Path":
409409
"""
410410
Return a new `Path` with changed suffix or remove it when its an empty
411411
string.
@@ -444,8 +444,8 @@ def with_suffix(self, suffix: Union[str, List[str]]) -> _Path:
444444
return super(self.__class__, stem).with_suffix(suffix)
445445

446446
def relative_to(
447-
self, *other: Union[str, _Path], walk_up: Union[bool, int] = False
448-
) -> _Path:
447+
self, *other: Union[str, "Path"], walk_up: Union[bool, int] = False
448+
) -> "Path":
449449
"""
450450
Return the relative path to another path identified by the passed
451451
arguments. If the operation is not possible (because this is not
@@ -485,7 +485,7 @@ def relative_to(
485485
return relative
486486

487487
@classmethod
488-
def cwd(cls, *, frozen: Literal[True, False, "_MEIPASS"] = False) -> _Path:
488+
def cwd(cls, *, frozen: Literal[True, False, "_MEIPASS"] = False) -> "Path":
489489
"""
490490
Return a `Path` object representing the current working directory.
491491
@@ -536,7 +536,7 @@ def run(cmd: str) -> str:
536536
except Exception:
537537
return {}
538538

539-
def _resolve_unc(self) -> _Path:
539+
def _resolve_unc(self) -> "Path":
540540
"""
541541
Resolve UNC paths to mapped network drives.
542542
"""
@@ -549,7 +549,7 @@ def _resolve_unc(self) -> _Path:
549549
except KeyError:
550550
return self
551551

552-
def resolve(self, strict: bool = False, unc: bool = True) -> _Path:
552+
def resolve(self, strict: bool = False, unc: bool = True) -> "Path":
553553
"""
554554
Make the path absolute, resolving all symlinks on the way and also normalizing
555555
it.
@@ -579,7 +579,7 @@ def walk(
579579
top_down: bool = True,
580580
on_error: Callable[[OSError], object] = None,
581581
follow_symlinks: bool = False,
582-
) -> Generator[Tuple[_Path, List[str], List[str]], None, None]:
582+
) -> Generator[Tuple["Path", List[str], List[str]], None, None]:
583583
"""
584584
Walks the directory tree and yields a 3-tuple of (dirpath, dirnames, filenames).
585585
"""
@@ -602,9 +602,9 @@ def iterdir(
602602
self,
603603
*,
604604
recursive: Union[bool, int] = False,
605-
exclude_dirs: Callable[[_Path], bool] = None,
605+
exclude_dirs: Callable[["Path"], bool] = None,
606606
**kwargs,
607-
) -> Generator[_Path, None, None]:
607+
) -> Generator["Path", None, None]:
608608
"""
609609
Iterates over the files in the directory.
610610
@@ -616,7 +616,7 @@ def iterdir(
616616
`exclude_dirs`, e.g.
617617
618618
```python
619-
def exclude_version_control(dirpath: _Path) -> bool:
619+
def exclude_version_control(dirpath: "Path") -> bool:
620620
return dirpath.name in (".git", ".svn", ".hg", ".bzr", "CVS")
621621
```
622622
"""
@@ -660,7 +660,7 @@ def expand(
660660
cls,
661661
*files: str,
662662
duplicates: bool = True,
663-
) -> Generator[_Path, None, None]:
663+
) -> Generator["Path", None, None]:
664664
"""
665665
Yields only Path object of file names that exists. Supports glob patterns in
666666
filename as wildcards.

0 commit comments

Comments
 (0)