|
10 | 10 | __all__ = ["auto_add_readme", "recursive_add_readmes", "TouchModeEnum"] |
11 | 11 |
|
12 | 12 | from enum import Enum |
13 | | -from functools import wraps |
14 | 13 | from pathlib import Path |
15 | | -from typing import Callable, Iterable, Optional, MutableMapping, Sequence |
| 14 | +from typing import Callable, Iterable, Optional |
16 | 15 |
|
17 | 16 | from sorcery import assigned_names |
| 17 | +from warg.os.filtering import negate, is_python_package |
18 | 18 |
|
19 | 19 |
|
20 | 20 | class TouchModeEnum(Enum): |
@@ -68,41 +68,6 @@ def auto_add_readme( |
68 | 68 | print(f"{readme_name} already exists at {path}") |
69 | 69 |
|
70 | 70 |
|
71 | | -def is_python_module(path: Path) -> bool: |
72 | | - """ |
73 | | - Check if path is a python module |
74 | | - """ |
75 | | - return path.is_file() and path.suffix == ".py" |
76 | | - |
77 | | - |
78 | | -def is_python_package(path: Path) -> bool: |
79 | | - """ |
80 | | - Check if path is a python package |
81 | | - """ |
82 | | - return path.is_dir() and (path / "__init__.py").exists() |
83 | | - |
84 | | - |
85 | | -def negate(f: Callable) -> Callable: |
86 | | - """ |
87 | | - Negate a function return |
88 | | - """ |
89 | | - |
90 | | - @wraps(f) |
91 | | - def wrapper(*args: Sequence, **kwargs: MutableMapping): |
92 | | - """ |
93 | | -
|
94 | | - :param args: |
95 | | - :type args: |
96 | | - :param kwargs: |
97 | | - :type kwargs: |
98 | | - :return: |
99 | | - :rtype: |
100 | | - """ |
101 | | - return not f(*args, **kwargs) |
102 | | - |
103 | | - return wrapper |
104 | | - |
105 | | - |
106 | 71 | def recursive_add_readmes( |
107 | 72 | path: Path, |
108 | 73 | exclusion_filter: Optional[Iterable[Callable]] = (negate(is_python_package),), |
@@ -151,4 +116,4 @@ def recursive_add_readmes( |
151 | 116 |
|
152 | 117 |
|
153 | 118 | if __name__ == "__main__": |
154 | | - recursive_add_readmes("exclude") |
| 119 | + recursive_add_readmes("../exclude") |
0 commit comments