kenenet 0.5.0__py3-none-any.whl → 0.5.2__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,10 +1,10 @@
1
- import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types, os, random, pyperclip, inspect, datetime, atexit
1
+ import sys, zhmiscellany, keyboard, mss, time, os, random, pyperclip, inspect, datetime, atexit
2
2
  import numpy as np
3
3
  from PIL import Image
4
- global timings, ospid
5
4
  from pydub import AudioSegment
6
5
  from pydub.playback import play
7
- ospid = None
6
+ global timings, ospid, debug_mode
7
+ ospid, debug_mode = None, False
8
8
  timings = {}
9
9
 
10
10
  def quick_print(message, l=None):
@@ -51,97 +51,115 @@ 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', 'datetime', '__class__',
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: cls._instance = VariableTracker()
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
- def fmt(self, v):
73
- try: return repr(v)
74
- except: return f"<{type(v).__name__} object>"
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
- ts = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if Config.SHOW_TIMESTAMPS else ""
77
- print(f"{ts}{scope} '{name}' changed from {self.fmt(old)} to {self.fmt(new)}")
78
- def _should_track_name(self, n):
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__'))
80
- def _should_track_frame(self, f):
81
- if not Config.EXCLUDE_INTERNALS:
82
- return True
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
- self.tracked_module = sys.modules[mod_name]
94
- self.global_vars = {n: v for n, v in self.tracked_module.__dict__.items() if self._should_track_name(n)}
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(); self.global_vars.clear(); self.active = False
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 not tracker._should_track_frame(frame):
107
- return track_frame
108
- if event != 'line':
109
- return track_frame
110
- fid, is_mod = id(frame), frame.f_code.co_name == '<module>'
111
- scope = "Global" if is_mod else f"Local in '{frame.f_code.co_name}'"
112
- curr = {n: v for n, v in frame.f_locals.items() if tracker._should_track_name(n)}
113
- if is_mod:
114
- for n, v in curr.items():
115
- if n not in tracker.global_vars:
116
- tracker.print_change(n, None, v, scope); tracker.global_vars[n] = v
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
- if fid in tracker.frame_locals:
121
- for n, v in curr.items():
122
- if n not in tracker.frame_locals[fid]:
123
- tracker.print_change(n, None, v, scope)
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 n, v in curr.items():
128
- tracker.print_change(n, None, v, scope)
129
- tracker.frame_locals[fid] = curr.copy()
130
- if event == 'return' and not is_mod and fid in tracker.frame_locals:
131
- del tracker.frame_locals[fid]
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
 
134
- def track_variables():
135
- cf = inspect.currentframe().f_back
136
- mod = cf.f_globals['__name__']
137
- VariableTracker.get_instance().start_tracking(mod)
138
- cf.f_trace = track_frame
139
- atexit.register(stop_tracking)
140
141
 
141
- def stop_tracking():
142
- VariableTracker.get_instance().stop_tracking()
142
+ # ==========================================================================
143
+ # PUBLIC API
144
+ # ==========================================================================
145
+
146
+ def debug():
147
+ global debug_mode
148
+ if not debug_mode:
149
+ caller_frame = inspect.currentframe().f_back
150
+ module_name = caller_frame.f_globals['__name__']
151
+ tracker = VariableTracker.get_instance()
152
+ tracker.start_tracking(module_name)
153
+ caller_frame.f_trace = track_frame
154
+ debug_mode = True
155
+ if debug_mode:
156
+ VariableTracker.get_instance().stop_tracking()
157
+ debug_mode = False
143
158
 
144
159
 
160
+ def stop_debug():
161
+ VariableTracker.get_instance().stop_tracking()
162
+
145
163
  def pp(msg='caca', subdir=None, pps=3):
146
164
  import os, subprocess
147
165
  os_current = os.getcwd()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kenenet
3
- Version: 0.5.0
3
+ Version: 0.5.2
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=4D9UWgrpuc6RhS344NlFnH0ersev0O8CXqiM1gsZql0,8880
2
+ kenenet-0.5.2.dist-info/METADATA,sha256=MZtYIgC1PfAxZOBIwce-u5J4scQs-sNJ57Pt8bplJ3w,633
3
+ kenenet-0.5.2.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
4
+ kenenet-0.5.2.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
+ kenenet-0.5.2.dist-info/RECORD,,
@@ -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,,