kenenet 0.2.5__py3-none-any.whl → 0.2.7__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,5 +1,4 @@
1
- import inspect, sys, zhmiscellany, keyboard, mss, time, sys
2
-
1
+ import inspect, sys, zhmiscellany, keyboard, mss, time, linecache, types
3
2
  global timings
4
3
  timings = {}
5
4
 
@@ -37,6 +36,81 @@ def timer(clock=1):
37
36
  else:
38
37
  timings[clock] = time.time()
39
38
 
39
+
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
+ """
52
+ special_vars = {
53
+ "__name__", "__doc__", "__package__", "__loader__",
54
+ "__spec__", "__annotations__", "__file__", "__cached__"
55
+ }
56
+
57
+ def trace_lines(frame, event, arg):
58
+ if event == 'line':
59
+ filename = frame.f_code.co_filename
60
+ lineno = frame.f_lineno
61
+ code_line = linecache.getline(filename, lineno).strip()
62
+ # Header for readability.
63
+ header = f"Executing line {lineno}:" if ignore_file_path else f"Executing {filename}:{lineno}:"
64
+ _quick_print("=" * 60)
65
+ _quick_print(header, lineno)
66
+ _quick_print(f" {code_line}", lineno)
67
+ _quick_print("-" * 60, lineno)
68
+ _quick_print("Local Variables:", lineno)
69
+ for var, value in frame.f_locals.items():
70
+ if ignore_special_vars and var in special_vars:
71
+ continue
72
+ if ignore_modules and isinstance(value, types.ModuleType):
73
+ continue
74
+ if ignore_functions and isinstance(value, types.FunctionType):
75
+ continue
76
+ if ignore_classes and isinstance(value, type):
77
+ continue
78
+ _quick_print(f" {var} = {value}", lineno)
79
+ _quick_print("=" * 60, lineno)
80
+ return trace_lines
81
+
82
+ return trace_lines
83
+
84
+
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(
97
+ ignore_special_vars=ignore_special_vars,
98
+ ignore_functions=ignore_functions,
99
+ ignore_classes=ignore_classes,
100
+ ignore_modules=ignore_modules,
101
+ ignore_file_path=ignore_file_path
102
+ )
103
+ sys.settrace(trace_func)
104
+ # Force the current (global) frame to be traced.
105
+ sys._getframe().f_trace = trace_func
106
+ _quick_print("Tracing activated.")
107
+
108
+
109
+ def dbug_stop():
110
+ """Deactivates the tracing."""
111
+ sys.settrace(None)
112
+ _quick_print("Tracing deactivated.")
113
+
40
114
  def pp(msg='caca', subdir=None, pps=3):
41
115
  import os, subprocess
42
116
  os_current = os.getcwd()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: kenenet
3
- Version: 0.2.5
3
+ Version: 0.2.7
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=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,,
@@ -1,5 +0,0 @@
1
- kenenet/__init__.py,sha256=4s6SRN2YKzN8rC54qcwS7DKa7ZBmSiPy9zpO4_Qtr6k,2478
2
- kenenet-0.2.5.dist-info/METADATA,sha256=unx9dXlxg8CXe8ZVZhM-KnO89d4jIk1xwADR68LKOnk,513
3
- kenenet-0.2.5.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
4
- kenenet-0.2.5.dist-info/top_level.txt,sha256=gUsWXLrM0jF4b4nbYJZdksdFewIx_F3xOF-zER8fMuQ,8
5
- kenenet-0.2.5.dist-info/RECORD,,