abstract-utilities 0.2.2.448__py3-none-any.whl → 0.2.2.449__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 (57) hide show
  1. abstract_utilities/__init__.py +43 -17
  2. abstract_utilities/abstract_classes.py +0 -49
  3. abstract_utilities/class_utils.py +3 -39
  4. abstract_utilities/cmd_utils/user_utils.py +1 -1
  5. abstract_utilities/{compare_utils/compare_utils.py → compare_utils.py} +1 -1
  6. abstract_utilities/dynimport.py +15 -7
  7. abstract_utilities/json_utils.py +0 -35
  8. abstract_utilities/log_utils.py +3 -14
  9. abstract_utilities/path_utils.py +6 -90
  10. abstract_utilities/read_write_utils.py +156 -99
  11. abstract_utilities/robust_reader/__init__.py +1 -1
  12. abstract_utilities/{file_utils/file_utils → robust_reader}/file_reader.py +19 -5
  13. abstract_utilities/{file_utils/file_utils → robust_reader}/pdf_utils.py +9 -1
  14. abstract_utilities/robust_readers/__init__.py +1 -0
  15. abstract_utilities/{file_utils/file_utils/file_utils.py → robust_readers/file_filters.py} +1 -2
  16. abstract_utilities/{file_utils/file_utils → robust_readers}/filter_params.py +38 -1
  17. abstract_utilities/robust_readers/initFuncGen.py +74 -82
  18. abstract_utilities/type_utils.py +1 -0
  19. {abstract_utilities-0.2.2.448.dist-info → abstract_utilities-0.2.2.449.dist-info}/METADATA +4 -15
  20. abstract_utilities-0.2.2.449.dist-info/RECORD +49 -0
  21. {abstract_utilities-0.2.2.448.dist-info → abstract_utilities-0.2.2.449.dist-info}/WHEEL +1 -1
  22. abstract_utilities/cmd_utils/imports/__init__.py +0 -1
  23. abstract_utilities/cmd_utils/imports/imports.py +0 -10
  24. abstract_utilities/cmd_utils/pexpect_utils.py +0 -310
  25. abstract_utilities/compare_utils/__init__.py +0 -3
  26. abstract_utilities/compare_utils/best_match.py +0 -150
  27. abstract_utilities/compare_utils/find_value.py +0 -105
  28. abstract_utilities/env_utils/__init__.py +0 -3
  29. abstract_utilities/env_utils/abstractEnv.py +0 -129
  30. abstract_utilities/env_utils/envy_it.py +0 -33
  31. abstract_utilities/env_utils/imports/__init__.py +0 -2
  32. abstract_utilities/env_utils/imports/imports.py +0 -8
  33. abstract_utilities/env_utils/imports/utils.py +0 -122
  34. abstract_utilities/file_utils/__init__.py +0 -3
  35. abstract_utilities/file_utils/file_utils/__init__.py +0 -6
  36. abstract_utilities/file_utils/file_utils/file_filters.py +0 -104
  37. abstract_utilities/file_utils/file_utils/imports.py +0 -1
  38. abstract_utilities/file_utils/file_utils/map_utils.py +0 -29
  39. abstract_utilities/file_utils/imports/__init__.py +0 -5
  40. abstract_utilities/file_utils/imports/classes.py +0 -381
  41. abstract_utilities/file_utils/imports/constants.py +0 -39
  42. abstract_utilities/file_utils/imports/file_functions.py +0 -10
  43. abstract_utilities/file_utils/imports/imports.py +0 -14
  44. abstract_utilities/file_utils/imports/module_imports.py +0 -9
  45. abstract_utilities/file_utils/req.py +0 -329
  46. abstract_utilities/robust_reader/imports/__init__.py +0 -1
  47. abstract_utilities/robust_reader/imports/imports.py +0 -12
  48. abstract_utilities/robust_readers/imports.py +0 -8
  49. abstract_utilities/safe_utils.py +0 -133
  50. abstract_utilities/ssh_utils/__init__.py +0 -3
  51. abstract_utilities/ssh_utils/classes.py +0 -127
  52. abstract_utilities/ssh_utils/imports.py +0 -10
  53. abstract_utilities/ssh_utils/pexpect_utils.py +0 -315
  54. abstract_utilities/ssh_utils/utils.py +0 -188
  55. abstract_utilities/string_utils.py +0 -12
  56. abstract_utilities-0.2.2.448.dist-info/RECORD +0 -83
  57. {abstract_utilities-0.2.2.448.dist-info → abstract_utilities-0.2.2.449.dist-info}/top_level.txt +0 -0
