kenenet 0.5.0__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 +69 -57
- {kenenet-0.5.0.dist-info → kenenet-0.5.1.dist-info}/METADATA +1 -1
- kenenet-0.5.1.dist-info/RECORD +5 -0
- kenenet-0.5.0.dist-info/RECORD +0 -5
- {kenenet-0.5.0.dist-info → kenenet-0.5.1.dist-info}/WHEEL +0 -0
- {kenenet-0.5.0.dist-info → kenenet-0.5.1.dist-info}/top_level.txt +0 -0
kenenet/__init__.py
CHANGED
@@ -51,97 +51,109 @@ def timer(clock=1):
|
|
51
51
|
|
52
52
|
class Config:
|
53
53
|
EXCLUDED_NAMES = {'Config', 'VariableTracker', 'track_variables', 'stop_tracking',
|
54
|
-
'track_frame', 'sys', 'inspect', '
|
55
|
-
'self', 'cls', 'args', 'kwargs'}
|
56
|
-
IGNORED_VARS = {'weakcontainer', 'w', 'e', 't', 'b', 's', 'pop', 'd', 'items'}
|
54
|
+
'track_frame', 'sys', 'inspect', 'types', 'datetime',
|
55
|
+
'self', 'cls', 'args', 'kwargs', '__class__'}
|
57
56
|
EXCLUDED_FILES = {'<string>', '<frozen importlib', 'importlib', 'abc.py', 'typing.py', '_collections_abc.py'}
|
58
57
|
SHOW_TIMESTAMPS = True
|
59
58
|
EXCLUDE_INTERNALS = True
|
60
59
|
|
60
|
+
|
61
|
+
# ==========================================================================
|
62
|
+
# CORE TRACKING FUNCTIONALITY
|
63
|
+
# ==========================================================================
|
64
|
+
|
61
65
|
class VariableTracker:
|
62
66
|
_instance = None
|
67
|
+
|
63
68
|
@classmethod
|
64
69
|
def get_instance(cls):
|
65
|
-
if cls._instance is None:
|
70
|
+
if cls._instance is None:
|
71
|
+
cls._instance = VariableTracker()
|
66
72
|
return cls._instance
|
73
|
+
|
67
74
|
def __init__(self):
|
68
75
|
self.active = False
|
69
|
-
self.tracked_module = None
|
70
76
|
self.frame_locals = {}
|
71
77
|
self.global_vars = {}
|
72
|
-
|
73
|
-
|
74
|
-
|
78
|
+
|
79
|
+
def format_value(self, value):
|
80
|
+
try:
|
81
|
+
return repr(value)
|
82
|
+
except:
|
83
|
+
return f"<{type(value).__name__} object>"
|
84
|
+
|
75
85
|
def print_change(self, name, old, new, scope="Global"):
|
76
|
-
|
77
|
-
print(f"{
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
fn, func = f.f_code.co_filename, f.f_code.co_name
|
84
|
-
if any(e in fn for e in Config.EXCLUDED_FILES) or func in {
|
85
|
-
'tracked_setattr', 'fmt', 'print_change', 'track_globals', 'get_instance',
|
86
|
-
'_maintain_shutdown_locks', '_shutdown', '_stop', '<listcomp>',
|
87
|
-
'__init__', '__enter__', '__exit__', '_commit_removals', '_python_exit'
|
88
|
-
}:
|
89
|
-
return False
|
90
|
-
return True
|
91
|
-
def start_tracking(self, mod_name):
|
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)}")
|
88
|
+
|
89
|
+
def _should_track(self, name):
|
90
|
+
return not (name.startswith('_') and name not in ('__name__', '__file__')) and name not in Config.EXCLUDED_NAMES
|
91
|
+
|
92
|
+
def start_tracking(self, module_name):
|
92
93
|
if self.active: return
|
93
|
-
|
94
|
-
self.global_vars = {
|
94
|
+
module = sys.modules[module_name]
|
95
|
+
self.global_vars = {name: value for name, value in module.__dict__.items() if self._should_track(name)}
|
95
96
|
sys.settrace(track_frame)
|
96
97
|
self.active = True
|
97
98
|
print(f"Variable tracking started at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
99
|
+
|
98
100
|
def stop_tracking(self):
|
99
101
|
if not self.active: return
|
100
102
|
sys.settrace(None)
|
101
|
-
self.frame_locals.clear()
|
103
|
+
self.frame_locals.clear()
|
104
|
+
self.global_vars.clear()
|
105
|
+
self.active = False
|
102
106
|
print(f"Variable tracking stopped at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
103
107
|
|
108
|
+
|
109
|
+
# ==========================================================================
|
110
|
+
# TRACE FUNCTION
|
111
|
+
# ==========================================================================
|
112
|
+
|
104
113
|
def track_frame(frame, event, arg):
|
105
114
|
tracker = VariableTracker.get_instance()
|
106
|
-
if not tracker.active or
|
107
|
-
|
108
|
-
if
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
elif tracker.global_vars[n] != v:
|
118
|
-
tracker.print_change(n, tracker.global_vars[n], v, scope); 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)
|
119
126
|
else:
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
elif tracker.frame_locals[fid][n] != v:
|
125
|
-
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)
|
126
131
|
else:
|
127
|
-
for
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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)]
|
132
139
|
return track_frame
|
133
140
|
|
141
|
+
|
142
|
+
# ==========================================================================
|
143
|
+
# PUBLIC API
|
144
|
+
# ==========================================================================
|
145
|
+
|
134
146
|
def track_variables():
|
135
|
-
|
136
|
-
|
137
|
-
VariableTracker.get_instance()
|
138
|
-
|
139
|
-
|
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
|
152
|
+
|
140
153
|
|
141
154
|
def stop_tracking():
|
142
155
|
VariableTracker.get_instance().stop_tracking()
|
143
156
|
|
144
|
-
|
145
157
|
def pp(msg='caca', subdir=None, pps=3):
|
146
158
|
import os, subprocess
|
147
159
|
os_current = os.getcwd()
|
@@ -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.5.0.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
kenenet/__init__.py,sha256=_S-XB0eiMzsaQ3ttXae6uKkbF2qxVJet-uF0nInznv8,8561
|
2
|
-
kenenet-0.5.0.dist-info/METADATA,sha256=vpqZzkpBfpVT8cpRHEEibOBGto9f9NqPweK5iHN1s6w,633
|
3
|
-
kenenet-0.5.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
4
|
-
kenenet-0.5.0.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
|
5
|
-
kenenet-0.5.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|