abstract-utilities 0.2.2.413__py3-none-any.whl → 0.2.2.414__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.

Potentially problematic release.


This version of abstract-utilities might be problematic. Click here for more details.

Files changed (38) hide show
  1. abstract_utilities/__init__.py +12 -9
  2. abstract_utilities/cmd_utils/imports/__init__.py +1 -0
  3. abstract_utilities/cmd_utils/imports/imports.py +10 -0
  4. abstract_utilities/cmd_utils/pexpect_utils.py +310 -0
  5. abstract_utilities/cmd_utils/user_utils.py +1 -1
  6. abstract_utilities/env_utils/__init__.py +3 -0
  7. abstract_utilities/env_utils/abstractEnv.py +129 -0
  8. abstract_utilities/env_utils/envy_it.py +33 -0
  9. abstract_utilities/env_utils/imports/__init__.py +2 -0
  10. abstract_utilities/env_utils/imports/imports.py +8 -0
  11. abstract_utilities/env_utils/imports/utils.py +122 -0
  12. abstract_utilities/{path_utils → file_utils}/__init__.py +0 -3
  13. abstract_utilities/file_utils/file_utils/__init__.py +4 -0
  14. abstract_utilities/file_utils/file_utils/file_filters.py +104 -0
  15. abstract_utilities/file_utils/file_utils/file_utils.py +194 -0
  16. abstract_utilities/file_utils/file_utils/imports.py +1 -0
  17. abstract_utilities/{path_utils → file_utils}/imports/__init__.py +1 -0
  18. abstract_utilities/file_utils/imports/classes.py +125 -0
  19. abstract_utilities/file_utils/imports/imports.py +11 -0
  20. abstract_utilities/{path_utils → file_utils}/imports/module_imports.py +3 -1
  21. abstract_utilities/{path_utils → file_utils}/req.py +2 -5
  22. abstract_utilities/{path_utils/path_utils.py → path_utils.py} +4 -1
  23. abstract_utilities/robust_readers/__init__.py +1 -0
  24. abstract_utilities/robust_readers/imports.py +1 -1
  25. abstract_utilities/ssh_utils/__init__.py +3 -0
  26. abstract_utilities/ssh_utils/classes.py +127 -0
  27. abstract_utilities/ssh_utils/imports.py +11 -0
  28. abstract_utilities/ssh_utils/pexpect_utils.py +315 -0
  29. abstract_utilities/ssh_utils/utils.py +122 -0
  30. {abstract_utilities-0.2.2.413.dist-info → abstract_utilities-0.2.2.414.dist-info}/METADATA +1 -1
  31. {abstract_utilities-0.2.2.413.dist-info → abstract_utilities-0.2.2.414.dist-info}/RECORD +36 -18
  32. abstract_utilities/path_utils/file_filters.py +0 -213
  33. abstract_utilities/path_utils/imports/imports.py +0 -6
  34. /abstract_utilities/{path_utils → file_utils/file_utils}/filter_params.py +0 -0
  35. /abstract_utilities/{path_utils/file_utils.py → file_utils/file_utils/map_utils.py} +0 -0
  36. /abstract_utilities/{path_utils → file_utils}/imports/constants.py +0 -0
  37. {abstract_utilities-0.2.2.413.dist-info → abstract_utilities-0.2.2.414.dist-info}/WHEEL +0 -0
  38. {abstract_utilities-0.2.2.413.dist-info → abstract_utilities-0.2.2.414.dist-info}/top_level.txt +0 -0
