abstract-utilities 0.2.2.513__py3-none-any.whl → 0.2.2.627__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.
- abstract_utilities/__init__.py +11 -3
- abstract_utilities/class_utils/caller_utils.py +19 -0
- abstract_utilities/class_utils/global_utils.py +35 -20
- abstract_utilities/class_utils/imports/imports.py +1 -1
- abstract_utilities/directory_utils/__init__.py +2 -4
- abstract_utilities/directory_utils/imports/__init__.py +2 -0
- abstract_utilities/directory_utils/imports/imports.py +1 -0
- abstract_utilities/directory_utils/imports/module_imports.py +2 -0
- abstract_utilities/directory_utils/src/__init__.py +4 -0
- abstract_utilities/directory_utils/src/directory_utils.py +110 -0
- abstract_utilities/directory_utils/src/name_utils.py +43 -0
- abstract_utilities/directory_utils/src/size_utils.py +57 -0
- abstract_utilities/directory_utils/src/utils.py +116 -0
- abstract_utilities/file_utils/imports/constants.py +81 -7
- abstract_utilities/file_utils/imports/imports.py +0 -4
- abstract_utilities/file_utils/imports/module_imports.py +1 -1
- abstract_utilities/file_utils/src/__init__.py +2 -4
- abstract_utilities/file_utils/src/file_filters/__init__.py +4 -0
- abstract_utilities/file_utils/src/file_filters/ensure_utils.py +118 -0
- abstract_utilities/file_utils/src/file_filters/filter_params.py +86 -0
- abstract_utilities/file_utils/src/file_filters/filter_utils.py +78 -0
- abstract_utilities/file_utils/src/file_filters/predicate_utils.py +116 -0
- abstract_utilities/file_utils/src/file_filters.py +114 -47
- abstract_utilities/file_utils/src/file_reader.py +0 -64
- abstract_utilities/file_utils/src/file_utils.py +7 -130
- abstract_utilities/file_utils/src/filter_params.py +128 -86
- abstract_utilities/file_utils/src/find_collect.py +85 -165
- abstract_utilities/file_utils/src/find_content.py +210 -0
- abstract_utilities/file_utils/src/initFunctionsGen.py +35 -28
- abstract_utilities/file_utils/src/initFunctionsGens.py +280 -0
- abstract_utilities/file_utils/src/reader_utils/__init__.py +4 -0
- abstract_utilities/file_utils/src/reader_utils/directory_reader.py +53 -0
- abstract_utilities/file_utils/src/reader_utils/file_reader.py +543 -0
- abstract_utilities/file_utils/src/reader_utils/file_readers.py +376 -0
- abstract_utilities/file_utils/src/reader_utils/imports.py +18 -0
- abstract_utilities/file_utils/src/reader_utils/pdf_utils.py +300 -0
- abstract_utilities/file_utils (2)/__init__.py +2 -0
- abstract_utilities/file_utils (2)/imports/__init__.py +2 -0
- abstract_utilities/file_utils (2)/imports/constants.py +118 -0
- abstract_utilities/file_utils (2)/imports/imports/__init__.py +3 -0
- abstract_utilities/file_utils (2)/imports/imports/constants.py +119 -0
- abstract_utilities/file_utils (2)/imports/imports/imports.py +46 -0
- abstract_utilities/file_utils (2)/imports/imports/module_imports.py +8 -0
- abstract_utilities/file_utils (2)/imports/utils/__init__.py +3 -0
- abstract_utilities/file_utils (2)/imports/utils/classes.py +379 -0
- abstract_utilities/file_utils (2)/imports/utils/clean_imps.py +155 -0
- abstract_utilities/file_utils (2)/imports/utils/filter_utils.py +341 -0
- abstract_utilities/file_utils (2)/src/__init__.py +8 -0
- abstract_utilities/file_utils (2)/src/file_filters.py +155 -0
- abstract_utilities/file_utils (2)/src/file_reader.py +604 -0
- abstract_utilities/file_utils (2)/src/find_collect.py +258 -0
- abstract_utilities/file_utils (2)/src/initFunctionsGen.py +286 -0
- abstract_utilities/file_utils (2)/src/map_utils.py +28 -0
- abstract_utilities/file_utils (2)/src/pdf_utils.py +300 -0
- abstract_utilities/import_utils/circular_import_finder.py +222 -0
- abstract_utilities/import_utils/circular_import_finder2.py +118 -0
- abstract_utilities/import_utils/imports/module_imports.py +3 -1
- abstract_utilities/import_utils/src/clean_imports.py +156 -25
- abstract_utilities/import_utils/src/dot_utils.py +11 -0
- abstract_utilities/import_utils/src/extract_utils.py +4 -0
- abstract_utilities/import_utils/src/import_functions.py +66 -2
- abstract_utilities/import_utils/src/pkg_utils.py +58 -4
- abstract_utilities/import_utils/src/sysroot_utils.py +56 -1
- abstract_utilities/log_utils/log_file.py +73 -24
- abstract_utilities/parse_utils/parse_utils.py +23 -0
- abstract_utilities/path_utils/path_utils.py +25 -23
- abstract_utilities/read_write_utils/imports/imports.py +1 -1
- abstract_utilities/read_write_utils/read_write_utils.py +99 -31
- abstract_utilities/safe_utils/safe_utils.py +30 -0
- {abstract_utilities-0.2.2.513.dist-info → abstract_utilities-0.2.2.627.dist-info}/METADATA +1 -1
- {abstract_utilities-0.2.2.513.dist-info → abstract_utilities-0.2.2.627.dist-info}/RECORD +73 -32
- {abstract_utilities-0.2.2.513.dist-info → abstract_utilities-0.2.2.627.dist-info}/WHEEL +0 -0
- {abstract_utilities-0.2.2.513.dist-info → abstract_utilities-0.2.2.627.dist-info}/top_level.txt +0 -0
|
@@ -52,38 +52,13 @@ def get_all_allowed_dirs(items,allowed=None):
|
|
|
52
52
|
for directory in dirs:
|
|
53
53
|
nu_dirs += get_filtered_dirs(directory,allowed=allowed,dirs=nu_dirs)
|
|
54
54
|
return nu_dirs
|
|
55
|
-
def get_files_and_dirs(
|
|
56
|
-
|
|
57
|
-
cfg: Optional["ScanConfig"] = None,
|
|
58
|
-
allowed_exts: Optional[Set[str]] = False,
|
|
59
|
-
unallowed_exts: Optional[Set[str]] = False,
|
|
60
|
-
allowed_types: Optional[Set[str]] = False,
|
|
61
|
-
exclude_types: Optional[Set[str]] = False,
|
|
62
|
-
allowed_dirs: Optional[List[str]] = False,
|
|
63
|
-
exclude_dirs: Optional[List[str]] = False,
|
|
64
|
-
allowed_patterns: Optional[List[str]] = False,
|
|
65
|
-
exclude_patterns: Optional[List[str]] = False,
|
|
66
|
-
add = False,
|
|
67
|
-
recursive: bool = True,
|
|
68
|
-
include_files: bool = True,
|
|
69
|
-
**kwargs
|
|
70
|
-
):
|
|
71
|
-
cfg = cfg or define_defaults(
|
|
72
|
-
allowed_exts = allowed_exts,
|
|
73
|
-
unallowed_exts = unallowed_exts,
|
|
74
|
-
allowed_types = allowed_types,
|
|
75
|
-
exclude_types = exclude_types,
|
|
76
|
-
allowed_dirs = allowed_dirs,
|
|
77
|
-
exclude_dirs = exclude_dirs,
|
|
78
|
-
allowed_patterns = allowed_patterns,
|
|
79
|
-
exclude_patterns = exclude_patterns,
|
|
80
|
-
add=add
|
|
81
|
-
)
|
|
82
|
-
allowed = make_allowed_predicate(cfg)
|
|
55
|
+
def get_files_and_dirs(*args,**kwargs)-> List[str]:
|
|
56
|
+
directories,cfg,allowed,include_files,recursive = get_file_filters(*args,**kwargs)
|
|
83
57
|
items=[]
|
|
84
58
|
files =[]
|
|
85
59
|
if recursive:
|
|
86
|
-
|
|
60
|
+
for directory in directories:
|
|
61
|
+
items += get_globs(directories,recursive=recursive,allowed=allowed)
|
|
87
62
|
else:
|
|
88
63
|
directories = make_list(directory)
|
|
89
64
|
for directory in directories:
|
|
@@ -92,68 +67,7 @@ def get_files_and_dirs(
|
|
|
92
67
|
if include_files:
|
|
93
68
|
files = get_allowed_files(items,allowed=allowed)
|
|
94
69
|
return dirs,files
|
|
95
|
-
def make_allowed_predicate(cfg: ScanConfig) -> Callable[[str], bool]:
|
|
96
|
-
"""
|
|
97
|
-
Build a predicate that returns True if a given path is considered allowed
|
|
98
|
-
under the given ScanConfig. Applies allowed_* and exclude_* logic symmetrically.
|
|
99
|
-
"""
|
|
100
|
-
def allowed(path: str=None,p=None) -> bool:
|
|
101
|
-
p = p or Path(path)
|
|
102
|
-
name = p.name.lower()
|
|
103
|
-
path_str = str(p).lower()
|
|
104
|
-
|
|
105
|
-
# --------------------
|
|
106
|
-
# A) directory filters
|
|
107
|
-
# --------------------
|
|
108
|
-
if cfg.exclude_dirs:
|
|
109
|
-
for dpat in cfg.exclude_dirs:
|
|
110
|
-
dpat_l = dpat.lower()
|
|
111
|
-
if dpat_l in path_str or fnmatch.fnmatch(name, dpat_l):
|
|
112
|
-
if p.is_dir() or dpat_l in path_str:
|
|
113
|
-
return False
|
|
114
|
-
|
|
115
|
-
if cfg.allowed_dirs and cfg.allowed_dirs != ["*"]:
|
|
116
|
-
# must be in at least one allowed dir
|
|
117
|
-
if not any(
|
|
118
|
-
fnmatch.fnmatch(path_str, f"*{dpat.lower()}*") for dpat in cfg.allowed_dirs
|
|
119
|
-
):
|
|
120
|
-
return False
|
|
121
70
|
|
|
122
|
-
# --------------------
|
|
123
|
-
# B) pattern filters
|
|
124
|
-
# --------------------
|
|
125
|
-
if cfg.allowed_patterns and cfg.allowed_patterns != ["*"]:
|
|
126
|
-
if not any(fnmatch.fnmatch(name, pat.lower()) for pat in cfg.allowed_patterns):
|
|
127
|
-
return False
|
|
128
|
-
|
|
129
|
-
if cfg.exclude_patterns:
|
|
130
|
-
for pat in cfg.exclude_patterns:
|
|
131
|
-
if fnmatch.fnmatch(name, pat.lower()):
|
|
132
|
-
return False
|
|
133
|
-
|
|
134
|
-
# --------------------
|
|
135
|
-
# C) extension filters
|
|
136
|
-
# --------------------
|
|
137
|
-
if p.is_file():
|
|
138
|
-
ext = p.suffix.lower()
|
|
139
|
-
if cfg.allowed_exts and ext not in cfg.allowed_exts:
|
|
140
|
-
return False
|
|
141
|
-
if cfg.unallowed_exts and ext in cfg.unallowed_exts:
|
|
142
|
-
return False
|
|
143
|
-
|
|
144
|
-
# --------------------
|
|
145
|
-
# D) type filters (optional)
|
|
146
|
-
# --------------------
|
|
147
|
-
if cfg.allowed_types and cfg.allowed_types != {"*"}:
|
|
148
|
-
if not any(t in path_str for t in cfg.allowed_types):
|
|
149
|
-
return False
|
|
150
|
-
if cfg.exclude_types and cfg.exclude_types != {"*"}:
|
|
151
|
-
if any(t in path_str for t in cfg.exclude_types):
|
|
152
|
-
return False
|
|
153
|
-
|
|
154
|
-
return True
|
|
155
|
-
|
|
156
|
-
return allowed
|
|
157
71
|
def correct_kwargs(**kwargs):
|
|
158
72
|
for key,values in kwargs.items():
|
|
159
73
|
if key.startswith('excluded'):
|
|
@@ -163,47 +77,10 @@ def correct_kwargs(**kwargs):
|
|
|
163
77
|
kwargs[correct_key]=combine_params(correct_vals,values)
|
|
164
78
|
del kwargs[key]
|
|
165
79
|
|
|
166
|
-
def collect_filepaths(
|
|
167
|
-
|
|
168
|
-
cfg: ScanConfig=None,
|
|
169
|
-
allowed_exts: Optional[Set[str]] = False,
|
|
170
|
-
unallowed_exts: Optional[Set[str]] = False,
|
|
171
|
-
allowed_types: Optional[Set[str]] = False,
|
|
172
|
-
exclude_types: Optional[Set[str]] = False,
|
|
173
|
-
allowed_dirs: Optional[List[str]] = False,
|
|
174
|
-
exclude_dirs: Optional[List[str]] = False,
|
|
175
|
-
allowed_patterns: Optional[List[str]] = False,
|
|
176
|
-
exclude_patterns: Optional[List[str]] = False,
|
|
177
|
-
add=False,
|
|
178
|
-
allowed: Optional[Callable[[str], bool]] = None,
|
|
179
|
-
**kwargs
|
|
180
|
-
) -> List[str]:
|
|
181
|
-
kwargs = correct_kwargs(allowed_exts = allowed_exts,
|
|
182
|
-
unallowed_exts = unallowed_exts,
|
|
183
|
-
allowed_types = allowed_types,
|
|
184
|
-
exclude_types = exclude_types,
|
|
185
|
-
allowed_dirs = allowed_dirs,
|
|
186
|
-
exclude_dirs = exclude_dirs,
|
|
187
|
-
allowed_patterns = allowed_patterns,
|
|
188
|
-
exclude_patterns = exclude_patterns,
|
|
189
|
-
**kwargs)
|
|
190
|
-
cfg = cfg or define_defaults(
|
|
191
|
-
allowed_exts = allowed_exts,
|
|
192
|
-
unallowed_exts = unallowed_exts,
|
|
193
|
-
allowed_types = allowed_types,
|
|
194
|
-
exclude_types = exclude_types,
|
|
195
|
-
allowed_dirs = allowed_dirs,
|
|
196
|
-
exclude_dirs = exclude_dirs,
|
|
197
|
-
allowed_patterns = allowed_patterns,
|
|
198
|
-
exclude_patterns = exclude_patterns,
|
|
199
|
-
add = add
|
|
200
|
-
)
|
|
201
|
-
allowed = allowed or make_allowed_predicate(cfg)
|
|
202
|
-
directories = make_list(directory)
|
|
203
|
-
roots = [r for r in directories if r]
|
|
204
|
-
|
|
80
|
+
def collect_filepaths(*args,**kwargs)-> List[str]:
|
|
81
|
+
directories,cfg,allowed,include_files,recursive = get_file_filters(*args,**kwargs)
|
|
205
82
|
# your existing helpers (get_dirs, get_globs, etc.) stay the same
|
|
206
|
-
original_dirs = get_allowed_dirs(
|
|
83
|
+
original_dirs = get_allowed_dirs(directories, allowed=allowed)
|
|
207
84
|
original_globs = get_globs(original_dirs)
|
|
208
85
|
files = get_allowed_files(original_globs, allowed=allowed)
|
|
209
86
|
|
|
@@ -5,68 +5,78 @@ def combine_params(*values,typ=None):
|
|
|
5
5
|
nu_values = None
|
|
6
6
|
for value in values:
|
|
7
7
|
if value is not None:
|
|
8
|
+
typ = typ or type(value)
|
|
8
9
|
if nu_values is None:
|
|
9
|
-
typ = typ or type(value)
|
|
10
10
|
nu_values = typ()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
|
|
12
|
+
if typ is set:
|
|
13
|
+
nu_values = nu_values | typ(value)
|
|
14
|
+
if typ is list:
|
|
15
|
+
nu_values += typ(value)
|
|
16
16
|
return nu_values
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"image", "video", "audio", "presentation",
|
|
30
|
-
"spreadsheet", "archive", "executable"
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
_unallowed = set(get_media_exts(DEFAULT_EXCLUDE_TYPES)) | {
|
|
34
|
-
".bak", ".shp", ".cpg", ".dbf", ".shx", ".geojson",
|
|
35
|
-
".pyc", ".prj", ".sbn", ".sbx"
|
|
36
|
-
}
|
|
37
|
-
DEFAULT_UNALLOWED_EXTS = {e for e in _unallowed if e not in DEFAULT_ALLOWED_EXTS}
|
|
38
|
-
|
|
39
|
-
DEFAULT_EXCLUDE_DIRS: List[str] = [
|
|
40
|
-
"node_modules", "__pycache__", "backups", "backup",
|
|
41
|
-
"trash", "deprecated", "old", "__init__"
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
DEFAULT_EXCLUDE_PATTERNS: List[str] = [
|
|
45
|
-
"__init__*", "*.tmp", "*.log", "*.lock", "*.zip", "*~"
|
|
46
|
-
]
|
|
47
|
-
|
|
48
|
-
DEFAULT_ALLOWED_PATTERNS: List[str] = ["*"]
|
|
49
|
-
DEFAULT_ALLOWED_DIRS: List[str] = ["*"]
|
|
50
|
-
DEFAULT_ALLOWED_TYPES: List[str] = ["*"]
|
|
51
|
-
|
|
52
|
-
REMOTE_RE = re.compile(r"^(?P<host>[^:\s]+@[^:\s]+):(?P<path>/.*)$")
|
|
53
|
-
AllowedPredicate = Optional[Callable[[str], bool]]
|
|
54
|
-
|
|
55
|
-
# -------------------------
|
|
56
|
-
# Config dataclass
|
|
57
|
-
# -------------------------
|
|
17
|
+
def get_safe_kwargs(canonical_map, **kwargs):
|
|
18
|
+
# Lowercase all keys for safety
|
|
19
|
+
canonical_map = canonical_map or CANONICAL_MAP
|
|
20
|
+
norm_kwargs = {k.lower(): v for k, v in kwargs.items() if v is not None}
|
|
21
|
+
|
|
22
|
+
# Inverse lookup: alias → canonical key
|
|
23
|
+
alias_lookup = {
|
|
24
|
+
alias: canon
|
|
25
|
+
for canon, aliases in canonical_map.items()
|
|
26
|
+
if aliases
|
|
27
|
+
for alias in aliases
|
|
28
|
+
}
|
|
58
29
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
allowed_exts: Set[str]
|
|
62
|
-
unallowed_exts: Set[str]
|
|
63
|
-
allowed_types: Set[str]
|
|
64
|
-
exclude_types: Set[str]
|
|
65
|
-
allowed_dirs: List[str] = field(default_factory=list)
|
|
66
|
-
exclude_dirs: List[str] = field(default_factory=list)
|
|
67
|
-
allowed_patterns: List[str] = field(default_factory=list)
|
|
68
|
-
exclude_patterns: List[str] = field(default_factory=list)
|
|
30
|
+
# Preserve correctly named keys
|
|
31
|
+
safe_kwargs = {k: v for k, v in norm_kwargs.items() if k in canonical_map}
|
|
69
32
|
|
|
33
|
+
for k, v in norm_kwargs.items():
|
|
34
|
+
if k in alias_lookup:
|
|
35
|
+
canonical_key = alias_lookup[k]
|
|
36
|
+
prev = safe_kwargs.get(canonical_key)
|
|
37
|
+
if prev is None:
|
|
38
|
+
safe_kwargs[canonical_key] = v
|
|
39
|
+
else:
|
|
40
|
+
# merge intelligently if both exist
|
|
41
|
+
if isinstance(prev, (set, list)) and isinstance(v, (set, list)):
|
|
42
|
+
safe_kwargs[canonical_key] = list(set(prev) | set(v))
|
|
43
|
+
else:
|
|
44
|
+
safe_kwargs[canonical_key] = v # overwrite for non-iterables
|
|
45
|
+
|
|
46
|
+
# fill defaults if missing
|
|
47
|
+
for canon in canonical_map:
|
|
48
|
+
safe_kwargs.setdefault(canon, None)
|
|
49
|
+
|
|
50
|
+
return safe_kwargs
|
|
51
|
+
|
|
52
|
+
def create_canonical_map(*args,canonical_map=None):
|
|
53
|
+
keys = [arg for arg in args if arg]
|
|
54
|
+
if not keys:
|
|
55
|
+
return CANONICAL_MAP
|
|
56
|
+
canonical_map = canonical_map or CANONICAL_MAP
|
|
57
|
+
|
|
58
|
+
return {key:canonical_map.get(key) for key in keys}
|
|
59
|
+
def get_safe_canonical_kwargs(*args,canonical_map=None,**kwargs):
|
|
60
|
+
canonical_map = canonical_map or create_canonical_map(*args)
|
|
61
|
+
|
|
62
|
+
return get_safe_kwargs(canonical_map=canonical_map,**kwargs)
|
|
63
|
+
def get_dir_filter_kwargs(**kwargs):
|
|
64
|
+
canonical_map = create_canonical_map("directories")
|
|
65
|
+
return get_safe_kwargs(canonical_map=canonical_map,**kwargs)
|
|
66
|
+
def get_file_filter_kwargs(**kwargs):
|
|
67
|
+
"""
|
|
68
|
+
Normalize arbitrary keyword arguments for file scanning configuration.
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
- 'excluded_ext' or 'unallowed_exts' → 'exclude_exts'
|
|
72
|
+
- 'include_dirs' or 'allow_dir' → 'allowed_dirs'
|
|
73
|
+
- 'excludePattern' or 'excluded_patterns' → 'exclude_patterns'
|
|
74
|
+
- 'allowed_type' or 'include_types' → 'allowed_types'
|
|
75
|
+
"""
|
|
76
|
+
# Canonical keys and aliases
|
|
77
|
+
canonical_keys =["allowed_exts","exclude_exts","allowed_types","exclude_types","allowed_dirs","exclude_dirs","allowed_patterns","exclude_patterns"]
|
|
78
|
+
|
|
79
|
+
return get_safe_canonical_kwargs(*canonical_keys,**kwargs)
|
|
70
80
|
# -------------------------
|
|
71
81
|
# Utility functions
|
|
72
82
|
# -------------------------
|
|
@@ -110,10 +120,12 @@ def ensure_patterns(patterns):
|
|
|
110
120
|
|
|
111
121
|
def _get_default_modular(value, default, add=False, typ=set):
|
|
112
122
|
"""Merge user and default values intelligently."""
|
|
113
|
-
if value
|
|
123
|
+
if value == None:
|
|
124
|
+
value = add
|
|
125
|
+
if value in [True]:
|
|
114
126
|
return default
|
|
115
127
|
if value is False:
|
|
116
|
-
return
|
|
128
|
+
return value
|
|
117
129
|
if add:
|
|
118
130
|
return combine_params(value,default,typ=None)
|
|
119
131
|
|
|
@@ -122,33 +134,63 @@ def _get_default_modular(value, default, add=False, typ=set):
|
|
|
122
134
|
# -------------------------
|
|
123
135
|
# Default derivation logic
|
|
124
136
|
# -------------------------
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
137
|
+
def _get_default_modular(value, default, add=None, typ=set):
|
|
138
|
+
"""Merge user and default values intelligently."""
|
|
139
|
+
add = add or False
|
|
140
|
+
if value == None:
|
|
141
|
+
value = add
|
|
142
|
+
if value in [True]:
|
|
143
|
+
return default
|
|
144
|
+
if value is False:
|
|
145
|
+
return value
|
|
146
|
+
if add:
|
|
147
|
+
return combine_params(value,default,typ=None)
|
|
148
|
+
return typ(value)
|
|
149
|
+
def derive_all_defaults(**kwargs):
|
|
150
|
+
kwargs = get_safe_canonical_kwargs(**kwargs)
|
|
151
|
+
add = kwargs.get("add",False)
|
|
152
|
+
nu_defaults = {}
|
|
153
|
+
for key,values in DEFAULT_CANONICAL_MAP.items():
|
|
154
|
+
default = values.get("default")
|
|
155
|
+
typ = values.get("type")
|
|
156
|
+
key_value = kwargs.get(key)
|
|
157
|
+
if key in DEFAULT_ALLOWED_EXCLUDE_MAP:
|
|
158
|
+
|
|
159
|
+
if key.endswith('exts'):
|
|
160
|
+
input_value = ensure_exts(key_value)
|
|
161
|
+
if key.endswith('patterns'):
|
|
162
|
+
input_value = ensure_patterns(key_value)
|
|
163
|
+
else:
|
|
164
|
+
input_value = _normalize_listlike(key_value, typ)
|
|
165
|
+
nu_defaults[key] = _get_default_modular(input_value, default, add, typ)
|
|
166
|
+
else:
|
|
167
|
+
value = default if key_value is None else key_value
|
|
168
|
+
if typ == list:
|
|
169
|
+
value = make_list(value)
|
|
170
|
+
elif typ == bool:
|
|
171
|
+
value = bool(value)
|
|
172
|
+
nu_defaults[key] = value
|
|
173
|
+
|
|
174
|
+
return nu_defaults
|
|
175
|
+
# -------------------------
|
|
176
|
+
# Default derivation logic
|
|
177
|
+
# -------------------------
|
|
178
|
+
def derive_file_defaults(**kwargs):
|
|
179
|
+
kwargs = derive_all_defaults(**kwargs)
|
|
180
|
+
add = kwargs.get("add",False)
|
|
181
|
+
nu_defaults = {}
|
|
182
|
+
for key,values in DEFAULT_ALLOWED_EXCLUDE_MAP.items():
|
|
183
|
+
default = values.get("default")
|
|
184
|
+
typ = values.get("type")
|
|
185
|
+
key_value = kwargs.get(key)
|
|
186
|
+
if key.endswith('exts'):
|
|
187
|
+
input_value = ensure_exts(key_value)
|
|
188
|
+
if key.endswith('patterns'):
|
|
189
|
+
input_value = ensure_patterns(key_value)
|
|
190
|
+
else:
|
|
191
|
+
input_value = _normalize_listlike(key_value, typ)
|
|
192
|
+
nu_defaults[key] = _get_default_modular(input_value, default, add, typ)
|
|
193
|
+
return nu_defaults
|
|
152
194
|
|
|
153
195
|
def define_defaults(**kwargs):
|
|
154
196
|
defaults = derive_file_defaults(**kwargs)
|