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

@@ -5,6 +5,12 @@ from ...list_utils import make_list
5
5
  import os
6
6
  import_tag = 'import '
7
7
  from_tag = 'from '
8
+ def get_text_or_read(text=None,file_path=None):
9
+ text = text or ''
10
+ imports_js = {}
11
+ if file_path and os.path.isfile(file_path):
12
+ text+=read_from_file(file_path)
13
+ return text
8
14
  def is_line_import(line):
9
15
  if line and (line.startswith(from_tag) or line.startswith(import_tag)):
10
16
  return True
@@ -65,17 +71,32 @@ def get_cleaned_import_list(line,commaClean=True):
65
71
  imports = line.split(import_tag)[1]
66
72
  cleaned_import_list+=clean_imports(imports,commaClean=commaClean)
67
73
  return cleaned_import_list
68
- def clean_imports(text=None,file_path=None,write=False):
69
- text = text or ''
70
- imports_js = {}
71
- if file_path and os.path.isfile(file_path):
72
- text+=read_from_file(file_path)
74
+ def get_all_imports(text=None,file_path=None,import_pkg_js=None):
75
+ text = get_text_or_read(text=text,file_path=file_path)
73
76
  lines = text.split('\n')
74
77
  cleaned_import_list=[]
75
78
  nu_lines = []
76
- j=None
77
79
  is_from_group = False
78
- import_pkg_js={"nulines":[],"file_path":file_path}
80
+ import_pkg_js = import_pkg_js or {}
81
+ if "nulines" not in import_pkg_js:
82
+ import_pkg_js["nulines"]=[]
83
+ if "file_path" not in import_pkg_js:
84
+ import_pkg_js["file_path"]=file_path
85
+ if "all_data" not in import_pkg_js:
86
+ import_pkg_js["all_data"]=[]
87
+ if file_path and file_path != import_pkg_js["file_path"]:
88
+ found=False
89
+ nu_data = {"file_path":import_pkg_js["file_path"],"nulines":import_pkg_js["nulines"]}
90
+ for i,data in enumerate(import_pkg_js["all_data"]):
91
+ if data.get('file_path') == import_pkg_js["file_path"]:
92
+ import_pkg_js["all_data"][i] = nu_data
93
+ found = True
94
+ break
95
+ if found == False:
96
+ import_pkg_js["all_data"].append(nu_data)
97
+ import_pkg_js["nulines"]=[]
98
+ import_pkg_js["file_path"]=file_path
99
+ import_pkg_js={}
79
100
  for line in lines:
80
101
  if line.startswith(import_tag) and ' from ' not in line:
81
102
  cleaned_import_list = get_cleaned_import_list(line)
@@ -93,12 +114,15 @@ def clean_imports(text=None,file_path=None,write=False):
93
114
  else:
94
115
  import_pkg_js=update_import_pkg_js(line,import_pkg_js=import_pkg_js)
95
116
  if is_from_line_group(line) and is_from_group == False:
96
-
97
117
  is_from_group=get_import_pkg(line)
118
+ return import_pkg_js
119
+ def clean_all_imports(text=None,file_path=None,import_pkg_js=None):
120
+ if not import_pkg_js:
121
+ import_pkg_js = get_all_imports(text=text,file_path=file_path)
98
122
  nu_lines = import_pkg_js["nulines"]
99
123
  for pkg,values in import_pkg_js.items():
100
124
  comments = []
101
- if pkg not in ["nulines","file_path"]:
125
+ if pkg not in ["nulines","file_path","all_data"]:
102
126
  line = values.get('line')
103
127
  imports = values.get('imports')
104
128
  for i,imp in enumerate(imports):
@@ -114,9 +138,14 @@ def clean_imports(text=None,file_path=None,write=False):
114
138
  if comments:
115
139
  comments=','.join(comments)
116
140
  imports+=f" #{comments}"
117
-
141
+ import_pkg_js[pkg]["imports"]=imports
118
142
  nu_lines[line] += imports
119
- contents = '\n'.join(nu_lines)
143
+ import_pkg_js["nulines"]=nu_lines
144
+ return import_pkg_js
145
+ def save_cleaned_imports(text=None,file_path=None,write=False,import_pkg_js=None):
146
+ import_pkg_js=get_all_imports(text=text,file_path=file_path,import_pkg_js=import_pkg_js)
147
+ import_pkg_js = clean_all_imports(text=text,file_path=file_path,import_pkg_js=import_pkg_js)
148
+ contents = '\n'.join(import_pkg_js["nulines"])
120
149
  if file_path and write:
