kenenet 0.4.6__py3-none-any.whl → 0.4.8__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.
- kenenet/__init__.py +91 -59
- {kenenet-0.4.6.dist-info → kenenet-0.4.8.dist-info}/METADATA +1 -1
- kenenet-0.4.8.dist-info/RECORD +5 -0
- kenenet-0.4.6.dist-info/RECORD +0 -5
- {kenenet-0.4.6.dist-info → kenenet-0.4.8.dist-info}/WHEEL +0 -0
- {kenenet-0.4.6.dist-info → kenenet-0.4.8.dist-info}/top_level.txt +0 -0
kenenet/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types, os, random, pyperclip
|
1
|
+
import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types, os, random, pyperclip, inspect, datetime, atexit
|
2
2
|
import numpy as np
|
3
3
|
from PIL import Image
|
4
4
|
global timings, ospid
|
@@ -49,66 +49,98 @@ def timer(clock=1):
|
|
49
49
|
timings[clock] = time.time()
|
50
50
|
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
if event == 'line':
|
60
|
-
filename = frame.f_code.co_filename
|
61
|
-
lineno = frame.f_lineno
|
62
|
-
code_line = linecache.getline(filename, lineno).strip()
|
63
|
-
|
64
|
-
# Prevent spamming by ensuring we aren't tracing internal Python locks or infinite loops
|
65
|
-
if not code_line:
|
66
|
-
return trace_lines
|
67
|
-
|
68
|
-
header = f"Executing line {lineno}:" if ignore_file_path else f"Executing {filename}:{lineno}:"
|
69
|
-
quick_print("=" * 60)
|
70
|
-
quick_print(header, lineno)
|
71
|
-
quick_print(f" {code_line}", lineno)
|
72
|
-
quick_print("-" * 60, lineno)
|
73
|
-
quick_print("Local Variables:", lineno)
|
74
|
-
|
75
|
-
for var, value in frame.f_locals.items():
|
76
|
-
if ignore_special_vars and var in special_vars:
|
77
|
-
continue
|
78
|
-
if ignore_modules and isinstance(value, types.ModuleType):
|
79
|
-
continue
|
80
|
-
if ignore_functions and isinstance(value, types.FunctionType):
|
81
|
-
continue
|
82
|
-
if ignore_classes and isinstance(value, type):
|
83
|
-
continue
|
84
|
-
try:
|
85
|
-
quick_print(f" {var} = {repr(value)}", lineno)
|
86
|
-
except (AttributeError, TypeError, Exception):
|
87
|
-
quick_print(f" {var} = [unreadable]", lineno)
|
88
|
-
|
89
|
-
quick_print("=" * 60, lineno)
|
90
|
-
|
91
|
-
return trace_lines
|
92
|
-
|
93
|
-
return trace_lines
|
52
|
+
class _Config:
|
53
|
+
EXCLUDED_NAMES = {'Config', 'VariableTracker', 'track_variables', 'stop_tracking',
|
54
|
+
'track_frame', 'sys', 'inspect', 'types', 'datetime',
|
55
|
+
'self', 'cls', 'args', 'kwargs', '__class__'}
|
56
|
+
EXCLUDED_FILES = {'<string>', '<frozen importlib', 'importlib', 'abc.py', 'typing.py', '_collections_abc.py'}
|
57
|
+
SHOW_TIMESTAMPS = True
|
58
|
+
EXCLUDE_INTERNALS = True
|
94
59
|
|
60
|
+
class _VariableTracker:
|
61
|
+
_instance = None
|
62
|
+
@classmethod
|
63
|
+
def _get_instance(cls):
|
64
|
+
if cls._instance is None: cls._instance = _VariableTracker()
|
65
|
+
return cls._instance
|
66
|
+
def __init__(self):
|
67
|
+
self.active = False
|
68
|
+
self.tracked_module = None
|
69
|
+
self.frame_locals = {}
|
70
|
+
self.global_vars = {}
|
71
|
+
def fmt(self, v):
|
72
|
+
try: return repr(v)
|
73
|
+
except: return f"<{type(v).__name__} object>"
|
74
|
+
def print_change(self, name, old, new, scope="Global"):
|
75
|
+
ts = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if _Config.SHOW_TIMESTAMPS else ""
|
76
|
+
print(f"{ts}{scope} '{name}' changed from {self.fmt(old)} to {self.fmt(new)}")
|
77
|
+
def _should_track_name(self, n):
|
78
|
+
return not (n.startswith('_') and n not in ('__name__','__file__')) and n not in _Config.EXCLUDED_NAMES
|
79
|
+
def _should_track_frame(self, f):
|
80
|
+
if not _Config.EXCLUDE_INTERNALS:
|
81
|
+
return True
|
82
|
+
fn = f.f_code.co_filename
|
83
|
+
if any(e in fn for e in _Config.EXCLUDED_FILES):
|
84
|
+
return False
|
85
|
+
# Exclude known internal shutdown and list comprehension functions.
|
86
|
+
if f.f_code.co_name in ('tracked_setattr', 'fmt', 'print_change', 'track_globals', 'get_instance',
|
87
|
+
'_maintain_shutdown_locks', '_shutdown', '_stop', '<listcomp>'):
|
88
|
+
return False
|
89
|
+
return True
|
90
|
+
def _start_tracking(self, mod_name):
|
91
|
+
if self.active: return
|
92
|
+
self.tracked_module = sys.modules[mod_name]
|
93
|
+
for name, value in self.tracked_module.__dict__.items():
|
94
|
+
if self._should_track_name(name):
|
95
|
+
self.global_vars[name] = value
|
96
|
+
sys.settrace(_track_frame)
|
97
|
+
self.active = True
|
98
|
+
print(f"Variable tracking started at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
99
|
+
def _stop_tracking(self):
|
100
|
+
if not self.active: return
|
101
|
+
sys.settrace(None)
|
102
|
+
self.frame_locals.clear(); self.global_vars.clear(); self.active = False
|
103
|
+
print(f"Variable tracking stopped at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
95
104
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
105
|
+
def _track_frame(frame, event, arg):
|
106
|
+
tracker = _VariableTracker._get_instance()
|
107
|
+
if not tracker.active or not tracker._should_track_frame(frame):
|
108
|
+
return _track_frame
|
109
|
+
if event != 'line':
|
110
|
+
return _track_frame
|
111
|
+
fid, is_mod = id(frame), frame.f_code.co_name == '<module>'
|
112
|
+
scope = "Global" if is_mod else f"Local in '{frame.f_code.co_name}'"
|
113
|
+
curr = {n: v for n, v in frame.f_locals.items() if tracker._should_track_name(n)}
|
114
|
+
if is_mod:
|
115
|
+
for n, v in curr.items():
|
116
|
+
if n not in tracker.global_vars:
|
117
|
+
tracker.print_change(n, None, v, scope); tracker.global_vars[n] = v
|
118
|
+
elif tracker.global_vars[n] != v:
|
119
|
+
tracker.print_change(n, tracker.global_vars[n], v, scope); tracker.global_vars[n] = v
|
120
|
+
else:
|
121
|
+
if fid in tracker.frame_locals:
|
122
|
+
for n, v in curr.items():
|
123
|
+
if n not in tracker.frame_locals[fid]:
|
124
|
+
tracker.print_change(n, None, v, scope)
|
125
|
+
elif tracker.frame_locals[fid][n] != v:
|
126
|
+
tracker.print_change(n, tracker.frame_locals[fid][n], v, scope)
|
127
|
+
else:
|
128
|
+
for n, v in curr.items():
|
129
|
+
tracker.print_change(n, None, v, scope)
|
130
|
+
tracker.frame_locals[fid] = curr.copy()
|
131
|
+
if event == 'return' and not is_mod and fid in tracker.frame_locals:
|
132
|
+
del tracker.frame_locals[fid]
|
133
|
+
return _track_frame
|
107
134
|
|
135
|
+
def debug():
|
136
|
+
cf = inspect.currentframe().f_back
|
137
|
+
mod = cf.f_globals['__name__']
|
138
|
+
_VariableTracker._get_instance()._start_tracking(mod)
|
139
|
+
cf.f_trace = _track_frame
|
140
|
+
atexit.register(stop_debug)
|
108
141
|
|
109
|
-
def
|
110
|
-
|
111
|
-
quick_print("Tracing deactivated.")
|
142
|
+
def stop_debug():
|
143
|
+
_VariableTracker._get_instance()._stop_tracking()
|
112
144
|
|
113
145
|
def pp(msg='caca', subdir=None, pps=3):
|
114
146
|
import os, subprocess
|
@@ -131,7 +163,7 @@ def pp(msg='caca', subdir=None, pps=3):
|
|
131
163
|
quick_print('PP finished B======D')
|
132
164
|
os.chdir(os_current)
|
133
165
|
|
134
|
-
def save_img(img, name='', reset=True, file='temp_screenshots'):
|
166
|
+
def save_img(img, name=' ', reset=True, file='temp_screenshots', mute=False):
|
135
167
|
global ospid
|
136
168
|
if os.path.exists(file):
|
137
169
|
if reset and ospid is None:
|
@@ -147,7 +179,7 @@ def save_img(img, name='', reset=True, file='temp_screenshots'):
|
|
147
179
|
save_name = name + f'{time.time()}'
|
148
180
|
img = Image.fromarray(img)
|
149
181
|
img.save(fr'{file}\{save_name}.png')
|
150
|
-
quick_print(f'Saved image as {save_name}', lineno)
|
182
|
+
if not mute: quick_print(f'Saved image as {save_name}', lineno)
|
151
183
|
else:
|
152
184
|
quick_print(f"Your img is not a fucking numpy array you twat, couldn't save {name}", lineno)
|
153
185
|
|
@@ -0,0 +1,5 @@
|
|
1
|
+
kenenet/__init__.py,sha256=rEHte4thzsgNXDblmcHHQlIEN38OpXalPZ28o9NGrgc,8518
|
2
|
+
kenenet-0.4.8.dist-info/METADATA,sha256=vYSrchmnsYXGa6Wp9H4UmZZw8OBVaTO8R-fsZPxHxYM,633
|
3
|
+
kenenet-0.4.8.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
+
kenenet-0.4.8.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
+
kenenet-0.4.8.dist-info/RECORD,,
|
kenenet-0.4.6.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
kenenet/__init__.py,sha256=Woj-Uj8g7ZibLM84W3hJ7i5DDo6NfubSfTaHvLqiKNQ,6634
|
2
|
-
kenenet-0.4.6.dist-info/METADATA,sha256=4njs5V-E4IYfpZ4pcQpOe6WqW9V4mvsF346Rb2KXr2g,633
|
3
|
-
kenenet-0.4.6.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
-
kenenet-0.4.6.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
-
kenenet-0.4.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|