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
@@ -1,129 +0,0 @@
1
- from .imports import *
2
- class abstractEnv:
3
- def __init__(self,key='MY_PASSWORD',file_name=None,path=os.getcwd(),deep_scan=False):
4
- file_name = file_name or '.env'
5
- self.re_initialize(file_name=file_name,key=key,path=path,deep_scan=deep_scan)
6
- def re_initialize(self,key='MY_PASSWORD',file_name='.env',path=os.getcwd(),deep_scan=False):
7
- """
8
- Initializes an AbstractEnv object to manage environment variables.
9
-
10
- Args:
11
- key (str, optional): The key to search for in the .env file. Defaults to 'MY_PASSWORD'.
12
- file_name (str, optional): The name of the .env file. Defaults to '.env'.
13
- path (str, optional): The path where the .env file is located. Defaults to the current working directory.
14
- """
15
-
16
- self.key = key or 'MY_PASSWORD'
17
-
18
- file_name = file_name or '.env'
19
- self.key = key or 'MY_PASSWORD'
20
- self.deep_scan=deep_scan
21
- self.current_folder = os.getcwd()
22
- if path and os.path.isfile(path):
23
- self.file_name = os.path.basename(path)
24
- self.path = os.path.dirname(path)
25
- else:
26
- self.path = path or self.current_folder
27
- self.file_name = file_name or '.env'
28
- self.start_path_env = os.path.join(self.path,self.file_name)
29
- self.home_folder = os.path.expanduser("~")
30
- self.envy_all = os.path.join(self.home_folder,'.envy_all')
31
- self.directories = self.get_directories()
32
- self.env_value = self.find_and_read_env_file(key=self.key,file_name=self.file_name, path=self.path,initialize=False)
33
-
34
- def find_and_read_env_file(self,key:str=None, file_name:str=None, path=None,initialize=True,deep_scan=False):
35
- """
36
- Search for an environment file and read a specific key from it.
37
-
38
- Args:
39
- file_name (str): Name of the .env file to be searched. Defaults to '.env'.
40
- key (str): Key to be retrieved from the .env file. Defaults to 'MY_PASSWORD'.
41
- start_path (str): Directory path to start the search from. If None, search starts from current directory.
42
-
43
- Returns:
44
- str: The value corresponding to the key if found, otherwise None.
45
- """
46
- # Set the default start_path to the current directory if it's None
47
- # Try to find the file in the start_path
48
- key = key or self.key
49
- path = path or self.start_path_env
50
- file_name = file_name or self.file_name
51
- if initialize:
52
- self.re_initialize(key=key,file_name=file_name,path=path)
53
- for directory in self.directories:
54
- if directory and os.path.isdir(directory) and self.file_name:
55
- env_path = os.path.join(directory,self.file_name)
56
- if os.path.isfile(env_path):
57
- value = self.search_for_env_key(key=key,path=env_path)
58
- self.env_path = os.path.join(directory,self.file_name)
59
- if os.path.isfile(self.env_path):
60
- value = self.search_for_env_key(key=key,path=self.env_path,deep_scan=deep_scan)
61
- if value:
62
- return value
63
- def get_directories(self):
64
- """
65
- Retrieves a list of directories to search for the .env file.
66
-
67
- Returns:
68
- list: A list of directories including the specified path, current folder, home folder, and '.envy_all' directory.
69
- """
70
- directories=[]
71
- for directory in [self.path,self.current_folder,self.home_folder,self.envy_all]:
72
- if os.path.isdir(directory) and directory not in directories:
73
- directories.append(directory)
74
- return directories
75
-
76
-
77
- def search_for_env_key(self,key:str=None,path:str=None,deep_scan=False):
78
-
79
- """
80
- Retrieves the value of a specified environment variable from a .env file.
81
-
82
- Args:
83
- key (str, optional): The key to search for in the .env file. Defaults to None.
84
- path (str, optional): The path to the .env file. Defaults to None.
85
- file_name (str, optional): The name of the .env file. Defaults to None.
86
-
87
- Returns:
88
- str: The value of the environment variable if found, otherwise None.
89
- """
90
-
91
- highest = [None,0,0.0]
92
- key = key or self.default_env_key
93
- path = path or self.start_path_env
94
- if path and os.path.isfile(path):
95
- with open(path, "r") as f:
96
- for line in f:
97
- line_key,line_value = split_eq(line)
98
- # If the line contains the key, return the value after stripping extra characters
99
- if line_key == key:
100
- return line_value
101
- if deep_scan:
102
- line_keys = []
103
- key_parts=0
104
- for key_part in key.split('_'):
105
- line_keys.append([])
106
- if key_part in line_key:
107
- line_keys[-1].append(line_key)
108
- key_parts+=len(key_part)
109
- if float(key_parts/len(key))>=0.5 and key_parts >highest[1]:
110
- highest = [line_value,key_parts]
111
- if deep_scan and highest[0] != None:
112
- return line_value
113
- def get_env_value(key:str=None,path:str=os.getcwd(),file_name:str=None):
114
- """
115
- Retrieves the value of the specified environment variable.
116
-
117
- Args:
118
- path (str): The path to the environment file. Defaults to None.
119
- file_name (str): The name of the environment file. Defaults to '.env'.
120
- key (str): The key to search for in the .env file. Defaults to 'MY_PASSWORD'.
121
-
122
- Returns:
123
- str: The value of the environment variable if found, otherwise None.
124
- """
125
- if safe_env_load(path):
126
- return os.getenv(key)
127
- return find_and_read_env_file(file_name=file_name, key=key, path=path_ls)
128
-
129
- AbstractEnv = abstractEnv
@@ -1,33 +0,0 @@
1
- from .imports import *
2
- from .abstractEnv import abstractEnv
3
- def get_env_value(key:str=None,path:str=None,file_name:str=None,deep_scan=False):
4
- abstract_env = abstractEnv(key=key, file_name=file_name, path=path,deep_scan=deep_scan)
5
-
6
- """
7
- Retrieves the value of a specified environment variable from a .env file.
8
-
9
- Args:
10
- key (str, optional): The key to search for in the .env file. Defaults to None.
11
- path (str, optional): The path to the .env file. Defaults to None.
12
- file_name (str, optional): The name of the .env file. Defaults to None.
13
-
14
- Returns:
15
- str: The value of the environment variable if found, otherwise None.
16
- """
17
- return abstract_env.env_value
18
-
19
-
20
- def get_env_path(key:str=None,path:str=None,file_name:str=None,deep_scan=False):
21
- abstract_env = abstractEnv(key=key, file_name=file_name, path=path,deep_scan=deep_scan)
22
- """
23
- Retrieves the value of a specified environment variable from a .env file.
24
-
25
- Args:
26
- key (str, optional): The key to search for in the .env file. Defaults to None.
27
- path (str, optional): The path to the .env file. Defaults to None.
28
- file_name (str, optional): The name of the .env file. Defaults to None.
29
-
30
- Returns:
31
- str: The value of the environment variable if found, otherwise None.
32
- """
33
- return abstract_env.env_path
@@ -1,2 +0,0 @@
1
- from .imports import *
2
- from .utils import *
@@ -1,8 +0,0 @@
1
- import os
2
- from dotenv import load_dotenv
3
- from ...string_clean import eatAll,eatInner,eatOuter,safe_split
4
- from ...compare_utils import line_contains
5
- from ...type_utils import is_list,is_bool
6
- from ...path_utils import get_slash,path_join,if_not_last_child_join,get_home_folder,simple_path_join,is_file
7
- DEFAULT_FILE_NAME = '.env'
8
- DEFAULT_KEY = 'MY_PASSWORD'
@@ -1,122 +0,0 @@
1
- from .imports import *
2
- def find_and_read_env_file(key:str=DEFAULT_KEY,file_name:str=DEFAULT_FILE_NAME, start_path:str=None):
3
- """
4
- Search for an environment file and read a specific key from it.
5
-
6
- Args:
7
- file_name (str): Name of the .env file to be searched. Defaults to '.env'.
8
- key (str): Key to be retrieved from the .env file. Defaults to 'MY_PASSWORD'.
9
- start_path (str): Directory path to start the search from. If None, search starts from current directory.
10
-
11
- Returns:
12
- str: The value corresponding to the key if found, otherwise None.
13
- """
14
- # Set the default start_path to the current directory if it's None
15
- directories = [start_path, os.getcwd(), get_home_folder(), simple_path_join(get_home_folder(),'.envy_all'),simple_path_join(get_home_folder(),'envy_all')]
16
- if start_path in [None, os.getcwd()]:
17
- directories = directories[1:]
18
-
19
- # Try to find the file in the start_path
20
- for k in range(0,len(directories)):
21
- env_path = check_env_file(path=directories[k],file_name=file_name)
22
- if not is_bool(env_path):
23
- value = search_for_env_key(path=env_path,key=key)
24
- if value != None:
25
- return value
26
-
27
- def search_for_env_key(key:str,path:str):
28
- """
29
- Search for a specific key in a .env file.
30
-
31
- Args:
32
- path (str): The path to the .env file.
33
- key (str): The key to search for in the .env file.
34
-
35
- Returns:
36
- str: The value of the key if found, otherwise None.
37
- """
38
- with open(path, "r") as f:
39
- for line in f:
40
- eq_split = safe_split(line,['=',0])
41
- # If the line contains the key, return the value after stripping extra characters
42
- if line_contains(string=eq_split, compare=key):
43
- return eatAll(line[len(eq_split):],[' ','','=']).strip()
44
-
45
- def check_env_file(path:str,file_name:str=DEFAULT_FILE_NAME):
46
- """
47
- Check if the environment file exists in a specified path.
48
-
49
- Args:
50
- path (str): The path to check for the .env file.
51
- file_name (str): The name of the .env file. Defaults to '.env'.
52
-
53
- Returns:
54
- str: The path of the .env file if it exists, otherwise False.
55
- """
56
- path = if_not_last_child_join(path=path, child=DEFAULT_FILE_NAME)
57
- # Return the path if file exists, otherwise return False
58
- if is_file(path):
59
- return path
60
- return False
61
-
62
- def safe_env_load(path:str=None):
63
- """
64
- Safely load the .env file if it exists at a specified path.
65
-
66
- Args:
67
- path (str): The path to load the .env file from. If None, no operation is performed.
68
-
69
- Returns:
70
- bool: True if the .env file is successfully loaded, otherwise False.
71
- """
72
- if path == None:
73
- return False
74
- if is_file(path):
75
- if str(safe_split(path,[get_slash(),-1]))[0] == '.':
76
- load_dotenv(path)
77
- return True
78
- return False
79
-
80
- def get_env_value(key:str=DEFAULT_KEY,path:str=None,file_name:str=DEFAULT_FILE_NAME):
81
- """
82
- Retrieves the value of the specified environment variable.
83
-
84
- Args:
85
- path (str): The path to the environment file. Defaults to None.
86
- file_name (str): The name of the environment file. Defaults to '.env'.
87
- key (str): The key to search for in the .env file. Defaults to 'MY_PASSWORD'.
88
-
89
- Returns:
90
- str: The value of the environment variable if found, otherwise None.
91
- """
92
- if safe_env_load(path):
93
- return os.getenv(key)
94
- return find_and_read_env_file(file_name=file_name, key=key, start_path=os.getcwd())
95
- def split_eq(line):
96
- """
97
- Splits a string at the first equals sign '=' and cleans up the key and value.
98
-
99
- Args:
100
- line (str): The string to be split.
101
-
102
- Returns:
103
- list: A list containing the cleaned key and value. If '=' is not found, returns [line, None].
104
- """
105
- if '=' in line:
106
- key_side = line.split('=')[0]
107
- value_side = line[len(key_side+'='):]
108
- return [eatOuter(key_side,[' ','','\t']),eatAll(value_side,[' ','','\t','\n'])]
109
- return [line,None]
110
- def dotenv_load(path:str=None):
111
- """
112
- Safely load the .env file if it exists at a specified path.
113
-
114
- Args:
115
- path (str): The path to load the .env file from. If None, no operation is performed.
116
-
117
- Returns:
118
- bool: True if the .env file is successfully loaded, otherwise False.
119
- """
120
- if path and os.path.isfile(path) and os.path.basename(path)[0] == '.':
121
- load_dotenv(path)
122
- return True
@@ -1,3 +0,0 @@
1
- from .imports import *
2
- from .file_utils import *
3
- from .req import call_for_all_tabs,get_for_all_tabs
@@ -1,6 +0,0 @@
1
- from .file_filters import *
2
- from .file_utils import *
3
- from .filter_params import *
4
- from .map_utils import *
5
- from .pdf_utils import *
6
- from .file_reader import *
@@ -1,104 +0,0 @@
1
- from .imports import *
2
- from .filter_params import *
3
- from .file_utils import *
4
- ##from abstract_utilities import make_list,get_media_exts, is_media_type
5
-
6
- def collect_filepaths(
7
- directory: List[str],
8
- cfg: ScanConfig=None,
9
- allowed_exts: Optional[Set[str]] = False,
10
- unallowed_exts: Optional[Set[str]] = False,
11
- exclude_types: Optional[Set[str]] = False,
12
- exclude_dirs: Optional[List[str]] = False,
13
- exclude_patterns: Optional[List[str]] = False,
14
- add=False,
15
- allowed: Optional[Callable[[str], bool]] = None,
16
- **kwargs
17
- ) -> List[str]:
18
- cfg = cfg or define_defaults(
19
- allowed_exts=allowed_exts,
20
- unallowed_exts=unallowed_exts,
21
- exclude_types=exclude_types,
22
- exclude_dirs=exclude_dirs,
23
- exclude_patterns=exclude_patterns,
24
- add = add
25
- )
26
- allowed = allowed or make_allowed_predicate(cfg)
27
- directories = make_list(directory)
28
- roots = [r for r in directories if r]
29
-
30
- # your existing helpers (get_dirs, get_globs, etc.) stay the same
31
- original_dirs = get_allowed_dirs(roots, allowed=allowed)
32
- original_globs = get_globs(original_dirs)
33
- files = get_allowed_files(original_globs, allowed=allowed)
34
-
35
- for d in get_filtered_dirs(original_dirs, allowed=allowed):
36
- files += get_filtered_files(d, allowed=allowed, files=files)
37
-
38
- # de-dupe while preserving order
39
- seen, out = set(), []
40
- for f in files:
41
- if f not in seen:
42
- seen.add(f)
43
- out.append(f)
44
- return out
45
-
46
-
47
- def _fast_walk(
48
- root: Path,
49
- exts: Iterable[str],
50
- skip_dirs: Iterable[str] = (),
51
- skip_patterns: Iterable[str] = (),
52
- ) -> List[Path]:
53
- exts = tuple(exts)
54
- skip_dirs = set(sd.lower() for sd in skip_dirs or ())
55
- skip_patterns = tuple(sp.lower() for sp in (skip_patterns or ()))
56
-
57
- out = []
58
- for p in root.rglob("*"):
59
- # skip directories by name hit
60
- if p.is_dir():
61
- name = p.name.lower()
62
- if name in skip_dirs:
63
- # rglob doesn't let us prune mid-iteration cleanly; we just won't collect under it
64
- continue
65
- # nothing to collect for dirs
66
- continue
67
-
68
- # file filters
69
- name = p.name.lower()
70
- if any(fnmatch.fnmatch(name, pat) for pat in skip_patterns):
71
- continue
72
- if p.suffix.lower() in exts:
73
- out.append(p)
74
-
75
- # de-dup and normalize
76
- return sorted({pp.resolve() for pp in out})
77
-
78
-
79
- def enumerate_source_files(
80
- src_root: Path,
81
- cfg: Optional["ScanConfig"] = None,
82
- *,
83
- exts: Optional[Iterable[str]] = None,
84
- fast_skip_dirs: Optional[Iterable[str]] = None,
85
- fast_skip_patterns: Optional[Iterable[str]] = None,
86
- ) -> List[Path]:
87
- """
88
- Unified enumerator:
89
- - If `cfg` is provided: use collect_filepaths(...) with full rules.
90
- - Else: fast walk using rglob over `exts` (defaults to EXTS) with optional light excludes.
91
- """
92
- src_root = Path(src_root)
93
-
94
- if cfg is not None:
95
- files = collect_filepaths([str(src_root)], cfg=cfg)
96
- return sorted({Path(f).resolve() for f in files})
97
-
98
- # Fast mode
99
- return _fast_walk(
100
- src_root,
101
- exts or EXTS,
102
- skip_dirs=fast_skip_dirs or (),
103
- skip_patterns=fast_skip_patterns or (),
104
- )
@@ -1 +0,0 @@
1
- from ..imports import *
@@ -1,29 +0,0 @@
1
- from .imports import MIME_TYPES,make_list,os
2
- from .file_filters import get_globs
3
- def get_file_type(file_path,types=None,default=None):
4
- mime_types = {}
5
- if types:
6
- types = make_list(types)
7
- for typ in types:
8
- mime_types[typ] = MIME_TYPES.get(typ)
9
- else:
10
- mime_types = MIME_TYPES
11
-
12
- if os.path.isfile(file_path):
13
- basename = os.path.basename(file_path)
14
- filename,ext = os.path.splitext(basename)
15
- for file_type,ext_values in mime_types.items():
16
- if ext in ext_values:
17
- return file_type
18
- def get_file_map(directory,types=None,default=None):
19
- if directory and os.path.isfile(directory):
20
- directory = os.path.dirname(directory)
21
- all_types = {}
22
- files = get_globs(directory)
23
- for file in files:
24
- file_type = get_file_type(file,types=types,default=default)
25
- if file_type:
26
- if file_type not in all_types:
27
- all_types[file_type] = []
28
- all_types[file_type].append(file)
29
- return all_types
@@ -1,5 +0,0 @@
1
- from .constants import *
2
- from .imports import *
3
- from .module_imports import *
4
- from .classes import *
5
- from .file_functions import *