kaparoo-python 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/PKG-INFO +6 -1
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/README.md +5 -0
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/data/sequence.py +39 -39
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/data/utils.py +46 -46
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/__init__.py +73 -73
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/directory.py +226 -226
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/exceptions.py +17 -17
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/existence.py +392 -392
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/search/__init__.py +2 -0
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/search/classes.py +208 -199
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/search/deprecated.py +289 -289
- kaparoo_python-0.2.1/kaparoo/filesystem/search/filters/__init__.py +73 -0
- kaparoo_python-0.2.1/kaparoo/filesystem/search/filters/base.py +92 -0
- kaparoo_python-0.2.1/kaparoo/filesystem/search/filters/logical.py +138 -0
- kaparoo_python-0.2.1/kaparoo/filesystem/search/filters/multi_pattern.py +154 -0
- kaparoo_python-0.2.1/kaparoo/filesystem/search/filters/pattern.py +210 -0
- kaparoo_python-0.2.1/kaparoo/filesystem/search/filters/types.py +47 -0
- kaparoo_python-0.2.1/kaparoo/filesystem/search/filters/utils.py +51 -0
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/search/wrappers.py +318 -311
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/types.py +9 -9
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/filesystem/utils.py +208 -208
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/utils/__init__.py +21 -21
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/utils/optional.py +129 -129
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/utils/timer.py +374 -374
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/pyproject.toml +265 -253
- kaparoo_python-0.2.0/kaparoo/filesystem/search/filters.py +0 -322
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/LICENSE +0 -0
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/__init__.py +0 -0
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/data/__init__.py +0 -0
- {kaparoo_python-0.2.0 → kaparoo_python-0.2.1}/kaparoo/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kaparoo-python
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Personally common and useful Python features
|
|
5
5
|
Keywords: filesystem,pathlib,paths,utilities
|
|
6
6
|
Author: Jaewoo Park
|
|
@@ -66,6 +66,11 @@ Filesystem traversal with composable filters.
|
|
|
66
66
|
- **Multi-pattern filters** — `EqualsAny`, `StartsWithAny`, `EndsWithAny`,
|
|
67
67
|
`ContainsAny`.
|
|
68
68
|
- **Logical filters** — `And`, `Or`, `Not`.
|
|
69
|
+
- **Serialization** — `Filter.to_dict()` / `Filter.from_dict()` round-trip
|
|
70
|
+
via a `"kind"` discriminator; `Filter.parse()` accepts a `Filter` or a
|
|
71
|
+
`FilterDict`; `register_filter(kind)` extends the dispatcher with
|
|
72
|
+
custom subclasses. `FilterDict` family lives at
|
|
73
|
+
`kaparoo.filesystem.search.filters.types`.
|
|
69
74
|
- **Deprecated** — `get_paths`, `get_files`, `get_dirs` (use `search_*`).
|
|
70
75
|
|
|
71
76
|
### `kaparoo.utils`
|
|
@@ -45,6 +45,11 @@ Filesystem traversal with composable filters.
|
|
|
45
45
|
- **Multi-pattern filters** — `EqualsAny`, `StartsWithAny`, `EndsWithAny`,
|
|
46
46
|
`ContainsAny`.
|
|
47
47
|
- **Logical filters** — `And`, `Or`, `Not`.
|
|
48
|
+
- **Serialization** — `Filter.to_dict()` / `Filter.from_dict()` round-trip
|
|
49
|
+
via a `"kind"` discriminator; `Filter.parse()` accepts a `Filter` or a
|
|
50
|
+
`FilterDict`; `register_filter(kind)` extends the dispatcher with
|
|
51
|
+
custom subclasses. `FilterDict` family lives at
|
|
52
|
+
`kaparoo.filesystem.search.filters.types`.
|
|
48
53
|
- **Deprecated** — `get_paths`, `get_files`, `get_dirs` (use `search_*`).
|
|
49
54
|
|
|
50
55
|
### `kaparoo.utils`
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
__all__ = ("DataSequence",)
|
|
4
|
-
|
|
5
|
-
from abc import abstractmethod
|
|
6
|
-
from collections.abc import Sequence
|
|
7
|
-
from typing import TYPE_CHECKING, overload
|
|
8
|
-
|
|
9
|
-
if TYPE_CHECKING:
|
|
10
|
-
from kaparoo.filesystem.types import StrPath
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class DataSequence[T](Sequence[T]):
|
|
14
|
-
@abstractmethod
|
|
15
|
-
def __init__(self, path: StrPath) -> None:
|
|
16
|
-
raise NotImplementedError
|
|
17
|
-
|
|
18
|
-
@abstractmethod
|
|
19
|
-
def __len__(self) -> int:
|
|
20
|
-
raise NotImplementedError
|
|
21
|
-
|
|
22
|
-
@overload
|
|
23
|
-
def __getitem__(self, index: int, /) -> T: ...
|
|
24
|
-
|
|
25
|
-
@overload
|
|
26
|
-
def __getitem__(self, index: slice, /) -> Sequence[T]: ...
|
|
27
|
-
|
|
28
|
-
def __getitem__(self, index: int | slice, /) -> T | Sequence[T]:
|
|
29
|
-
if isinstance(index, slice):
|
|
30
|
-
start, stop, step = index.indices(len(self))
|
|
31
|
-
return self.by_indices(range(start, stop, step))
|
|
32
|
-
return self.by_index(index)
|
|
33
|
-
|
|
34
|
-
@abstractmethod
|
|
35
|
-
def by_index(self, index: int) -> T:
|
|
36
|
-
raise NotImplementedError
|
|
37
|
-
|
|
38
|
-
def by_indices(self, indices: Sequence[int]) -> Sequence[T]:
|
|
39
|
-
return [self.by_index(index) for index in indices]
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
__all__ = ("DataSequence",)
|
|
4
|
+
|
|
5
|
+
from abc import abstractmethod
|
|
6
|
+
from collections.abc import Sequence
|
|
7
|
+
from typing import TYPE_CHECKING, overload
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from kaparoo.filesystem.types import StrPath
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DataSequence[T](Sequence[T]):
|
|
14
|
+
@abstractmethod
|
|
15
|
+
def __init__(self, path: StrPath) -> None:
|
|
16
|
+
raise NotImplementedError
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def __len__(self) -> int:
|
|
20
|
+
raise NotImplementedError
|
|
21
|
+
|
|
22
|
+
@overload
|
|
23
|
+
def __getitem__(self, index: int, /) -> T: ...
|
|
24
|
+
|
|
25
|
+
@overload
|
|
26
|
+
def __getitem__(self, index: slice, /) -> Sequence[T]: ...
|
|
27
|
+
|
|
28
|
+
def __getitem__(self, index: int | slice, /) -> T | Sequence[T]:
|
|
29
|
+
if isinstance(index, slice):
|
|
30
|
+
start, stop, step = index.indices(len(self))
|
|
31
|
+
return self.by_indices(range(start, stop, step))
|
|
32
|
+
return self.by_index(index)
|
|
33
|
+
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def by_index(self, index: int) -> T:
|
|
36
|
+
raise NotImplementedError
|
|
37
|
+
|
|
38
|
+
def by_indices(self, indices: Sequence[int]) -> Sequence[T]:
|
|
39
|
+
return [self.by_index(index) for index in indices]
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
__all__ = ("generate_batches",)
|
|
4
|
-
|
|
5
|
-
from typing import TYPE_CHECKING
|
|
6
|
-
|
|
7
|
-
from kaparoo.utils.optional import replace_if_none
|
|
8
|
-
|
|
9
|
-
if TYPE_CHECKING:
|
|
10
|
-
from collections.abc import Iterator, Sequence
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def generate_batches[T](
|
|
14
|
-
sequence: Sequence[T],
|
|
15
|
-
size: int,
|
|
16
|
-
step: int = 1,
|
|
17
|
-
skip: int = 1,
|
|
18
|
-
start: int = 0,
|
|
19
|
-
stop: int | None = None,
|
|
20
|
-
*,
|
|
21
|
-
drop_last: bool = True,
|
|
22
|
-
) -> Iterator[Sequence[T]]:
|
|
23
|
-
def die_if_not_positive(name: str, value: int) -> None:
|
|
24
|
-
if value <= 0:
|
|
25
|
-
msg = f"{name} must be positive (got {value})"
|
|
26
|
-
raise ValueError(msg)
|
|
27
|
-
|
|
28
|
-
die_if_not_positive("size", size)
|
|
29
|
-
die_if_not_positive("step", step)
|
|
30
|
-
die_if_not_positive("skip", skip)
|
|
31
|
-
|
|
32
|
-
stop = replace_if_none(stop, len_ := len(sequence))
|
|
33
|
-
if not (start < stop <= len_ and start >= 0):
|
|
34
|
-
msg = f"invalid range [{start}, {stop}) for sequence of length {len_}"
|
|
35
|
-
raise ValueError(msg)
|
|
36
|
-
|
|
37
|
-
head = start
|
|
38
|
-
tail = head + (size - 1) * skip + 1
|
|
39
|
-
|
|
40
|
-
while tail <= stop:
|
|
41
|
-
yield sequence[head:tail:skip]
|
|
42
|
-
head += step
|
|
43
|
-
tail += step
|
|
44
|
-
|
|
45
|
-
if not drop_last and head < stop:
|
|
46
|
-
yield sequence[head:tail:skip]
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
__all__ = ("generate_batches",)
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from kaparoo.utils.optional import replace_if_none
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from collections.abc import Iterator, Sequence
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def generate_batches[T](
|
|
14
|
+
sequence: Sequence[T],
|
|
15
|
+
size: int,
|
|
16
|
+
step: int = 1,
|
|
17
|
+
skip: int = 1,
|
|
18
|
+
start: int = 0,
|
|
19
|
+
stop: int | None = None,
|
|
20
|
+
*,
|
|
21
|
+
drop_last: bool = True,
|
|
22
|
+
) -> Iterator[Sequence[T]]:
|
|
23
|
+
def die_if_not_positive(name: str, value: int) -> None:
|
|
24
|
+
if value <= 0:
|
|
25
|
+
msg = f"{name} must be positive (got {value})"
|
|
26
|
+
raise ValueError(msg)
|
|
27
|
+
|
|
28
|
+
die_if_not_positive("size", size)
|
|
29
|
+
die_if_not_positive("step", step)
|
|
30
|
+
die_if_not_positive("skip", skip)
|
|
31
|
+
|
|
32
|
+
stop = replace_if_none(stop, len_ := len(sequence))
|
|
33
|
+
if not (start < stop <= len_ and start >= 0):
|
|
34
|
+
msg = f"invalid range [{start}, {stop}) for sequence of length {len_}"
|
|
35
|
+
raise ValueError(msg)
|
|
36
|
+
|
|
37
|
+
head = start
|
|
38
|
+
tail = head + (size - 1) * skip + 1
|
|
39
|
+
|
|
40
|
+
while tail <= stop:
|
|
41
|
+
yield sequence[head:tail:skip]
|
|
42
|
+
head += step
|
|
43
|
+
tail += step
|
|
44
|
+
|
|
45
|
+
if not drop_last and head < stop:
|
|
46
|
+
yield sequence[head:tail:skip]
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
__all__ = (
|
|
2
|
-
"DirectoryNotFoundError",
|
|
3
|
-
"NotAFileError",
|
|
4
|
-
"dir_empty",
|
|
5
|
-
"dir_empty_unsafe",
|
|
6
|
-
"dir_exists",
|
|
7
|
-
"dirs_empty",
|
|
8
|
-
"dirs_empty_unsafe",
|
|
9
|
-
"dirs_exist",
|
|
10
|
-
"ensure_dir_exists",
|
|
11
|
-
"ensure_dirs_exist",
|
|
12
|
-
"ensure_file_exists",
|
|
13
|
-
"ensure_files_exist",
|
|
14
|
-
"ensure_path_exists",
|
|
15
|
-
"ensure_paths_exist",
|
|
16
|
-
"file_exists",
|
|
17
|
-
"files_exist",
|
|
18
|
-
"get_dirs",
|
|
19
|
-
"get_files",
|
|
20
|
-
"get_paths",
|
|
21
|
-
"make_dir",
|
|
22
|
-
"make_dirs",
|
|
23
|
-
"path_exists",
|
|
24
|
-
"paths_exist",
|
|
25
|
-
"search_dirs",
|
|
26
|
-
"search_files",
|
|
27
|
-
"search_paths",
|
|
28
|
-
"stringify_path",
|
|
29
|
-
"stringify_paths",
|
|
30
|
-
"wrap_path",
|
|
31
|
-
"wrap_paths",
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
from kaparoo.filesystem.directory import (
|
|
35
|
-
dir_empty,
|
|
36
|
-
dir_empty_unsafe,
|
|
37
|
-
dirs_empty,
|
|
38
|
-
dirs_empty_unsafe,
|
|
39
|
-
make_dir,
|
|
40
|
-
make_dirs,
|
|
41
|
-
)
|
|
42
|
-
from kaparoo.filesystem.exceptions import (
|
|
43
|
-
DirectoryNotFoundError,
|
|
44
|
-
NotAFileError,
|
|
45
|
-
)
|
|
46
|
-
from kaparoo.filesystem.existence import (
|
|
47
|
-
dir_exists,
|
|
48
|
-
dirs_exist,
|
|
49
|
-
ensure_dir_exists,
|
|
50
|
-
ensure_dirs_exist,
|
|
51
|
-
ensure_file_exists,
|
|
52
|
-
ensure_files_exist,
|
|
53
|
-
ensure_path_exists,
|
|
54
|
-
ensure_paths_exist,
|
|
55
|
-
file_exists,
|
|
56
|
-
files_exist,
|
|
57
|
-
path_exists,
|
|
58
|
-
paths_exist,
|
|
59
|
-
)
|
|
60
|
-
from kaparoo.filesystem.search import (
|
|
61
|
-
get_dirs,
|
|
62
|
-
get_files,
|
|
63
|
-
get_paths,
|
|
64
|
-
search_dirs,
|
|
65
|
-
search_files,
|
|
66
|
-
search_paths,
|
|
67
|
-
)
|
|
68
|
-
from kaparoo.filesystem.utils import (
|
|
69
|
-
stringify_path,
|
|
70
|
-
stringify_paths,
|
|
71
|
-
wrap_path,
|
|
72
|
-
wrap_paths,
|
|
73
|
-
)
|
|
1
|
+
__all__ = (
|
|
2
|
+
"DirectoryNotFoundError",
|
|
3
|
+
"NotAFileError",
|
|
4
|
+
"dir_empty",
|
|
5
|
+
"dir_empty_unsafe",
|
|
6
|
+
"dir_exists",
|
|
7
|
+
"dirs_empty",
|
|
8
|
+
"dirs_empty_unsafe",
|
|
9
|
+
"dirs_exist",
|
|
10
|
+
"ensure_dir_exists",
|
|
11
|
+
"ensure_dirs_exist",
|
|
12
|
+
"ensure_file_exists",
|
|
13
|
+
"ensure_files_exist",
|
|
14
|
+
"ensure_path_exists",
|
|
15
|
+
"ensure_paths_exist",
|
|
16
|
+
"file_exists",
|
|
17
|
+
"files_exist",
|
|
18
|
+
"get_dirs",
|
|
19
|
+
"get_files",
|
|
20
|
+
"get_paths",
|
|
21
|
+
"make_dir",
|
|
22
|
+
"make_dirs",
|
|
23
|
+
"path_exists",
|
|
24
|
+
"paths_exist",
|
|
25
|
+
"search_dirs",
|
|
26
|
+
"search_files",
|
|
27
|
+
"search_paths",
|
|
28
|
+
"stringify_path",
|
|
29
|
+
"stringify_paths",
|
|
30
|
+
"wrap_path",
|
|
31
|
+
"wrap_paths",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
from kaparoo.filesystem.directory import (
|
|
35
|
+
dir_empty,
|
|
36
|
+
dir_empty_unsafe,
|
|
37
|
+
dirs_empty,
|
|
38
|
+
dirs_empty_unsafe,
|
|
39
|
+
make_dir,
|
|
40
|
+
make_dirs,
|
|
41
|
+
)
|
|
42
|
+
from kaparoo.filesystem.exceptions import (
|
|
43
|
+
DirectoryNotFoundError,
|
|
44
|
+
NotAFileError,
|
|
45
|
+
)
|
|
46
|
+
from kaparoo.filesystem.existence import (
|
|
47
|
+
dir_exists,
|
|
48
|
+
dirs_exist,
|
|
49
|
+
ensure_dir_exists,
|
|
50
|
+
ensure_dirs_exist,
|
|
51
|
+
ensure_file_exists,
|
|
52
|
+
ensure_files_exist,
|
|
53
|
+
ensure_path_exists,
|
|
54
|
+
ensure_paths_exist,
|
|
55
|
+
file_exists,
|
|
56
|
+
files_exist,
|
|
57
|
+
path_exists,
|
|
58
|
+
paths_exist,
|
|
59
|
+
)
|
|
60
|
+
from kaparoo.filesystem.search import (
|
|
61
|
+
get_dirs,
|
|
62
|
+
get_files,
|
|
63
|
+
get_paths,
|
|
64
|
+
search_dirs,
|
|
65
|
+
search_files,
|
|
66
|
+
search_paths,
|
|
67
|
+
)
|
|
68
|
+
from kaparoo.filesystem.utils import (
|
|
69
|
+
stringify_path,
|
|
70
|
+
stringify_paths,
|
|
71
|
+
wrap_path,
|
|
72
|
+
wrap_paths,
|
|
73
|
+
)
|