kaparoo-python 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl

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/__about__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.6"
1
+ __version__ = "0.1.8"
@@ -1,10 +1,4 @@
1
1
  __all__ = (
2
- # exceptions
3
- "DirectoryNotFoundError",
4
- "NotAFileError",
5
- # types
6
- "StrPath",
7
- "StrPaths",
8
2
  # utils
9
3
  "prepend_path",
10
4
  "prepend_paths",
@@ -30,11 +24,8 @@ __all__ = (
30
24
  "get_files",
31
25
  "get_paths",
32
26
  "make_dirs",
33
- # collections
34
- "DataFolder",
35
27
  )
36
28
 
37
- from kaparoo.filesystem.collections import DataFolder
38
29
  from kaparoo.filesystem.directory import (
39
30
  dir_empty,
40
31
  dirs_empty,
@@ -43,10 +34,6 @@ from kaparoo.filesystem.directory import (
43
34
  get_paths,
44
35
  make_dirs,
45
36
  )
46
- from kaparoo.filesystem.exceptions import (
47
- DirectoryNotFoundError,
48
- NotAFileError,
49
- )
50
37
  from kaparoo.filesystem.existence import (
51
38
  dir_exists,
52
39
  dirs_exist,
@@ -61,7 +48,6 @@ from kaparoo.filesystem.existence import (
61
48
  path_exists,
62
49
  paths_exist,
63
50
  )
64
- from kaparoo.filesystem.types import StrPath, StrPaths
65
51
  from kaparoo.filesystem.utils import (
66
52
  prepend_path,
67
53
  prepend_paths,
@@ -1,27 +1,28 @@
1
1
  from __future__ import annotations
2
2
 
3
- __all__ = ("DataFolder",)
3
+ __all__ = ("DataSequence", "DataFilesFolder", "UnifiedDataFile", "UnifiedDataFolder")
4
4
 
5
5
  from abc import abstractmethod
6
6
  from collections.abc import Sequence
7
7
  from typing import TYPE_CHECKING, overload
8
8
 
9
- from kaparoo.filesystem.existence import ensure_dir_exists
9
+ from kaparoo.filesystem.existence import ensure_dir_exists, ensure_file_exists
10
10
  from kaparoo.utils.types import T_co
11
11
 
12
12
  if TYPE_CHECKING:
13
- from typing import Self
13
+ from typing import Any, Self
14
14
 
15
15
  from kaparoo.filesystem.types import StrPath, StrPaths
16
16
 
17
17
 
18
- class DataFolder(Sequence[T_co]):
19
- def __init__(self: Self, path: StrPath) -> None:
20
- self.path = ensure_dir_exists(path)
21
- self.files = self.list_files(self.path)
18
+ class DataSequence(Sequence[T_co]):
19
+ @abstractmethod
20
+ def __init__(self: Self, path: StrPath, *args: Any, **kwargs: Any) -> None:
21
+ raise NotImplementedError
22
22
 
23
+ @abstractmethod
23
24
  def __len__(self: Self) -> int:
24
- return len(self.files)
25
+ raise NotImplementedError
25
26
 
26
27
  @overload
27
28
  def __getitem__(self: Self, index: int, /) -> T_co:
@@ -34,21 +35,36 @@ class DataFolder(Sequence[T_co]):
34
35
  def __getitem__(self: Self, index: int | slice, /) -> T_co | Sequence[T_co]:
35
36
  if isinstance(index, slice):
36
37
  start, stop, step = index.indices(len(self))
37
- return self.parse_files(range(start, stop, step))
38
- return self.parse_file(index)
38
+ return self.by_indices(range(start, stop, step))
39
+ return self.by_index(index)
39
40
 
40
41
  @abstractmethod
41
- def parse_file(self: Self, index: int) -> T_co:
42
+ def by_index(self: Self, index: int) -> T_co:
42
43
  raise NotImplementedError
43
44
 
44
- def parse_files(self: Self, indices: Sequence[int]) -> Sequence[T_co]:
45
- return [self.parse_file(i) for i in indices]
45
+ def by_indices(self: Self, indices: Sequence[int]) -> Sequence[T_co]:
46
+ return [self.by_index(index) for index in indices]
47
+
48
+
49
+ class DataFilesFolder(DataSequence[T_co]):
50
+ def __init__(self: Self, path: StrPath, *args: Any, **kwargs: Any) -> None:
51
+ self.path = ensure_dir_exists(path)
52
+ self.files = self.list_files(*args, **kwargs)
53
+
54
+ def __len__(self: Self) -> int:
55
+ return len(self.files)
46
56
 
47
57
  @classmethod
48
58
  @abstractmethod
49
- def list_files(cls: type[Self], path: StrPath) -> StrPaths:
59
+ def list_files(cls: type[Self], *args: Any, **kwargs: Any) -> StrPaths:
50
60
  raise NotImplementedError
51
61
 
52
- def refresh(self: Self) -> None:
53
- """Refresh the list of files."""
54
- self.files = self.list_files(self.path)
62
+
63
+ class UnifiedDataFile(DataSequence[T_co]):
64
+ def __init__(self: Self, path: StrPath, *args: Any, **kwargs: Any) -> None:
65
+ self.path = ensure_file_exists(path)
66
+
67
+
68
+ class UnifiedDataFolder(DataFilesFolder[T_co]):
69
+ def __init__(self: Self, path: StrPath, *args: Any, **kwargs: Any) -> None:
70
+ self.path = ensure_dir_exists(path)
@@ -213,18 +213,12 @@ def get_paths(
213
213
 
214
214
  paths = list(root.rglob(pattern) if recursive else root.glob(pattern))
215
215
 
216
- if root in paths:
217
- paths.remove(root)
218
-
219
- if not excludes:
220
- excludes = []
221
-
222
- for exclude in excludes:
223
- path_exclude = Path(exclude)
224
- if not path_exclude.is_relative_to(root):
225
- path_exclude = root / path_exclude
226
- if path_exclude in paths:
227
- paths.remove(path_exclude)
216
+ excludes_set = {root}
217
+ if excludes:
218
+ resolve = lambda p: p if p.is_relative_to(root) else root / p # noqa: E731
219
+ excludes_set.update(resolve(Path(e)) for e in excludes)
220
+
221
+ paths = [p for p in paths if p not in excludes_set]
228
222
 
229
223
  if callable(condition):
230
224
  paths = [p for p in paths if condition(p)]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kaparoo-python
3
- Version: 0.1.6
3
+ Version: 0.1.8
4
4
  Summary: Personally common and useful Python features
5
5
  Project-URL: GitHub, https://www.github.com/kaparoo/kaparoo-python
6
6
  Author-email: Jaewoo Park <kaparoo2001@gmail.com>
@@ -37,11 +37,11 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
37
37
  Classifier: Typing :: Typed
38
38
  Requires-Python: >=3.11
39
39
  Provides-Extra: dev
40
- Requires-Dist: hatch>=1.9.1; extra == 'dev'
40
+ Requires-Dist: hatch>=1.9.3; extra == 'dev'
41
41
  Requires-Dist: mypy>=1.8.0; extra == 'dev'
42
42
  Requires-Dist: pytest-order>=1.2.0; extra == 'dev'
43
- Requires-Dist: pytest>=7.4.4; extra == 'dev'
44
- Requires-Dist: ruff>=0.1.13; extra == 'dev'
43
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
44
+ Requires-Dist: ruff>=0.2.1; extra == 'dev'
45
45
  Description-Content-Type: text/markdown
46
46
 
47
47
  # **kaparoo-python**
@@ -1,9 +1,9 @@
1
- kaparoo/__about__.py,sha256=js_m8PQ2W0sqE2u8EbnwOj4Lf2mj4pZf8gFa9fJIYQQ,23
1
+ kaparoo/__about__.py,sha256=0xngvyws52ELzKEHKt7iPFCbLG7K2r7U7qtbX9gCyQM,23
2
2
  kaparoo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  kaparoo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- kaparoo/filesystem/__init__.py,sha256=wAZKtPz9Djwzx1EVYiKryjVobhywADKpRYiYjJoHKhI,1473
5
- kaparoo/filesystem/collections.py,sha256=THI8uqXxcde9BhLP9aUajo1niLcCv1B0ZNs0BppRXq8,1636
6
- kaparoo/filesystem/directory.py,sha256=QGrJENGXDtkt1cCNDRZHiIdGBbKLv4xhH5S1QdEX4VI,13174
4
+ kaparoo/filesystem/__init__.py,sha256=GYaV82lgd9T52hMtnaC-D4oCR625lEoUW-W0d7R3b_k,1110
5
+ kaparoo/filesystem/collections.py,sha256=SNIg0DcI0sQlDoGV_HtnXCFkQneMQT_Z4AKc7Vy9VLs,2271
6
+ kaparoo/filesystem/directory.py,sha256=ZYYDKebQdCmGLLNKHiHpMJ4bSpn-YLyU412KuS9ThZI,13086
7
7
  kaparoo/filesystem/exceptions.py,sha256=Bb9PnDMja24QfHIE2pKAfSqcdHInukgeTnGciM5xO7o,468
8
8
  kaparoo/filesystem/existence.py,sha256=5_W4yDbd632HpG5kOPxwvQ01D50LNZmjmCis1JIsOxY,12391
9
9
  kaparoo/filesystem/types.py,sha256=rGI8Zbdi-CS8LlFeF0fc60wHob75Gx2KvJ6mctPA2wk,215
@@ -11,7 +11,7 @@ kaparoo/filesystem/utils.py,sha256=a0qYVvRl17sPOVfq_wgjO86-8B4jB8sfj-rsSaQWTO8,4
11
11
  kaparoo/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  kaparoo/utils/optional.py,sha256=Leb_8f5kSxRvBnEDrMfbXshJm1Bdc1lMH26xcqvUiaY,4772
13
13
  kaparoo/utils/types.py,sha256=orqC307c1fCrhdCp4iY011P8yVoXexB2Fnmb29_pWXU,194
14
- kaparoo_python-0.1.6.dist-info/METADATA,sha256=5YfWWCuNqecxbFe5HZyv64nwXYhxcPsNzK4VEkplmjs,3097
15
- kaparoo_python-0.1.6.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
16
- kaparoo_python-0.1.6.dist-info/licenses/LICENSE,sha256=_6aA_CoB_YWkSfqkGFxghm2GIsBRE2rp_g7vhz11DM8,1087
17
- kaparoo_python-0.1.6.dist-info/RECORD,,
14
+ kaparoo_python-0.1.8.dist-info/METADATA,sha256=oih8mN5qg3u1-TokE7oUehSsSrJbNht5olSDTPnjWRg,3096
15
+ kaparoo_python-0.1.8.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
16
+ kaparoo_python-0.1.8.dist-info/licenses/LICENSE,sha256=_6aA_CoB_YWkSfqkGFxghm2GIsBRE2rp_g7vhz11DM8,1087
17
+ kaparoo_python-0.1.8.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.21.0
2
+ Generator: hatchling 1.21.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any