kenenet 0.4.7__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 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
- def make_trace_function(ignore_special_vars=True, ignore_functions=True, ignore_classes=True, ignore_modules=True, ignore_file_path=True):
53
- special_vars = {
54
- "__name__", "__doc__", "__package__", "__loader__",
55
- "__spec__", "__annotations__", "__file__", "__cached__"
56
- }
57
-
58
- def trace_lines(frame, event, arg):
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 activate_tracing(ignore_special_vars=True, ignore_functions=True, ignore_classes=True, ignore_modules=True, ignore_file_path=True):
97
- trace_func = make_trace_function(
98
- ignore_special_vars=ignore_special_vars,
99
- ignore_functions=ignore_functions,
100
- ignore_classes=ignore_classes,
101
- ignore_modules=ignore_modules,
102
- ignore_file_path=ignore_file_path
103
- )
104
- sys.settrace(trace_func)
105
- sys._getframe().f_trace = trace_func
106
- quick_print("Tracing activated.")
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 deactivate_tracing():
110
- sys.settrace(None)
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kenenet
3
- Version: 0.4.7
3
+ Version: 0.4.8
4
4
  Summary: dude what the fuck even is this package
5
5
  Home-page: https://www.youtube.com/@KiddyKene
6
6
  Author: kiddykene
@@ -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,,
@@ -1,5 +0,0 @@
1
- kenenet/__init__.py,sha256=vJt7E0HsbvWtXvt8dEKjYGzQI0EhhPCzaNz6yR9wcQQ,6660
2
- kenenet-0.4.7.dist-info/METADATA,sha256=tdLr-XGfLjvoe4EoPZ8nIyz2Ahu0bycv7jDNwuPb3k0,633
3
- kenenet-0.4.7.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4
- kenenet-0.4.7.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
- kenenet-0.4.7.dist-info/RECORD,,