121
150
  write_to_file(contents=contents,file_path=file_path)
122
151
  return contents
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: abstract_utilities
3
- Version: 0.2.2.471
3
+ Version: 0.2.2.473
4
4
  Summary: abstract_utilities is a collection of utility modules providing a variety of functions to aid in tasks such as data comparison, list manipulation, JSON handling, string manipulation, mathematical computations, and time operations.
5
5
  Home-page: https://github.com/AbstractEndeavors/abstract_utilities
6
6
  Author: putkoff
@@ -73,7 +73,7 @@ abstract_utilities/robust_readers/__init__.py,sha256=_1vhOG1FJnfrRK0ubkT1v6U6udH
73
73
  abstract_utilities/robust_readers/imports.py,sha256=FtNxdPoLeeNycDnl-6rBGxBfYjhQ7VhmI5guj8XKFcU,355
74
74
  abstract_utilities/robust_readers/initFuncGen.py,sha256=nrQn1KpSlPNKoOngN1uizVwNMA4llrcd8aGKqlzpXzI,5436
75
75
  abstract_utilities/robust_readers/import_utils/__init__.py,sha256=0XaHXUzvgMjSV-4VXcBB-sLcXzL3U3ssHZ95YkvgS9w,195
76
- abstract_utilities/robust_readers/import_utils/clean_imports.py,sha256=eqnEngnXIp6p4VtePn5BgCzUV2hHF7eVc4M_9Ty61HU,4936
76
+ abstract_utilities/robust_readers/import_utils/clean_imports.py,sha256=ImekpGKREo3WUmkZSkKUvP6kC6kL2Jz5wGUoRP32t0c,6438
77
77
  abstract_utilities/robust_readers/import_utils/dot_utils.py,sha256=pmwnY461mOnDjIjgHD6H9MhQXFaF-q8kWerJDgJ1DuI,2364
78
78
  abstract_utilities/robust_readers/import_utils/function_utils.py,sha256=Q9NKvRov3uAaz2Aal3d6fb_opWNXHF9C8GSKOjgfO8Y,1622
79
79
  abstract_utilities/robust_readers/import_utils/import_utils.py,sha256=l0GYdtj5FEYX2yknL-8ru7_U2Sp9Hi1NpegqWPLRMc8,11705
@@ -86,7 +86,7 @@ abstract_utilities/ssh_utils/classes.py,sha256=3Q9BfLpyagNFYyiF4bt-5UCezeUJv9NK9
86
86
  abstract_utilities/ssh_utils/imports.py,sha256=oX8WAv-pkhizzko_h3fIUp9Vhsse4nR7RN2vwONxIx0,317
87
87
  abstract_utilities/ssh_utils/pexpect_utils.py,sha256=JBdOIXBTXAqE5TrsFjmPWJgwSaWyRJN8rbJ6y3_zKPY,10556
88
88
  abstract_utilities/ssh_utils/utils.py,sha256=smUWAx3nW1h0etTndJ_te9bkUX5YzQ8kYd9_gD1TXLk,4882
89
- abstract_utilities-0.2.2.471.dist-info/METADATA,sha256=omUQ9OGEqRJZ_Np_c72j0Q0OXBDDgUj3nHTTFvjSBWI,28108
90
- abstract_utilities-0.2.2.471.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
91
- abstract_utilities-0.2.2.471.dist-info/top_level.txt,sha256=BF0GZ0xVFfN1K-hFIWPO3viNsOs1sSF86n1vHBg39FM,19
92
- abstract_utilities-0.2.2.471.dist-info/RECORD,,
89
+ abstract_utilities-0.2.2.473.dist-info/METADATA,sha256=nVj-GHP9Bzs9VpesJ77x1T93HLcjeYc7VkbJjXMAsIk,28108
90
+ abstract_utilities-0.2.2.473.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
91
+ abstract_utilities-0.2.2.473.dist-info/top_level.txt,sha256=BF0GZ0xVFfN1K-hFIWPO3viNsOs1sSF86n1vHBg39FM,19
92
+ abstract_utilities-0.2.2.473.dist-info/RECORD,,