@@ -1,213 +0,0 @@
1
- from pathlib import Path
2
- from typing import *
3
- import fnmatch, os, glob
4
- from .filter_params import *
5
- ##from abstract_utilities import make_list,get_media_exts, is_media_type
6
- def get_allowed_predicate(allowed=None):
7
- if allowed != False:
8
- if allowed == True:
9
- allowed = None
10
- allowed = allowed or make_allowed_predicate()
11
- else:
12
- def allowed(*args):
13
- return True
14
- allowed = allowed
15
- return allowed
16
- def get_globs(items,recursive: bool = True,allowed=None):
17
- glob_paths = []
18
- items = [item for item in make_list(items) if item]
19
- for item in items:
20
- pattern = os.path.join(item, "**/*") # include all files recursively\n
21
- nuItems = glob.glob(pattern, recursive=recursive)
22
- if allowed:
23
- nuItems = [nuItem for nuItem in nuItems if nuItem and allowed(nuItem)]
24
- glob_paths += nuItems
25
- return glob_paths
26
- def get_allowed_files(items,allowed=True):
27
- allowed = get_allowed_predicate(allowed=allowed)
28
- return [item for item in items if item and os.path.isfile(item) and allowed(item)]
29
- def get_allowed_dirs(items,allowed=False):
30
- allowed = get_allowed_predicate(allowed=allowed)
31
- return [item for item in items if item and os.path.isdir(item) and allowed(item)]
32
-
33
- def get_filtered_files(items,allowed=None,files = []):
34
- allowed = get_allowed_predicate(allowed=allowed)
35
- glob_paths = get_globs(items)
36
- return [glob_path for glob_path in glob_paths if glob_path and os.path.isfile(glob_path) and glob_path not in files and allowed(glob_path)]
37
- def get_filtered_dirs(items,allowed=None,dirs = []):
38
- allowed = get_allowed_predicate(allowed=allowed)
39
- glob_paths = get_globs(items)
40
- return [glob_path for glob_path in glob_paths if glob_path and os.path.isdir(glob_path) and glob_path not in dirs and allowed(glob_path)]
41
-
42
- def get_all_allowed_files(items,allowed=None):
43
- dirs = get_all_allowed_dirs(items)
44
- files = get_allowed_files(items)
45
- nu_files = []
46
- for directory in dirs:
47
- files += get_filtered_files(directory,allowed=allowed,files=files)
48
- return files
49
- def get_all_allowed_dirs(items,allowed=None):
50
- allowed = get_allowed_predicate(allowed=allowed)
51
- dirs = get_allowed_dirs(items)
52
- nu_dirs=[]
53
- for directory in dirs:
54
- nu_dirs += get_filtered_dirs(directory,allowed=allowed,dirs=nu_dirs)
55
- return nu_dirs
56
- def get_files_and_dirs(
57
- directory: str,
58
- cfg: Optional["ScanConfig"] = None,
59
- allowed_exts: Optional[Set[str]] = False,
60
- unallowed_exts: Optional[Set[str]] = False,
61
- exclude_types: Optional[Set[str]] = False,
62
- exclude_dirs: Optional[List[str]] = False,
63
- exclude_patterns: Optional[List[str]] = False,
64
- add = False,
65
- recursive: bool = True,
66
- include_files: bool = True,
67
- **kwargs
68
- ):
69
- cfg = cfg or define_defaults(
70
- allowed_exts=allowed_exts,
71
- unallowed_exts=unallowed_exts,
72
- exclude_types=exclude_types,
73
- exclude_dirs=exclude_dirs,
74
- exclude_patterns=exclude_patterns,
75
- add=add
76
- )
77
- allowed = make_allowed_predicate(cfg)
78
- items=[]
79
- files =[]
80
- if recursive:
81
- items = get_globs(directory,recursive=recursive,allowed=allowed)
82
- else:
83
- directories = make_list(directory)
84
- for directory in directories:
85
- items +=[os.path.join(directory,item) for item in os.listdir(directory)]
86
- dirs = get_allowed_dirs(items,allowed=allowed)
87
- if include_files:
88
- files = get_allowed_files(items,allowed=allowed)
89
- return dirs,files
90
- def make_allowed_predicate(cfg: ScanConfig) -> Callable[[str], bool]:
91
- def allowed(path: str) -> bool:
92
- p = Path(path)
93
- name = p.name.lower()
94
- path_str = str(p).lower()
95
- # A) directories
96
- if cfg.exclude_dirs:
97
- for dpat in cfg.exclude_dirs:
98
- if dpat in path_str or fnmatch.fnmatch(name, dpat.lower()):
99
- if p.is_dir() or dpat in path_str:
100
- return False
101
-
102
- if cfg.exclude_patterns:
103
- # B) filename patterns
104
- for pat in cfg.exclude_patterns:
105
- if fnmatch.fnmatch(name, pat.lower()):
106
- return False
107
-
108
- # C) extension gates
109
- if p.is_file():
110
- ext = p.suffix.lower()
111
- if (cfg.allowed_exts and ext not in cfg.allowed_exts) or (cfg.unallowed_exts and ext in cfg.unallowed_exts):
112
- return False
113
- return True
114
- return allowed
115
- def collect_filepaths(
116
- directory: List[str],
117
- cfg: ScanConfig=None,
118
- allowed_exts: Optional[Set[str]] = False,
119
- unallowed_exts: Optional[Set[str]] = False,
120
- exclude_types: Optional[Set[str]] = False,
121
- exclude_dirs: Optional[List[str]] = False,
122
- exclude_patterns: Optional[List[str]] = False,
123
- add=False,
124
- allowed: Optional[Callable[[str], bool]] = None,
125
- **kwargs
126
- ) -> List[str]:
127
- cfg = cfg or define_defaults(
128
- allowed_exts=allowed_exts,
129
- unallowed_exts=unallowed_exts,
130
- exclude_types=exclude_types,
131
- exclude_dirs=exclude_dirs,
132
- exclude_patterns=exclude_patterns,
133
- add = add
134
- )
135
- allowed = allowed or make_allowed_predicate(cfg)
136
- directories = make_list(directory)
137
- roots = [r for r in directories if r]
138
-
139
- # your existing helpers (get_dirs, get_globs, etc.) stay the same
140
- original_dirs = get_allowed_dirs(roots, allowed=allowed)
141
- original_globs = get_globs(original_dirs)
142
- files = get_allowed_files(original_globs, allowed=allowed)
143
-
144
- for d in get_filtered_dirs(original_dirs, allowed=allowed):
145
- files += get_filtered_files(d, allowed=allowed, files=files)
146
-
147
- # de-dupe while preserving order
148
- seen, out = set(), []
149
- for f in files:
150
- if f not in seen:
151
- seen.add(f)
152
- out.append(f)
153
- return out
154
-
155
-
156
- def _fast_walk(
157
- root: Path,
158
- exts: Iterable[str],
159
- skip_dirs: Iterable[str] = (),
160
- skip_patterns: Iterable[str] = (),
161
- ) -> List[Path]:
162
- exts = tuple(exts)
163
- skip_dirs = set(sd.lower() for sd in skip_dirs or ())
164
- skip_patterns = tuple(sp.lower() for sp in (skip_patterns or ()))
165
-
166
- out = []
167
- for p in root.rglob("*"):
168
- # skip directories by name hit
169
- if p.is_dir():
170
- name = p.name.lower()
171
- if name in skip_dirs:
172
- # rglob doesn't let us prune mid-iteration cleanly; we just won't collect under it
173
- continue
174
- # nothing to collect for dirs
175
- continue
176
-
177
- # file filters
178
- name = p.name.lower()
179
- if any(fnmatch.fnmatch(name, pat) for pat in skip_patterns):
180
- continue
181
- if p.suffix.lower() in exts:
182
- out.append(p)
183
-
184
- # de-dup and normalize
185
- return sorted({pp.resolve() for pp in out})
186
-
187
-
188
- def enumerate_source_files(
189
- src_root: Path,
190
- cfg: Optional["ScanConfig"] = None,
191
- *,
192
- exts: Optional[Iterable[str]] = None,
193
- fast_skip_dirs: Optional[Iterable[str]] = None,
194
- fast_skip_patterns: Optional[Iterable[str]] = None,
195
- ) -> List[Path]:
196
- """
197
- Unified enumerator:
198
- - If `cfg` is provided: use collect_filepaths(...) with full rules.
199
- - Else: fast walk using rglob over `exts` (defaults to EXTS) with optional light excludes.
200
- """
201
- src_root = Path(src_root)
202
-
203
- if cfg is not None:
204
- files = collect_filepaths([str(src_root)], cfg=cfg)
205
- return sorted({Path(f).resolve() for f in files})
206
-
207
- # Fast mode
208
- return _fast_walk(
209
- src_root,
210
- exts or EXTS,
211
- skip_dirs=fast_skip_dirs or (),
212
- skip_patterns=fast_skip_patterns or (),
213
- )
@@ -1,6 +0,0 @@
1
- from pathlib import Path
2
- from typing import *
3
- from dataclasses import dataclass, field
4
- import fnmatch, glob, os, platform, textwrap, pkgutil, re, textwrap, sys, types, importlib, importlib.util, inspect
5
- from types import ModuleType
6
-