kenenet 0.4.8__py3-none-any.whl → 0.5.0__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 +32 -32
- {kenenet-0.4.8.dist-info → kenenet-0.5.0.dist-info}/METADATA +1 -1
- kenenet-0.5.0.dist-info/RECORD +5 -0
- kenenet-0.4.8.dist-info/RECORD +0 -5
- {kenenet-0.4.8.dist-info → kenenet-0.5.0.dist-info}/WHEEL +0 -0
- {kenenet-0.4.8.dist-info → kenenet-0.5.0.dist-info}/top_level.txt +0 -0
kenenet/__init__.py
CHANGED
@@ -49,19 +49,20 @@ def timer(clock=1):
|
|
49
49
|
timings[clock] = time.time()
|
50
50
|
|
51
51
|
|
52
|
-
class
|
52
|
+
class Config:
|
53
53
|
EXCLUDED_NAMES = {'Config', 'VariableTracker', 'track_variables', 'stop_tracking',
|
54
|
-
'track_frame', 'sys', 'inspect', '
|
55
|
-
'self', 'cls', 'args', 'kwargs'
|
54
|
+
'track_frame', 'sys', 'inspect', 'datetime', '__class__',
|
55
|
+
'self', 'cls', 'args', 'kwargs'}
|
56
|
+
IGNORED_VARS = {'weakcontainer', 'w', 'e', 't', 'b', 's', 'pop', 'd', 'items'}
|
56
57
|
EXCLUDED_FILES = {'<string>', '<frozen importlib', 'importlib', 'abc.py', 'typing.py', '_collections_abc.py'}
|
57
58
|
SHOW_TIMESTAMPS = True
|
58
59
|
EXCLUDE_INTERNALS = True
|
59
60
|
|
60
|
-
class
|
61
|
+
class VariableTracker:
|
61
62
|
_instance = None
|
62
63
|
@classmethod
|
63
|
-
def
|
64
|
-
if cls._instance is None: cls._instance =
|
64
|
+
def get_instance(cls):
|
65
|
+
if cls._instance is None: cls._instance = VariableTracker()
|
65
66
|
return cls._instance
|
66
67
|
def __init__(self):
|
67
68
|
self.active = False
|
@@ -72,42 +73,40 @@ class _VariableTracker:
|
|
72
73
|
try: return repr(v)
|
73
74
|
except: return f"<{type(v).__name__} object>"
|
74
75
|
def print_change(self, name, old, new, scope="Global"):
|
75
|
-
ts = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if
|
76
|
+
ts = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if Config.SHOW_TIMESTAMPS else ""
|
76
77
|
print(f"{ts}{scope} '{name}' changed from {self.fmt(old)} to {self.fmt(new)}")
|
77
78
|
def _should_track_name(self, n):
|
78
|
-
return not (n.startswith('_') and n not in ('__name__','__file__'))
|
79
|
+
return n not in Config.EXCLUDED_NAMES and n not in Config.IGNORED_VARS and not (n.startswith('_') and n not in ('__name__','__file__'))
|
79
80
|
def _should_track_frame(self, f):
|
80
|
-
if not
|
81
|
+
if not Config.EXCLUDE_INTERNALS:
|
81
82
|
return True
|
82
|
-
fn = f.f_code.co_filename
|
83
|
-
if any(e in fn for e in
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
+
}:
|
88
89
|
return False
|
89
90
|
return True
|
90
|
-
def
|
91
|
+
def start_tracking(self, mod_name):
|
91
92
|
if self.active: return
|
92
93
|
self.tracked_module = sys.modules[mod_name]
|
93
|
-
for
|
94
|
-
|
95
|
-
self.global_vars[name] = value
|
96
|
-
sys.settrace(_track_frame)
|
94
|
+
self.global_vars = {n: v for n, v in self.tracked_module.__dict__.items() if self._should_track_name(n)}
|
95
|
+
sys.settrace(track_frame)
|
97
96
|
self.active = True
|
98
97
|
print(f"Variable tracking started at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
99
|
-
def
|
98
|
+
def stop_tracking(self):
|
100
99
|
if not self.active: return
|
101
100
|
sys.settrace(None)
|
102
101
|
self.frame_locals.clear(); self.global_vars.clear(); self.active = False
|
103
102
|
print(f"Variable tracking stopped at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
|
104
103
|
|
105
|
-
def
|
106
|
-
tracker =
|
104
|
+
def track_frame(frame, event, arg):
|
105
|
+
tracker = VariableTracker.get_instance()
|
107
106
|
if not tracker.active or not tracker._should_track_frame(frame):
|
108
|
-
return
|
107
|
+
return track_frame
|
109
108
|
if event != 'line':
|
110
|
-
return
|
109
|
+
return track_frame
|
111
110
|
fid, is_mod = id(frame), frame.f_code.co_name == '<module>'
|
112
111
|
scope = "Global" if is_mod else f"Local in '{frame.f_code.co_name}'"
|
113
112
|
curr = {n: v for n, v in frame.f_locals.items() if tracker._should_track_name(n)}
|
@@ -130,17 +129,18 @@ def _track_frame(frame, event, arg):
|
|
130
129
|
tracker.frame_locals[fid] = curr.copy()
|
131
130
|
if event == 'return' and not is_mod and fid in tracker.frame_locals:
|
132
131
|
del tracker.frame_locals[fid]
|
133
|
-
return
|
132
|
+
return track_frame
|
134
133
|
|
135
|
-
def
|
134
|
+
def track_variables():
|
136
135
|
cf = inspect.currentframe().f_back
|
137
136
|
mod = cf.f_globals['__name__']
|
138
|
-
|
139
|
-
cf.f_trace =
|
140
|
-
atexit.register(
|
137
|
+
VariableTracker.get_instance().start_tracking(mod)
|
138
|
+
cf.f_trace = track_frame
|
139
|
+
atexit.register(stop_tracking)
|
140
|
+
|
141
|
+
def stop_tracking():
|
142
|
+
VariableTracker.get_instance().stop_tracking()
|
141
143
|
|
142
|
-
def stop_debug():
|
143
|
-
_VariableTracker._get_instance()._stop_tracking()
|
144
144
|
|
145
145
|
def pp(msg='caca', subdir=None, pps=3):
|
146
146
|
import os, subprocess
|
@@ -0,0 +1,5 @@
|
|
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,,
|
kenenet-0.4.8.dist-info/RECORD
DELETED
@@ -1,5 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|