kenenet 0.2.7__py3-none-any.whl → 0.3.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 CHANGED
@@ -1,4 +1,6 @@
1
- import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types
1
+ import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types, os
2
+ import numpy as np
3
+ from PIL import Image
2
4
  global timings
3
5
  timings = {}
4
6
 
@@ -37,18 +39,7 @@ def timer(clock=1):
37
39
  timings[clock] = time.time()
38
40
 
39
41
 
40
- def _make_trace_function(ignore_special_vars=False, ignore_functions=False, ignore_classes=False, ignore_modules=False, ignore_file_path=False):
41
- """
42
- Returns a trace function that prints each executed line along with local variables.
43
-
44
- Parameters:
45
- ignore_special_vars (bool): If True, ignores special system variables such as:
46
- __name__, __doc__, __package__, __loader__, __spec__, __annotations__, __file__, __cached__
47
- ignore_functions (bool): If True, ignores function objects.
48
- ignore_classes (bool): If True, ignores class objects.
49
- ignore_modules (bool): If True, ignores module objects.
50
- ignore_file_path (bool): If True, does not print the file path in the header.
51
- """
42
+ def make_trace_function(ignore_special_vars=True, ignore_functions=True, ignore_classes=True, ignore_modules=True, ignore_file_path=True):
52
43
  special_vars = {
53
44
  "__name__", "__doc__", "__package__", "__loader__",
54
45
  "__spec__", "__annotations__", "__file__", "__cached__"
@@ -59,13 +50,18 @@ def _make_trace_function(ignore_special_vars=False, ignore_functions=False, igno
59
50
  filename = frame.f_code.co_filename
60
51
  lineno = frame.f_lineno
61
52
  code_line = linecache.getline(filename, lineno).strip()
62
- # Header for readability.
53
+
54
+ # Prevent spamming by ensuring we aren't tracing internal Python locks or infinite loops
55
+ if not code_line:
56
+ return trace_lines
57
+
63
58
  header = f"Executing line {lineno}:" if ignore_file_path else f"Executing {filename}:{lineno}:"
64
59
  _quick_print("=" * 60)
65
60
  _quick_print(header, lineno)
66
61
  _quick_print(f" {code_line}", lineno)
67
62
  _quick_print("-" * 60, lineno)
68
63
  _quick_print("Local Variables:", lineno)
64
+
69
65
  for var, value in frame.f_locals.items():
70
66
  if ignore_special_vars and var in special_vars:
71
67
  continue
@@ -75,25 +71,20 @@ def _make_trace_function(ignore_special_vars=False, ignore_functions=False, igno
75
71
  continue
76
72
  if ignore_classes and isinstance(value, type):
77
73
  continue
78
- _quick_print(f" {var} = {value}", lineno)
74
+ try:
75
+ _quick_print(f" {var} = {repr(value)}", lineno)
76
+ except (AttributeError, TypeError, Exception):
77
+ _quick_print(f" {var} = [unreadable]", lineno)
78
+
79
79
  _quick_print("=" * 60, lineno)
80
+
80
81
  return trace_lines
81
82
 
82
83
  return trace_lines
83
84
 
84
85
 
85
- def dbug(ignore_special_vars=True, ignore_functions=True, ignore_classes=True, ignore_modules=True, ignore_file_path=True):
86
- """
87
- Activates the line-by-line tracing of code execution.
88
-
89
- Parameters:
90
- ignore_special_vars (bool): If True, omits special variables (e.g. __name__, __doc__, etc.)
91
- ignore_functions (bool): If True, omits function objects.
92
- ignore_classes (bool): If True, omits class objects.
93
- ignore_modules (bool): If True, omits module objects.
94
- ignore_file_path (bool): If True, only the line number is shown instead of the full file path.
95
- """
96
- trace_func = _make_trace_function(
86
+ def activate_tracing(ignore_special_vars=True, ignore_functions=True, ignore_classes=True, ignore_modules=True, ignore_file_path=True):
87
+ trace_func = make_trace_function(
97
88
  ignore_special_vars=ignore_special_vars,
98
89
  ignore_functions=ignore_functions,
99
90
  ignore_classes=ignore_classes,
@@ -101,13 +92,11 @@ def dbug(ignore_special_vars=True, ignore_functions=True, ignore_classes=True, i
101
92
  ignore_file_path=ignore_file_path
102
93
  )
103
94
  sys.settrace(trace_func)
104
- # Force the current (global) frame to be traced.
105
95
  sys._getframe().f_trace = trace_func
106
96
  _quick_print("Tracing activated.")
107
97
 
108
98
 
109
- def dbug_stop():
110
- """Deactivates the tracing."""
99
+ def deactivate_tracing():
111
100
  sys.settrace(None)
112
101
  _quick_print("Tracing deactivated.")
113
102
 
@@ -132,6 +121,19 @@ def pp(msg='caca', subdir=None, pps=3):
132
121
  _quick_print('PP finished B======D')
133
122
  os.chdir(os_current)
134
123
 
124
+ def save_img(img, name='', file='temp_screenshots'):
125
+ if os.path.exists(file): zhmiscellany.fileio.empty_directory(file)
126
+ else: zhmiscellany.fileio.create_folder(file)
127
+ frame = inspect.currentframe().f_back
128
+ lineno = frame.f_lineno
129
+ if isinstance(img, np.ndarray):
130
+ save_name = name + f'{time.time()}'
131
+ img = Image.fromarray(img)
132
+ img.save(f'{file}/{save_name}.png')
133
+ _quick_print(f'Saved image as {save_name}', lineno)
134
+ else:
135
+ _quick_print(f"Your img is not a fucking numpy array you twat, couldn't save {name}", lineno)
136
+
135
137
  class k:
136
138
  pass
137
139
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: kenenet
3
- Version: 0.2.7
3
+ Version: 0.3.1
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=LkhSQnZjdtyGRvOVAPP_-vEX8fHZnyFh4hGgruVKg-E,5627
2
+ kenenet-0.3.1.dist-info/METADATA,sha256=JZ846mPc_CN1nitMKhai6IpbaD4DhseHoNg0lPT5UkA,513
3
+ kenenet-0.3.1.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
4
+ kenenet-0.3.1.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
+ kenenet-0.3.1.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- kenenet/__init__.py,sha256=yq2XCgPyw_zFC5RR3zJfrPR2LNFF6hWIq8rZTXwp4Ds,5783
2
- kenenet-0.2.7.dist-info/METADATA,sha256=LNHs1CZ6wGcdoueBzq3QeM_-9TmfmRH9-npnTAtSyF8,513
3
- kenenet-0.2.7.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
4
- kenenet-0.2.7.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
- kenenet-0.2.7.dist-info/RECORD,,