kenenet 0.5.8__py3-none-any.whl → 0.5.9__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 +25 -42
- {kenenet-0.5.8.dist-info → kenenet-0.5.9.dist-info}/METADATA +1 -1
- kenenet-0.5.9.dist-info/RECORD +5 -0
- kenenet-0.5.8.dist-info/RECORD +0 -5
- {kenenet-0.5.8.dist-info → kenenet-0.5.9.dist-info}/WHEEL +0 -0
- {kenenet-0.5.8.dist-info → kenenet-0.5.9.dist-info}/top_level.txt +0 -0
kenenet/__init__.py
CHANGED
@@ -11,7 +11,6 @@ def quick_print(message, l=None):
|
|
11
11
|
if l: sys.stdout.write(f"\033[38;2;0;255;26m{l} || {message}\033[0m\n")
|
12
12
|
else: sys.stdout.write(f"\033[38;2;0;255;26m {message}\033[0m\n")
|
13
13
|
|
14
|
-
|
15
14
|
def get_pos(key='f10', kill=False):
|
16
15
|
coord_rgb = []
|
17
16
|
coords = []
|
@@ -48,8 +47,7 @@ def timer(clock=1):
|
|
48
47
|
else:
|
49
48
|
timings[clock] = time.time()
|
50
49
|
|
51
|
-
|
52
|
-
class Config:
|
50
|
+
class _Config:
|
53
51
|
EXCLUDED_NAMES = {'Config', 'VariableTracker', 'track_variables', 'stop_tracking',
|
54
52
|
'track_frame', 'sys', 'inspect', 'types', 'datetime',
|
55
53
|
'self', 'cls', 'args', 'kwargs', '__class__'}
|
@@ -57,18 +55,13 @@ class Config:
|
|
57
55
|
SHOW_TIMESTAMPS = True
|
58
56
|
EXCLUDE_INTERNALS = True
|
59
57
|
|
60
|
-
|
61
|
-
# ==========================================================================
|
62
|
-
# CORE TRACKING FUNCTIONALITY
|
63
|
-
# ==========================================================================
|
64
|
-
|
65
|
-
class VariableTracker:
|
58
|
+
class _VariableTracker:
|
66
59
|
_instance = None
|
67
60
|
|
68
61
|
@classmethod
|
69
|
-
def
|
62
|
+
def _get_instance(cls):
|
70
63
|
if cls._instance is None:
|
71
|
-
cls._instance =
|
64
|
+
cls._instance = _VariableTracker()
|
72
65
|
return cls._instance
|
73
66
|
|
74
67
|
def __init__(self):
|
@@ -76,28 +69,28 @@ class VariableTracker:
|
|
76
69
|
self.frame_locals = {}
|
77
70
|
self.global_vars = {}
|
78
71
|
|
79
|
-
def
|
72
|
+
def _format_value(self, value):
|
80
73
|
try:
|
81
74
|
return repr(value)
|
82
75
|
except:
|
83
76
|
return f"<{type(value).__name__} object>"
|
84
77
|
|
85
|
-
def
|
86
|
-
timestamp = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if
|
87
|
-
print(f"{timestamp}{scope} '{name}' changed from {self.
|
78
|
+
def _print_change(self, name, old, new, scope="Global"):
|
79
|
+
timestamp = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if _Config.SHOW_TIMESTAMPS else ""
|
80
|
+
print(f"{timestamp}{scope} '{name}' changed from {self._format_value(old)} to {self._format_value(new)}")
|
88
81
|
|
89
82
|
def _should_track(self, name):
|
90
|
-
return not (name.startswith('_') and name not in ('__name__', '__file__')) and name not in
|
83
|
+
return not (name.startswith('_') and name not in ('__name__', '__file__')) and name not in _Config.EXCLUDED_NAMES
|
91
84
|
|
92
|
-
def
|
85
|
+
def _start_tracking(self, module_name):
|
93
86
|
if self.active: return
|
94
87
|
module = sys.modules[module_name]
|
95
88
|
self.global_vars = {name: value for name, value in module.__dict__.items() if self._should_track(name)}
|
96
|
-
sys.settrace(
|
89
|
+
sys.settrace(_track_frame)
|
97
90
|
self.active = True
|
98
91
|
print(f"Variable tracking started at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
99
92
|
|
100
|
-
def
|
93
|
+
def _stop_tracking(self):
|
101
94
|
if not self.active: return
|
102
95
|
sys.settrace(None)
|
103
96
|
self.frame_locals.clear()
|
@@ -105,43 +98,33 @@ class VariableTracker:
|
|
105
98
|
self.active = False
|
106
99
|
print(f"Variable tracking stopped at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
107
100
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
# ==========================================================================
|
112
|
-
|
113
|
-
def track_frame(frame, event, arg):
|
114
|
-
tracker = VariableTracker.get_instance()
|
115
|
-
if not tracker.active or event != 'line': return track_frame
|
101
|
+
def _track_frame(frame, event, arg):
|
102
|
+
tracker = _VariableTracker._get_instance()
|
103
|
+
if not tracker.active or event != 'line': return _track_frame
|
116
104
|
scope = "Global" if frame.f_code.co_name == '<module>' else f"Local in '{frame.f_code.co_name}'"
|
117
105
|
current_vars = {name: value for name, value in (frame.f_locals if scope != "Global" else frame.f_globals).items() if tracker._should_track(name)}
|
118
106
|
|
119
107
|
if scope == "Global":
|
120
108
|
for name, value in current_vars.items():
|
121
109
|
if name not in tracker.global_vars:
|
122
|
-
tracker.
|
110
|
+
tracker._print_change(name, None, value, scope)
|
123
111
|
elif tracker.global_vars[name] != value:
|
124
|
-
tracker.
|
112
|
+
tracker._print_change(name, tracker.global_vars[name], value, scope)
|
125
113
|
tracker.global_vars.update(current_vars)
|
126
114
|
else:
|
127
115
|
frame_id = id(frame)
|
128
116
|
if frame_id not in tracker.frame_locals:
|
129
117
|
for name, value in current_vars.items():
|
130
|
-
tracker.
|
118
|
+
tracker._print_change(name, None, value, scope)
|
131
119
|
else:
|
132
120
|
for name, value in current_vars.items():
|
133
121
|
if name not in tracker.frame_locals[frame_id]:
|
134
|
-
tracker.
|
122
|
+
tracker._print_change(name, None, value, scope)
|
135
123
|
elif tracker.frame_locals[frame_id][name] != value:
|
136
|
-
tracker.
|
124
|
+
tracker._print_change(name, tracker.frame_locals[frame_id][name], value, scope)
|
137
125
|
tracker.frame_locals[frame_id] = current_vars
|
138
126
|
if event == 'return' and scope != "Global": del tracker.frame_locals[id(frame)]
|
139
|
-
return
|
140
|
-
|
141
|
-
|
142
|
-
# ==========================================================================
|
143
|
-
# PUBLIC API
|
144
|
-
# ==========================================================================
|
127
|
+
return _track_frame
|
145
128
|
|
146
129
|
def debug():
|
147
130
|
global debug_mode
|
@@ -149,12 +132,12 @@ def debug():
|
|
149
132
|
debug_mode = True
|
150
133
|
caller_frame = inspect.currentframe().f_back
|
151
134
|
module_name = caller_frame.f_globals['__name__']
|
152
|
-
tracker =
|
153
|
-
tracker.
|
154
|
-
caller_frame.f_trace =
|
135
|
+
tracker = _VariableTracker._get_instance()
|
136
|
+
tracker._start_tracking(module_name)
|
137
|
+
caller_frame.f_trace = _track_frame
|
155
138
|
else:
|
156
139
|
debug_mode = False
|
157
|
-
|
140
|
+
_VariableTracker._get_instance()._stop_tracking()
|
158
141
|
|
159
142
|
def pp(msg='caca', subdir=None, pps=3):
|
160
143
|
import os, subprocess
|
@@ -0,0 +1,5 @@
|
|
1
|
+
kenenet/__init__.py,sha256=6n3xWsFNz0VvjmrfTb-Jk477KCyN8ecla8f32gcUr2U,8306
|
2
|
+
kenenet-0.5.9.dist-info/METADATA,sha256=OK5Fwap_emuyXNCsD97-NHfqsLPQRR1okYo9v1P2YnY,633
|
3
|
+
kenenet-0.5.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
+
kenenet-0.5.9.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
+
kenenet-0.5.9.dist-info/RECORD,,
|
kenenet-0.5.8.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
kenenet/__init__.py,sha256=ns2VCwN8GcUMfZ83Mb_v7Dxaq-3O2LnjCC0Lki9kGhI,8823
|
2
|
-
kenenet-0.5.8.dist-info/METADATA,sha256=j7LXBBf4u8DJNOLv6zuNpCiKs-CbKaMY6UejBQyvkzY,633
|
3
|
-
kenenet-0.5.8.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
-
kenenet-0.5.8.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
-
kenenet-0.5.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|