atrace 0.1.1__tar.gz → 0.1.2__tar.gz
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.
- {atrace-0.1.1 → atrace-0.1.2}/PKG-INFO +15 -5
- {atrace-0.1.1 → atrace-0.1.2}/README.md +14 -4
- {atrace-0.1.1 → atrace-0.1.2}/pyproject.toml +1 -1
- {atrace-0.1.1 → atrace-0.1.2}/src/atrace/__init__.py +16 -20
- {atrace-0.1.1 → atrace-0.1.2}/src/example.py +4 -1
- {atrace-0.1.1 → atrace-0.1.2}/.github/workflows/publish-to-pypi.yml +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/.gitignore +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/.vscode/settings.json +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/atrace/py.typed +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/.python-version +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/devto_example.py +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/execution_trace_example.py +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/pyproject.toml +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/pytracetool_example.py +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/simple_program.py +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/stack_overflow_example.py +0 -0
- {atrace-0.1.1 → atrace-0.1.2}/src/inspiration/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: atrace
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Generate trace tables for programs
|
|
5
5
|
Project-URL: Repository, https://github.com/nwolff/atrace.git
|
|
6
6
|
Author-email: Nicholas Wolff <nwolff@gmail.com>
|
|
@@ -9,14 +9,21 @@ Description-Content-Type: text/markdown
|
|
|
9
9
|
|
|
10
10
|
# TODO:
|
|
11
11
|
|
|
12
|
-
- entering a function, binding the local arguments, returning
|
|
13
12
|
- ignore function definitions (look at the type of object)
|
|
14
13
|
|
|
15
14
|
- display at end only
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
- entering a function, binding the local arguments, returning
|
|
17
|
+
|
|
18
|
+
# Usage
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Automatically prints a trace table of a program once the execution is finished.
|
|
21
|
+
|
|
22
|
+
Just import the module.
|
|
23
|
+
|
|
24
|
+
An animated example of a trace table: https://www.101computing.net/using-trace-tables/
|
|
25
|
+
|
|
26
|
+
# Requirements
|
|
20
27
|
|
|
21
28
|
- Should not interfere with the running program (apart from capturing stdout)
|
|
22
29
|
- Should display the trace at the end of execution (not while the program is interacting with the user)
|
|
@@ -28,7 +35,10 @@ A package that automatically prints a trace table of a program, just by importin
|
|
|
28
35
|
- binding the local arguments
|
|
29
36
|
- returning
|
|
30
37
|
|
|
31
|
-
|
|
38
|
+
# Supported environments
|
|
39
|
+
|
|
40
|
+
- Thonny, which adds a shitload of magic
|
|
41
|
+
- python 3.10+
|
|
32
42
|
|
|
33
43
|
# Not in scope
|
|
34
44
|
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
# TODO:
|
|
2
2
|
|
|
3
|
-
- entering a function, binding the local arguments, returning
|
|
4
3
|
- ignore function definitions (look at the type of object)
|
|
5
4
|
|
|
6
5
|
- display at end only
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
- entering a function, binding the local arguments, returning
|
|
8
|
+
|
|
9
|
+
# Usage
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
Automatically prints a trace table of a program once the execution is finished.
|
|
12
|
+
|
|
13
|
+
Just import the module.
|
|
14
|
+
|
|
15
|
+
An animated example of a trace table: https://www.101computing.net/using-trace-tables/
|
|
16
|
+
|
|
17
|
+
# Requirements
|
|
11
18
|
|
|
12
19
|
- Should not interfere with the running program (apart from capturing stdout)
|
|
13
20
|
- Should display the trace at the end of execution (not while the program is interacting with the user)
|
|
@@ -19,7 +26,10 @@ A package that automatically prints a trace table of a program, just by importin
|
|
|
19
26
|
- binding the local arguments
|
|
20
27
|
- returning
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
# Supported environments
|
|
30
|
+
|
|
31
|
+
- Thonny, which adds a shitload of magic
|
|
32
|
+
- python 3.10+
|
|
23
33
|
|
|
24
34
|
# Not in scope
|
|
25
35
|
|
|
@@ -4,24 +4,20 @@ import sys
|
|
|
4
4
|
from types import FrameType
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
module_of_interest = None
|
|
8
8
|
last_locals = {}
|
|
9
9
|
|
|
10
|
-
ignored_variables = set(
|
|
11
|
-
[
|
|
12
|
-
"tid",
|
|
13
|
-
]
|
|
14
|
-
)
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
11
|
+
def ignore_variable(name: str, value: Any):
|
|
12
|
+
# if name.startswith("_"):
|
|
13
|
+
# return True
|
|
14
|
+
return callable(value) # Functions, modules, tout ça
|
|
19
15
|
|
|
20
16
|
|
|
21
17
|
def copy_carefully_using_ignored_variables(d: dict[str, Any]):
|
|
22
18
|
res = {}
|
|
23
19
|
for k, v in d.items():
|
|
24
|
-
if not ignore_variable(k):
|
|
20
|
+
if not ignore_variable(k, v):
|
|
25
21
|
res[k] = copy.deepcopy(v)
|
|
26
22
|
return res
|
|
27
23
|
|
|
@@ -38,9 +34,8 @@ def copy_carefully(d: dict[str, Any]):
|
|
|
38
34
|
|
|
39
35
|
|
|
40
36
|
def trace_vars(frame: FrameType, event: str, arg: Any):
|
|
41
|
-
if
|
|
37
|
+
if inspect.getmodule(frame) != module_of_interest:
|
|
42
38
|
return
|
|
43
|
-
# print(frame.f_lineno, frame.f_code.co_name, frame.f_locals, event)
|
|
44
39
|
if event != "line":
|
|
45
40
|
return trace_vars
|
|
46
41
|
code = frame.f_code
|
|
@@ -58,15 +53,15 @@ def trace_vars(frame: FrameType, event: str, arg: Any):
|
|
|
58
53
|
old_locals = last_locals[code.co_name]
|
|
59
54
|
|
|
60
55
|
for var, new_val in locals_now.items():
|
|
61
|
-
if not ignore_variable(var):
|
|
56
|
+
if not ignore_variable(var, new_val):
|
|
62
57
|
if var not in old_locals:
|
|
63
58
|
print(f"[{lineno}] NEW {var} = {new_val}")
|
|
64
59
|
elif old_locals[var] != new_val:
|
|
65
60
|
print(f"[{lineno}] MODIFIED {var}: {old_locals[var]} → {new_val}")
|
|
66
61
|
|
|
67
|
-
for var in old_locals:
|
|
68
|
-
if not
|
|
69
|
-
if
|
|
62
|
+
for var, old_val in old_locals.items():
|
|
63
|
+
if var not in locals_now:
|
|
64
|
+
if not ignore_variable(var, old_val):
|
|
70
65
|
print(f"[{lineno}] DELETED {var}")
|
|
71
66
|
|
|
72
67
|
last_locals[code.co_name] = locals_now
|
|
@@ -87,15 +82,16 @@ def get_importer_frame():
|
|
|
87
82
|
return None
|
|
88
83
|
|
|
89
84
|
|
|
90
|
-
# This will work next time we enter a function.
|
|
91
85
|
# It also kicks off the tracing machinery (so that the lines below work)
|
|
92
|
-
sys.settrace(
|
|
86
|
+
sys.settrace(just_kicking_off)
|
|
93
87
|
|
|
94
88
|
|
|
95
|
-
# This reaches into the importing module's frame to setup tracing
|
|
89
|
+
# This reaches into the importing module's frame to setup tracing of code outside of functions
|
|
96
90
|
importer_frame = get_importer_frame()
|
|
97
91
|
if importer_frame:
|
|
98
92
|
importer_frame.f_trace = trace_vars
|
|
99
|
-
|
|
93
|
+
module_of_interest = inspect.getmodule(importer_frame)
|
|
94
|
+
# This will work next time we enter a function.
|
|
95
|
+
sys.settrace(trace_vars)
|
|
100
96
|
else:
|
|
101
97
|
print("Cannot trace")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|