@@ -3,9 +3,8 @@ from datetime import timedelta
3
3
  from datetime import datetime
4
4
  from typing import *
5
5
  from .hash_utils import *
6
- ##from .dynimport import get_abstract_import,import_symbols_to_parent,call_for_all_tabs
7
- from .robust_readers import *
8
- from .dynimport import get_abstract_import
6
+ from .dynimport import get_abstract_import,import_symbols_to_parent,call_for_all_tabs
7
+
9
8
  from .json_utils import (unified_json_loader,
10
9
  find_keys,
11
10
  get_key_values_from_path,
@@ -41,8 +40,42 @@ from .json_utils import (unified_json_loader,
41
40
  )
42
41
  from .read_write_utils import (read_from_file,
43
42
  write_to_file)
44
- from .path_utils import *
45
- from .file_utils import *
43
+ from .path_utils import (get_file_create_time,
44
+ get_files,
45
+ get_folders,
46
+ path_join,
47
+ mkdirs,
48
+ split_text,
49
+ get_all_item_paths,
50
+ get_directory_items,
51
+ get_files,
52
+ get_folders,
53
+ break_down_find_existing,
54
+ get_directory_items,
55
+ get_directory_files,
56
+ get_all_item_paths,
57
+ get_all_file_paths,
58
+ get_directory,
59
+ create_directory,
60
+ initialize_file,
61
+ join_path,
62
+ is_last_itter,
63
+ path_join,
64
+ is_file,
65
+ is_dir,
66
+ is_path,
67
+ get_all_directories,
68
+ get_all_files,
69
+ get_all_items,
70
+ collate_text_docs,
71
+ get_dirlist,
72
+ get_content,
73
+ is_directory_in_paths,
74
+ make_dirs,
75
+ remove_directory,
76
+ remove_path,
77
+ get_file_parts
78
+ )
46
79
  from .list_utils import (get_highest_value_obj,
47
80
  make_list,
48
81
  safe_list_return,
@@ -87,8 +120,7 @@ from .type_utils import (make_bool,
87
120
  get_numbers,
88
121
  get_numbers_comp,
89
122
  is_any_instance,
90
- break_string,
91
- MIME_TYPES
123
+ break_string
92
124
  )
93
125
  get_media_types = get_all_types = get_all_file_types
94
126
  from .math_utils import (convert_to_percentage,
@@ -100,10 +132,7 @@ from .math_utils import (convert_to_percentage,
100
132
  return_0)
101
133
  from .compare_utils import (create_new_name,
102
134
  get_last_comp_list,
103
- get_closest_match_from_list,
104
- get_first_match,
105
- get_all_match,
106
- best_match)
135
+ get_closest_match_from_list)
107
136
  from .thread_utils import ThreadManager
108
137
  from .history_utils import HistoryManager
109
138
  from .abstract_classes import *
@@ -117,9 +146,6 @@ from .parse_utils import (num_tokens_from_string,
117
146
  from .log_utils import get_caller_info,get_logFile,print_or_log,get_json_call_response,initialize_call_log
118
147
  from .error_utils import try_func
119
148
  from .class_utils import alias,get_class_inputs,get_set_attr
120
- from .ssh_utils import *
121
- from .env_utils import *
122
- from .path_utils import *
123
- from .file_utils import *
124
- from .file_utils import call_for_all_tabs
125
- from .string_utils import *
149
+ from .robust_reader import *
150
+ from .robust_readers import *
151
+
@@ -1,4 +1,3 @@
1
- import inspect
2
1
  class SingletonMeta(type):
3
2
  _instances = {}
4
3
  def __call__(cls, *args, **kwargs):
@@ -23,51 +22,3 @@ def get_inputs(cls, *args, **kwargs):
23
22
  values[field] = getattr(cls(), field) # default from dataclass
24
23
 
25
24
  return cls(**values)
26
-
27
-
28
- def prune_inputs(func, *args, **kwargs):
29
- """
30
- Adapt the provided args/kwargs to fit the signature of func.
31
- Returns (args, kwargs) suitable for calling func.
32
- """
33
- sig = inspect.signature(func)
34
- params = sig.parameters
35
-
36
- # Handle positional arguments
37
- new_args = []
38
- args_iter = iter(args)
39
- for name, param in params.items():
40
- if param.kind in (inspect.Parameter.POSITIONAL_ONLY,
41
- inspect.Parameter.POSITIONAL_OR_KEYWORD):
42
- try:
43
- new_args.append(next(args_iter))
44
- except StopIteration:
45
- break
46
- elif param.kind == inspect.Parameter.VAR_POSITIONAL:
47
- # collect all remaining args
48
- new_args.extend(args_iter)
49
- break
50
- else:
51
- break
52
-
53
- # Handle keyword arguments
54
- new_kwargs = {}
55
- for name, param in params.items():
56
- if name in kwargs:
57
- new_kwargs[name] = kwargs[name]
58
- elif param.default is inspect.Parameter.empty and param.kind == inspect.Parameter.KEYWORD_ONLY:
59
- # Required keyword not provided
60
- raise TypeError(f"Missing required keyword argument: {name}")
61
-
62
- # Only include keywords func accepts
63
- accepted_names = {
64
- name for name, p in params.items()
65
- if p.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD,
66
- inspect.Parameter.KEYWORD_ONLY)
67
- }
68
- new_kwargs = {k: v for k, v in new_kwargs.items() if k in accepted_names}
69
-
70
- return tuple(new_args), new_kwargs
71
- def run_pruned_func(func, *args, **kwargs):
72
- args,kwargs = prune_inputs(func, *args, **kwargs)
73
- return func(*args, **kwargs)
@@ -44,9 +44,9 @@ Dependencies:
44
44
  Each function is furnished with its own docstring that elaborates on its purpose, expected inputs, and outputs.
45
45
 
46
46
  """
47
- import os,json,functools,inspect
48
- from typing import *
49
-
47
+ import inspect
48
+ import json
49
+ import functools
50
50
  def get_type_list() -> list:
51
51
  """Get a list of common Python types."""
52
52
  return ['None','str','int','float','bool','list','tuple','set','dict','frozenset','bytearray','bytes','memoryview','range','enumerate','zip','filter','map','property','slice','super','type','Exception','object']
@@ -370,39 +370,3 @@ def get_class_inputs(cls, *args, **kwargs):
370
370
  else:
371
371
  values[field] = getattr(cls(), field)
372
372
  return cls(**values)
373
- def get_caller(i: Optional[int] = None) -> str:
374
- """
375
- Return the filename of the calling frame.
376
-
377
- Args:
378
- i: Optional stack depth offset.
379
- None = immediate caller (depth 1).
380
-
381
- Returns:
382
- Absolute path of the file for the stack frame.
383
- """
384
- depth = 1 if i is None else int(i)
385
- stack = inspect.stack()
386
- if depth >= len(stack):
387
- depth = len(stack) - 1
388
- return stack[depth].filename
389
-
390
-
391
- def get_caller_path(i: Optional[int] = None) -> str:
392
- """
393
- Return the absolute path of the caller's file.
394
- """
395
- depth = 1 if i is None else int(i)
396
- file_path = get_caller(depth + 1)
397
- return os.path.realpath(file_path)
398
-
399
-
400
- def get_caller_dir(i: Optional[int] = None) -> str:
401
- """
402
- Return the absolute directory of the caller's file.
403
- """
404
- depth = 1 if i is None else int(i)
405
- abspath = get_caller_path(depth + 1)
406
- return os.path.dirname(abspath)
407
-
408
-
@@ -1,4 +1,4 @@
1
-
1
+ from ..string_clean import eatOuter
2
2
  def get_user_input(text,default='y'):
3
3
  choices = '(y/n)' if default in ['y','n'] else ''
4
4
  response = input(f"{text} {choices}:({default}) ") or default
@@ -9,7 +9,7 @@ Date: 05/31/2023
9
9
  Version: 0.1.2
10
10
  """
11
11
  import string
12
- from ..type_utils import is_number,make_list
12
+ from .type_utils import is_number,make_list
13
13
  def get_comp(string:str, string_2:str):
14
14
  """
15
15
  Calculates the similarity between two strings.
@@ -1,12 +1,12 @@
1
1
  # abstract_utilities/dynimport.py
2
2
  from __future__ import annotations
3
+ import importlib, sys, os
3
4
  from functools import lru_cache
4
- from typing import *
5
- import importlib, sys, os, sys,inspect
6
- from typing import Optional
5
+ from typing import Any, Callable, Iterable, Optional
6
+ import inspect, sys
7
7
  from importlib import import_module
8
8
  from .type_utils import make_list
9
-
9
+ from .robust_readers import get_for_all_tabs,call_for_all_tabs
10
10
  class _LazyAttr:
11
11
  """Lazy resolver proxy to avoid import-time cycles.
12
12
  First use triggers actual import & attribute lookup.
@@ -181,6 +181,14 @@ def get_many_module_imports(*args):
181
181
  all_modules[symbol] = get_abstract_import(module = module,symbol=symbol)
182
182
  import_symbols(all_modules)
183
183
  return all_modules
184
-
185
-
186
-
184
+ def get_caller_path():
185
+ frame = inspect.stack()[1]
186
+ return os.path.abspath(frame.filename)
187
+ def get_caller_dir():
188
+ frame = inspect.stack()[1]
189
+ abspath = os.path.abspath(frame.filename)
190
+ return os.path.dirname(abspath)
191
+ def call_for_all_tabs():
192
+
193
+ root = get_caller_dir()
194
+ get_for_all_tabs(root)
@@ -188,41 +188,6 @@ def find_keys(data, target_keys):
188
188
  values = []
189
189
  _find_keys_recursive(data, target_keys, values)
190
190
  return values
191
- def try_json_dumps_spec(obj, logger=True, level='error', file_path=None, **kwargs):
192
- """
193
- Attempts to serialize an object to JSON using json.dumps or json.dump.
194
-
195
- Args:
196
- obj: The Python object to serialize (e.g., dict, list, str, int, etc.).
197
- logger: Logger object or None to use _default_logger.
198
- level: Logging level for errors (default: 'error').
199
- file_path: If provided, writes JSON to this file using json.dump.
200
- **kwargs: Additional arguments to pass to json.dumps or json.dump (e.g., indent, sort_keys).
201
-
202
- Returns:
203
- str: The JSON-serialized string if file_path is None and serialization succeeds.
204
- None: If serialization fails or file_path is provided (in which case it writes to the file).
205
-
206
- Raises:
207
- ValueError: If file_path is provided but the file cannot be written.
208
- """
209
-
210
- try:
211
- if file_path:
212
- # Use json.dump to write to a file
213
- with open(file_path, 'w', encoding='utf-8') as f:
214
- json.dump(obj, f, **kwargs)
215
- return None
216
- else:
217
- # Use json.dumps to return a string
218
- return json.dumps(obj)
219
- except (TypeError, OverflowError, ValueError) as e:
220
- if log_callable:
221
- print_or_log(f"Exception in json.dumps/dump: {e}")
222
- return None
223
- def run_it(endpoint,**kwargs):
224
- response= make_request_link('typicaly',endpoint,data=kwargs)
225
- return response
226
191
  def get_logNone(e):
227
192
  logger(f"{e}")
228
193
  return None
@@ -5,17 +5,6 @@ from flask import jsonify
5
5
  from .path_utils import mkdirs
6
6
  from logging.handlers import RotatingFileHandler
7
7
  from .abstract_classes import SingletonMeta
8
- from pathlib import Path
9
-
10
- def _normalize(obj):
11
- """Recursively turn PosixPath into str, sets into list, etc."""
12
- if isinstance(obj, Path):
13
- return str(obj)
14
- if isinstance(obj, dict):
15
- return {k: _normalize(v) for k, v in obj.items()}
16
- if isinstance(obj, (list, tuple, set)):
17
- return [_normalize(x) for x in obj]
18
- return obj
19
8
 
20
9
 
21
10
  # from abstract_utilities import get_logFile # Potential conflict - consider removing or renaming
@@ -229,11 +218,11 @@ def initialize_call_log(value=None,
229
218
 
230
219
  print_or_log(full_message,level=log_level)
231
220
 
232
- def get_json_call_response(value=None, status_code=None, data=None, logMsg=None, callLog=False):
221
+ def get_json_call_response(value, status_code, data=None,logMsg=None,callLog = False):
233
222
  response_body = {}
234
223
  if status_code == 200:
235
224
  response_body["success"] = True
236
- response_body["result"] = _normalize(value)
225
+ response_body["result"] = value
237
226
  logMsg = logMsg or "success"
238
227
  if callLog:
239
228
  initialize_call_log(value=value,
@@ -242,7 +231,7 @@ def get_json_call_response(value=None, status_code=None, data=None, logMsg=None,
242
231
  log_level='info')
243
232
  else:
244
233
  response_body["success"] = False
245
- response_body["error"] = _normalize(value)
234
+ response_body["error"] = value
246
235
  logMsg = logMsg or f"ERROR: {logMsg}"
247
236
  initialize_call_log(value=value,
248
237
  data=data,
@@ -23,13 +23,8 @@ Date: 05/31/2023
23
23
  Version: 0.1.2
24
24
  """
25
25
  import os
26
- from .read_write_utils import read_from_file,write_to_file
27
- from .string_clean import eatAll
28
- from .list_utils import make_list
29
- from .type_utils import get_media_exts, is_media_type,MIME_TYPES
30
- from .safe_utils import safe_join
31
- from .class_utils import get_caller_path,get_caller_dir
32
-
26
+ import platform
27
+ from .read_write_utils import read_from_file
33
28
  def get_os_info():
34
29
  """
35
30
  Get Operating System Information
@@ -577,87 +572,8 @@ def remove_path(path=None):
577
572
  remove_directory(path)
578
573
  else:
579
574
  os.remove(path)
580
- def get_safe_dirname(path=None):
581
- if path:
582
- path_str = str(path)
583
- return os.path.dirname(path_str)
584
- def get_safe_basename(path=None):
585
- if path:
586
- path_str = str(path)
587
- return os.path.basename(path_str)
588
- def get_safe_splitext(path=None,basename=None):
589
- basename = basename or get_safe_basename(path=path)
590
- if basename:
591
- basename_str = str(basename)
592
- filename,ext = os.path.splitext(basename_str)
593
- return filename,ext
594
- def get_safe_filename(path=None,basename=None):
595
- filename,_ = get_safe_splitext(path=path,basename=basename)
596
- return filename
597
- def get_safe_ext(path=None,basename=None):
598
- _,ext = get_safe_splitext(path=path,basename=basename)
599
- return ext
600
- def raw_create_dirs(*paths):
601
- """Recursively create all directories along the given path."""
602
- full_path = os.path.abspath(safe_join(*paths))
603
- sub_parts = [p for p in full_path.split(os.sep) if p]
604
-
605
- current_path = "/" if full_path.startswith(os.sep) else ""
606
- for part in sub_parts:
607
- current_path = safe_join(current_path, part)
608
- os.makedirs(current_path, exist_ok=True)
609
- return full_path
610
-
611
-
612
- def create_dirs(directory, child=None):
613
- """Create directory and optional child path safely."""
614
- full_path = os.path.abspath(safe_join(directory, child))
615
- if not os.path.exists(full_path):
616
- raw_create_dirs(full_path)
617
- return full_path
618
-
619
-
620
- def get_base_dir(directory=None):
621
- """Return given directory or _BASE_DIR fallback."""
622
- return directory or _BASE_DIR
623
-
624
-
625
- def create_base_path(directory=None, child=None):
626
- """Join base dir with child."""
627
- directory = get_base_dir(directory)
628
- return safe_join(directory, child)
629
-
630
-
631
- def create_base_dir(directory=None, child=None):
632
- """Ensure existence of base directory path."""
633
- full_path = create_base_path(directory, child)
634
- if not os.path.exists(full_path):
635
- raw_create_dirs(full_path)
636
- return full_path
637
-
638
-
639
-
640
575
  def get_file_parts(path):
641
-
642
- basename = get_safe_basename(path)
643
- filename, ext = get_safe_splitext(basename=basename)
644
-
645
- dirname = get_safe_dirname(path)
646
- dirbase = get_safe_basename(dirname)
647
-
648
- parent_dirname = get_safe_dirname(dirname)
649
- parent_dirbase = get_safe_basename(parent_dirname)
650
-
651
- super_dirname = get_safe_dirname(parent_dirname)
652
- super_dirbase = get_safe_basename(super_dirname)
653
-
654
- return {"dirname": dirname,
655
- "basename": basename,
656
- "filename": filename,
657
- "ext": ext,
658
- "dirbase":dirbase,
659
- "parent_dirname":parent_dirname,
660
- "parent_dirbase":parent_dirbase,
661
- "super_dirname":super_dirname,
662
- "super_dirbase":super_dirbase
663
- }
576
+ dirName = os.path.dirname(path)
577
+ baseName = os.path.basename(path)
578
+ fileName, ext = os.path.splitext(baseName)
579
+ return {"dirName": dirName, "baseName": baseName, "fileName": fileName, "ext": ext}