kenenet 0.4.9__py3-none-any.whl → 0.5.1__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 +53 -59
- {kenenet-0.4.9.dist-info → kenenet-0.5.1.dist-info}/METADATA +1 -1
- kenenet-0.5.1.dist-info/RECORD +5 -0
- kenenet-0.4.9.dist-info/RECORD +0 -5
- {kenenet-0.4.9.dist-info → kenenet-0.5.1.dist-info}/WHEEL +0 -0
- {kenenet-0.4.9.dist-info → kenenet-0.5.1.dist-info}/top_level.txt +0 -0
kenenet/__init__.py
CHANGED
@@ -58,51 +58,41 @@ class Config:
|
|
58
58
|
EXCLUDE_INTERNALS = True
|
59
59
|
|
60
60
|
|
61
|
+
# ==========================================================================
|
62
|
+
# CORE TRACKING FUNCTIONALITY
|
63
|
+
# ==========================================================================
|
64
|
+
|
61
65
|
class VariableTracker:
|
62
66
|
_instance = None
|
63
67
|
|
64
68
|
@classmethod
|
65
69
|
def get_instance(cls):
|
66
|
-
if cls._instance is None:
|
70
|
+
if cls._instance is None:
|
71
|
+
cls._instance = VariableTracker()
|
67
72
|
return cls._instance
|
68
73
|
|
69
74
|
def __init__(self):
|
70
75
|
self.active = False
|
71
|
-
self.tracked_module = None
|
72
76
|
self.frame_locals = {}
|
73
77
|
self.global_vars = {}
|
74
78
|
|
75
|
-
def
|
79
|
+
def format_value(self, value):
|
76
80
|
try:
|
77
|
-
return repr(
|
81
|
+
return repr(value)
|
78
82
|
except:
|
79
|
-
return f"<{type(
|
83
|
+
return f"<{type(value).__name__} object>"
|
80
84
|
|
81
85
|
def print_change(self, name, old, new, scope="Global"):
|
82
|
-
|
83
|
-
print(f"{
|
84
|
-
|
85
|
-
def _should_track_name(self, n):
|
86
|
-
return not (n.startswith('_') and n not in ('__name__', '__file__')) and n not in Config.EXCLUDED_NAMES
|
86
|
+
timestamp = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if Config.SHOW_TIMESTAMPS else ""
|
87
|
+
print(f"{timestamp}{scope} '{name}' changed from {self.format_value(old)} to {self.format_value(new)}")
|
87
88
|
|
88
|
-
def
|
89
|
-
|
90
|
-
return True
|
91
|
-
fn = f.f_code.co_filename
|
92
|
-
if any(e in fn for e in Config.EXCLUDED_FILES):
|
93
|
-
return False
|
94
|
-
# Exclude known internal shutdown and list comprehension functions.
|
95
|
-
if f.f_code.co_name in ('tracked_setattr', 'fmt', 'print_change', 'track_globals', 'get_instance',
|
96
|
-
'_maintain_shutdown_locks', '_shutdown', '_stop', '<listcomp>'):
|
97
|
-
return False
|
98
|
-
return True
|
89
|
+
def _should_track(self, name):
|
90
|
+
return not (name.startswith('_') and name not in ('__name__', '__file__')) and name not in Config.EXCLUDED_NAMES
|
99
91
|
|
100
|
-
def start_tracking(self,
|
92
|
+
def start_tracking(self, module_name):
|
101
93
|
if self.active: return
|
102
|
-
|
103
|
-
for name, value in
|
104
|
-
if self._should_track_name(name):
|
105
|
-
self.global_vars[name] = value
|
94
|
+
module = sys.modules[module_name]
|
95
|
+
self.global_vars = {name: value for name, value in module.__dict__.items() if self._should_track(name)}
|
106
96
|
sys.settrace(track_frame)
|
107
97
|
self.active = True
|
108
98
|
print(f"Variable tracking started at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
@@ -110,51 +100,55 @@ class VariableTracker:
|
|
110
100
|
def stop_tracking(self):
|
111
101
|
if not self.active: return
|
112
102
|
sys.settrace(None)
|
113
|
-
self.frame_locals.clear()
|
114
|
-
self.global_vars.clear()
|
103
|
+
self.frame_locals.clear()
|
104
|
+
self.global_vars.clear()
|
115
105
|
self.active = False
|
116
106
|
print(f"Variable tracking stopped at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
117
107
|
|
118
108
|
|
109
|
+
# ==========================================================================
|
110
|
+
# TRACE FUNCTION
|
111
|
+
# ==========================================================================
|
112
|
+
|
119
113
|
def track_frame(frame, event, arg):
|
120
114
|
tracker = VariableTracker.get_instance()
|
121
|
-
if not tracker.active or
|
122
|
-
|
123
|
-
if
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
tracker.global_vars[n] = v
|
133
|
-
elif tracker.global_vars[n] != v:
|
134
|
-
tracker.print_change(n, tracker.global_vars[n], v, scope);
|
135
|
-
tracker.global_vars[n] = v
|
115
|
+
if not tracker.active or event != 'line': return track_frame
|
116
|
+
scope = "Global" if frame.f_code.co_name == '<module>' else f"Local in '{frame.f_code.co_name}'"
|
117
|
+
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
|
+
|
119
|
+
if scope == "Global":
|
120
|
+
for name, value in current_vars.items():
|
121
|
+
if name not in tracker.global_vars:
|
122
|
+
tracker.print_change(name, None, value, scope)
|
123
|
+
elif tracker.global_vars[name] != value:
|
124
|
+
tracker.print_change(name, tracker.global_vars[name], value, scope)
|
125
|
+
tracker.global_vars.update(current_vars)
|
136
126
|
else:
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
elif tracker.frame_locals[fid][n] != v:
|
142
|
-
tracker.print_change(n, tracker.frame_locals[fid][n], v, scope)
|
127
|
+
frame_id = id(frame)
|
128
|
+
if frame_id not in tracker.frame_locals:
|
129
|
+
for name, value in current_vars.items():
|
130
|
+
tracker.print_change(name, None, value, scope)
|
143
131
|
else:
|
144
|
-
for
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
132
|
+
for name, value in current_vars.items():
|
133
|
+
if name not in tracker.frame_locals[frame_id]:
|
134
|
+
tracker.print_change(name, None, value, scope)
|
135
|
+
elif tracker.frame_locals[frame_id][name] != value:
|
136
|
+
tracker.print_change(name, tracker.frame_locals[frame_id][name], value, scope)
|
137
|
+
tracker.frame_locals[frame_id] = current_vars
|
138
|
+
if event == 'return' and scope != "Global": del tracker.frame_locals[id(frame)]
|
149
139
|
return track_frame
|
150
140
|
|
151
141
|
|
142
|
+
# ==========================================================================
|
143
|
+
# PUBLIC API
|
144
|
+
# ==========================================================================
|
145
|
+
|
152
146
|
def track_variables():
|
153
|
-
|
154
|
-
|
155
|
-
VariableTracker.get_instance()
|
156
|
-
|
157
|
-
|
147
|
+
caller_frame = inspect.currentframe().f_back
|
148
|
+
module_name = caller_frame.f_globals['__name__']
|
149
|
+
tracker = VariableTracker.get_instance()
|
150
|
+
tracker.start_tracking(module_name)
|
151
|
+
caller_frame.f_trace = track_frame
|
158
152
|
|
159
153
|
|
160
154
|
def stop_tracking():
|
@@ -0,0 +1,5 @@
|
|
1
|
+
kenenet/__init__.py,sha256=AsXM-b-tQmk1xct78gaUsPJMgOfzG_bX4MCPoUqauPQ,8691
|
2
|
+
kenenet-0.5.1.dist-info/METADATA,sha256=sjWvuaThONKGgD2T3MYbmT-_tJwA9tc_4o3fq0AcQEE,633
|
3
|
+
kenenet-0.5.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
+
kenenet-0.5.1.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
+
kenenet-0.5.1.dist-info/RECORD,,
|
kenenet-0.4.9.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
kenenet/__init__.py,sha256=lW5HqrpZo8FAxzi1WgSAr4Bo-aweG0S0H-RNQ2OlVn8,8644
|
2
|
-
kenenet-0.4.9.dist-info/METADATA,sha256=jmh9EbdAn04ICRraoI8tOibDzbuencrMX2vzF0wnxh0,633
|
3
|
-
kenenet-0.4.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
-
kenenet-0.4.9.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
-
kenenet-0.4.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|