kenenet 0.4.9__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 CHANGED
@@ -51,71 +51,56 @@ 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', 'types', 'datetime',
55
- 'self', 'cls', 'args', 'kwargs', '__class__'}
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
-
61
61
  class VariableTracker:
62
62
  _instance = None
63
-
64
63
  @classmethod
65
64
  def get_instance(cls):
66
65
  if cls._instance is None: cls._instance = VariableTracker()
67
66
  return cls._instance
68
-
69
67
  def __init__(self):
70
68
  self.active = False
71
69
  self.tracked_module = None
72
70
  self.frame_locals = {}
73
71
  self.global_vars = {}
74
-
75
72
  def fmt(self, v):
76
- try:
77
- return repr(v)
78
- except:
79
- return f"<{type(v).__name__} object>"
80
-
73
+ try: return repr(v)
74
+ except: return f"<{type(v).__name__} object>"
81
75
  def print_change(self, name, old, new, scope="Global"):
82
76
  ts = f"[{datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}] " if Config.SHOW_TIMESTAMPS else ""
83
77
  print(f"{ts}{scope} '{name}' changed from {self.fmt(old)} to {self.fmt(new)}")
84
-
85
78
  def _should_track_name(self, n):
86
- return not (n.startswith('_') and n not in ('__name__', '__file__')) and n not in Config.EXCLUDED_NAMES
87
-
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__'))
88
80
  def _should_track_frame(self, f):
89
81
  if not Config.EXCLUDE_INTERNALS:
90
82
  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>'):
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
+ }:
97
89
  return False
98
90
  return True
99
-
100
91
  def start_tracking(self, mod_name):
101
92
  if self.active: return
102
93
  self.tracked_module = sys.modules[mod_name]
103
- for name, value in self.tracked_module.__dict__.items():
104
- if self._should_track_name(name):
105
- self.global_vars[name] = value
94
+ self.global_vars = {n: v for n, v in self.tracked_module.__dict__.items() if self._should_track_name(n)}
106
95
  sys.settrace(track_frame)
107
96
  self.active = True
108
97
  print(f"Variable tracking started at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
109
-
110
98
  def stop_tracking(self):
111
99
  if not self.active: return
112
100
  sys.settrace(None)
113
- self.frame_locals.clear();
114
- self.global_vars.clear();
115
- self.active = False
101
+ self.frame_locals.clear(); self.global_vars.clear(); self.active = False
116
102
  print(f"Variable tracking stopped at {datetime.datetime.now().strftime('%H:%M:%S.%f')[:-3]}")
117
103
 
118
-
119
104
  def track_frame(frame, event, arg):
120
105
  tracker = VariableTracker.get_instance()
121
106
  if not tracker.active or not tracker._should_track_frame(frame):
@@ -128,11 +113,9 @@ def track_frame(frame, event, arg):
128
113
  if is_mod:
129
114
  for n, v in curr.items():
130
115
  if n not in tracker.global_vars:
131
- tracker.print_change(n, None, v, scope);
132
- tracker.global_vars[n] = v
116
+ tracker.print_change(n, None, v, scope); tracker.global_vars[n] = v
133
117
  elif tracker.global_vars[n] != v:
134
- tracker.print_change(n, tracker.global_vars[n], v, scope);
135
- tracker.global_vars[n] = v
118
+ tracker.print_change(n, tracker.global_vars[n], v, scope); tracker.global_vars[n] = v
136
119
  else:
137
120
  if fid in tracker.frame_locals:
138
121
  for n, v in curr.items():
@@ -148,7 +131,6 @@ def track_frame(frame, event, arg):
148
131
  del tracker.frame_locals[fid]
149
132
  return track_frame
150
133
 
151
-
152
134
  def track_variables():
153
135
  cf = inspect.currentframe().f_back
154
136
  mod = cf.f_globals['__name__']
@@ -156,10 +138,10 @@ def track_variables():
156
138
  cf.f_trace = track_frame
157
139
  atexit.register(stop_tracking)
158
140
 
159
-
160
141
  def stop_tracking():
161
142
  VariableTracker.get_instance().stop_tracking()
162
143
 
144
+
163
145
  def pp(msg='caca', subdir=None, pps=3):
164
146
  import os, subprocess
165
147
  os_current = os.getcwd()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kenenet
3
- Version: 0.4.9
3
+ Version: 0.5.0
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=_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,,
@@ -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,,