kaparoo-python 0.1.6__tar.gz → 0.1.8__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.
@@ -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**
@@ -0,0 +1 @@
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,
@@ -0,0 +1,70 @@
1
+ from __future__ import annotations
2
+
3
+ __all__ = ("DataSequence", "DataFilesFolder", "UnifiedDataFile", "UnifiedDataFolder")
4
+
5
+ from abc import abstractmethod
6
+ from collections.abc import Sequence
7
+ from typing import TYPE_CHECKING, overload
8
+
9
+ from kaparoo.filesystem.existence import ensure_dir_exists, ensure_file_exists
10
+ from kaparoo.utils.types import T_co
11
+
12
+ if TYPE_CHECKING:
13
+ from typing import Any, Self
14
+
15
+ from kaparoo.filesystem.types import StrPath, StrPaths
16
+
17
+
18
+ class DataSequence(Sequence[T_co]):
19
+ @abstractmethod
20
+ def __init__(self: Self, path: StrPath, *args: Any, **kwargs: Any) -> None:
21
+ raise NotImplementedError
22
+
23
+ @abstractmethod
24
+ def __len__(self: Self) -> int:
25
+ raise NotImplementedError
26
+
27
+ @overload
28
+ def __getitem__(self: Self, index: int, /) -> T_co:
29
+ pass
30
+
31
+ @overload
32
+ def __getitem__(self: Self, index: slice, /) -> Sequence[T_co]:
33
+ pass
34
+
35
+ def __getitem__(self: Self, index: int | slice, /) -> T_co | Sequence[T_co]:
36
+ if isinstance(index, slice):
37
+ start, stop, step = index.indices(len(self))
38
+ return self.by_indices(range(start, stop, step))
39
+ return self.by_index(index)
40
+
41
+ @abstractmethod
42
+ def by_index(self: Self, index: int) -> T_co:
43
+ raise NotImplementedError
44
+
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)
56
+
57
+ @classmethod
58
+ @abstractmethod
59
+ def list_files(cls: type[Self], *args: Any, **kwargs: Any) -> StrPaths:
60
+ raise NotImplementedError
61
+
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)]
@@ -34,10 +34,10 @@ classifiers = [
34
34
 
35
35
  [project.optional-dependencies]
36
36
  dev = [
37
- "hatch>=1.9.1",
38
- "ruff>=0.1.13",
37
+ "hatch>=1.9.3",
38
+ "ruff>=0.2.1",
39
39
  "mypy>=1.8.0",
40
- "pytest>=7.4.4",
40
+ "pytest>=8.0.0",
41
41
  "pytest-order>=1.2.0",
42
42
  ]
43
43
 
@@ -1 +0,0 @@
1
- __version__ = "0.1.6"
@@ -1,54 +0,0 @@
1
- from __future__ import annotations
2
-
3
- __all__ = ("DataFolder",)
4
-
5
- from abc import abstractmethod
6
- from collections.abc import Sequence
7
- from typing import TYPE_CHECKING, overload
8
-
9
- from kaparoo.filesystem.existence import ensure_dir_exists
10
- from kaparoo.utils.types import T_co
11
-
12
- if TYPE_CHECKING:
13
- from typing import Self
14
-
15
- from kaparoo.filesystem.types import StrPath, StrPaths
16
-
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)
22
-
23
- def __len__(self: Self) -> int:
24
- return len(self.files)
25
-
26
- @overload
27
- def __getitem__(self: Self, index: int, /) -> T_co:
28
- pass
29
-
30
- @overload
31
- def __getitem__(self: Self, index: slice, /) -> Sequence[T_co]:
32
- pass
33
-
34
- def __getitem__(self: Self, index: int | slice, /) -> T_co | Sequence[T_co]:
35
- if isinstance(index, slice):
36
- start, stop, step = index.indices(len(self))
37
- return self.parse_files(range(start, stop, step))
38
- return self.parse_file(index)
39
-
40
- @abstractmethod
41
- def parse_file(self: Self, index: int) -> T_co:
42
- raise NotImplementedError
43
-
44
- def parse_files(self: Self, indices: Sequence[int]) -> Sequence[T_co]:
45
- return [self.parse_file(i) for i in indices]
46
-
47
- @classmethod
48
- @abstractmethod
49
- def list_files(cls: type[Self], path: StrPath) -> StrPaths:
50
- raise NotImplementedError
51
-
52
- def refresh(self: Self) -> None:
53
- """Refresh the list of files."""
54
- self.files = self.list_files(self.path)
File without changes
File without changes