invocation-tree 0.0.38__tar.gz → 0.0.40__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.
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/PKG-INFO +24 -7
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/README.md +23 -6
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree/__init__.py +17 -9
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree.egg-info/PKG-INFO +24 -7
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/pyproject.toml +1 -1
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/LICENSE.txt +0 -0
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree/regex_set.py +0 -0
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree.egg-info/SOURCES.txt +0 -0
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree.egg-info/dependency_links.txt +0 -0
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree.egg-info/requires.txt +0 -0
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree.egg-info/top_level.txt +0 -0
- {invocation_tree-0.0.38 → invocation_tree-0.0.40}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: invocation_tree
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.40
|
|
4
4
|
Summary: Generates an invocation tree of functions calls.
|
|
5
5
|
Author-email: Bas Terwijn <bterwijn@gmail.com>
|
|
6
6
|
License-Expression: BSD-2-Clause
|
|
@@ -48,9 +48,11 @@ The new `@ivt.show` [decorator interface](#decorator) now allows for **scaling**
|
|
|
48
48
|
|
|
49
49
|
[Collecting Results](#collecting-results)
|
|
50
50
|
|
|
51
|
+
[Mutability](#mutability)
|
|
52
|
+
|
|
51
53
|
[Quick Sort](#quick-sort)
|
|
52
54
|
|
|
53
|
-
[
|
|
55
|
+
[Tower of Hanoi](#tower-of-hanoi)
|
|
54
56
|
|
|
55
57
|
[Jugs Puzzle](#jugs-puzzle)
|
|
56
58
|
|
|
@@ -73,7 +75,7 @@ ___
|
|
|
73
75
|
|
|
74
76
|
# Iteration and Recursion #
|
|
75
77
|
|
|
76
|
-
Repetition can be implemented with **iteration** and **recursion**. As an example we compute the factorial of 4.
|
|
78
|
+
Repetition can in Python be implemented with **iteration** and **recursion**. As an example we compute the factorial of 4.
|
|
77
79
|
|
|
78
80
|
``` python
|
|
79
81
|
import math
|
|
@@ -147,9 +149,9 @@ Or see it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/
|
|
|
147
149
|
|
|
148
150
|
Each node in the invocation tree represents a function call, and the node's color indicates its state:
|
|
149
151
|
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
- Red:
|
|
152
|
+
- Green: the function is paused and will resume execution later
|
|
153
|
+
- White: the function is currently being executed
|
|
154
|
+
- Red: the function has completed execution and has returned
|
|
153
155
|
|
|
154
156
|
For every function call, the package displays its **local variables** and **return value**. Changes to the values of these variables over time are highlighted using bold text and gray shading to make them easier to track.
|
|
155
157
|
|
|
@@ -352,7 +354,7 @@ This would be much harder to implement with iteration and shows the power of rec
|
|
|
352
354
|
|
|
353
355
|
## Debug Prints ##
|
|
354
356
|
|
|
355
|
-
Adding temporarely debug print statements is in general a good technique to understand code, and is particularly helpful with recursion. Here we added a debug print statement when adding and removing a node from the path. As a result we can now in the output see how all paths are build step by step:
|
|
357
|
+
Adding temporarely debug print statements is in general a good technique to understand code, and is particularly helpful with recursion. Here we added a debug print statement when adding and removing a node from the path. As a result we can now, in the output, see how all paths are build step by step:
|
|
356
358
|
|
|
357
359
|
See it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/#codeurl=https://raw.githubusercontent.com/bterwijn/invocation_tree/refs/heads/main/src/print_paths_print_1.py&breakpoints=33&continues=1×tep=0.2&play)
|
|
358
360
|
|
|
@@ -538,6 +540,19 @@ Add a `key` argument so that we can use the `quick_sort(values, key=None)` funct
|
|
|
538
540
|
|
|
539
541
|
Sort the values as normal when `key` is `None`.
|
|
540
542
|
|
|
543
|
+
# Tower of Hanoi #
|
|
544
|
+
|
|
545
|
+
Another classic recursion problem is the Tower of Hanoi problem where we need to move all disks from A to C, by moving one disk at a time between any two positions, where a disk may never be on top of a smaller disk.
|
|
546
|
+
|
|
547
|
+

|
|
548
|
+
|
|
549
|
+
Doing this by hand can quickly get confusing, but the recursive solution is beautifully short. To move n disks we:
|
|
550
|
+
- first remove n-1 disks from the largest disk
|
|
551
|
+
- then move the largest disk
|
|
552
|
+
- and then move the n-1 disks back on top
|
|
553
|
+
|
|
554
|
+
See it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/#codeurl=https://raw.githubusercontent.com/bterwijn/invocation_tree/refs/heads/main/src/tower_of_hanoi.py×tep=0.5&play)
|
|
555
|
+
|
|
541
556
|
# Jugs Puzzle #
|
|
542
557
|
|
|
543
558
|
In the Jugs Puzzle we have a set of jugs of various capacities. Our goal is to get a jug with a certain amount of liquid in it. In each step we can take one of these actions:
|
|
@@ -729,6 +744,8 @@ tree = ivt.Invocation_Tree()
|
|
|
729
744
|
|
|
730
745
|
## Functions ##
|
|
731
746
|
|
|
747
|
+
- **mg.layout(horizontal: bool = None)**
|
|
748
|
+
- set tree layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
|
|
732
749
|
- **tree.dark_mode(b: bool = None)**
|
|
733
750
|
- set dark mode to 'True' or 'False', or 'None' to toggle.
|
|
734
751
|
- **tree.transparent_background(b: bool = None)**
|
|
@@ -28,9 +28,11 @@ The new `@ivt.show` [decorator interface](#decorator) now allows for **scaling**
|
|
|
28
28
|
|
|
29
29
|
[Collecting Results](#collecting-results)
|
|
30
30
|
|
|
31
|
+
[Mutability](#mutability)
|
|
32
|
+
|
|
31
33
|
[Quick Sort](#quick-sort)
|
|
32
34
|
|
|
33
|
-
[
|
|
35
|
+
[Tower of Hanoi](#tower-of-hanoi)
|
|
34
36
|
|
|
35
37
|
[Jugs Puzzle](#jugs-puzzle)
|
|
36
38
|
|
|
@@ -53,7 +55,7 @@ ___
|
|
|
53
55
|
|
|
54
56
|
# Iteration and Recursion #
|
|
55
57
|
|
|
56
|
-
Repetition can be implemented with **iteration** and **recursion**. As an example we compute the factorial of 4.
|
|
58
|
+
Repetition can in Python be implemented with **iteration** and **recursion**. As an example we compute the factorial of 4.
|
|
57
59
|
|
|
58
60
|
``` python
|
|
59
61
|
import math
|
|
@@ -127,9 +129,9 @@ Or see it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/
|
|
|
127
129
|
|
|
128
130
|
Each node in the invocation tree represents a function call, and the node's color indicates its state:
|
|
129
131
|
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
- Red:
|
|
132
|
+
- Green: the function is paused and will resume execution later
|
|
133
|
+
- White: the function is currently being executed
|
|
134
|
+
- Red: the function has completed execution and has returned
|
|
133
135
|
|
|
134
136
|
For every function call, the package displays its **local variables** and **return value**. Changes to the values of these variables over time are highlighted using bold text and gray shading to make them easier to track.
|
|
135
137
|
|
|
@@ -332,7 +334,7 @@ This would be much harder to implement with iteration and shows the power of rec
|
|
|
332
334
|
|
|
333
335
|
## Debug Prints ##
|
|
334
336
|
|
|
335
|
-
Adding temporarely debug print statements is in general a good technique to understand code, and is particularly helpful with recursion. Here we added a debug print statement when adding and removing a node from the path. As a result we can now in the output see how all paths are build step by step:
|
|
337
|
+
Adding temporarely debug print statements is in general a good technique to understand code, and is particularly helpful with recursion. Here we added a debug print statement when adding and removing a node from the path. As a result we can now, in the output, see how all paths are build step by step:
|
|
336
338
|
|
|
337
339
|
See it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/#codeurl=https://raw.githubusercontent.com/bterwijn/invocation_tree/refs/heads/main/src/print_paths_print_1.py&breakpoints=33&continues=1×tep=0.2&play)
|
|
338
340
|
|
|
@@ -518,6 +520,19 @@ Add a `key` argument so that we can use the `quick_sort(values, key=None)` funct
|
|
|
518
520
|
|
|
519
521
|
Sort the values as normal when `key` is `None`.
|
|
520
522
|
|
|
523
|
+
# Tower of Hanoi #
|
|
524
|
+
|
|
525
|
+
Another classic recursion problem is the Tower of Hanoi problem where we need to move all disks from A to C, by moving one disk at a time between any two positions, where a disk may never be on top of a smaller disk.
|
|
526
|
+
|
|
527
|
+

|
|
528
|
+
|
|
529
|
+
Doing this by hand can quickly get confusing, but the recursive solution is beautifully short. To move n disks we:
|
|
530
|
+
- first remove n-1 disks from the largest disk
|
|
531
|
+
- then move the largest disk
|
|
532
|
+
- and then move the n-1 disks back on top
|
|
533
|
+
|
|
534
|
+
See it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/#codeurl=https://raw.githubusercontent.com/bterwijn/invocation_tree/refs/heads/main/src/tower_of_hanoi.py×tep=0.5&play)
|
|
535
|
+
|
|
521
536
|
# Jugs Puzzle #
|
|
522
537
|
|
|
523
538
|
In the Jugs Puzzle we have a set of jugs of various capacities. Our goal is to get a jug with a certain amount of liquid in it. In each step we can take one of these actions:
|
|
@@ -709,6 +724,8 @@ tree = ivt.Invocation_Tree()
|
|
|
709
724
|
|
|
710
725
|
## Functions ##
|
|
711
726
|
|
|
727
|
+
- **mg.layout(horizontal: bool = None)**
|
|
728
|
+
- set tree layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
|
|
712
729
|
- **tree.dark_mode(b: bool = None)**
|
|
713
730
|
- set dark mode to 'True' or 'False', or 'None' to toggle.
|
|
714
731
|
- **tree.transparent_background(b: bool = None)**
|
|
@@ -10,7 +10,7 @@ import functools
|
|
|
10
10
|
|
|
11
11
|
import invocation_tree.regex_set as regset
|
|
12
12
|
|
|
13
|
-
__version__ = "0.0.
|
|
13
|
+
__version__ = "0.0.40"
|
|
14
14
|
__author__ = 'Bas Terwijn'
|
|
15
15
|
|
|
16
16
|
# colors dark
|
|
@@ -21,11 +21,11 @@ color_active_light = '#ffffff'
|
|
|
21
21
|
color_returned_light = '#ffcccc'
|
|
22
22
|
|
|
23
23
|
# colors light
|
|
24
|
-
foreground_color_dark = '#
|
|
24
|
+
foreground_color_dark = '#cccccc'
|
|
25
25
|
background_color_dark = '#1d1d1d'
|
|
26
|
-
color_paused_dark = '#
|
|
26
|
+
color_paused_dark = '#446644'
|
|
27
27
|
color_active_dark = '#1d1d1d'
|
|
28
|
-
color_returned_dark = '#
|
|
28
|
+
color_returned_dark = '#664444'
|
|
29
29
|
|
|
30
30
|
# color placeholders
|
|
31
31
|
foreground_color_PH = '<foreground_color_PH>'
|
|
@@ -71,9 +71,11 @@ def filter_variables(var, val):
|
|
|
71
71
|
return True
|
|
72
72
|
|
|
73
73
|
class Tree_Node:
|
|
74
|
+
node_id = 0
|
|
74
75
|
|
|
75
|
-
def __init__(self,
|
|
76
|
-
self.node_id = node_id
|
|
76
|
+
def __init__(self, frame, return_value):
|
|
77
|
+
self.node_id = Tree_Node.node_id
|
|
78
|
+
Tree_Node.node_id += 1
|
|
77
79
|
self.frame = frame
|
|
78
80
|
self.return_value = return_value
|
|
79
81
|
self.is_returned = False
|
|
@@ -127,6 +129,7 @@ class Invocation_Tree:
|
|
|
127
129
|
self.fontsize = '14'
|
|
128
130
|
self.in_dark_mode = False
|
|
129
131
|
self.in_transparent_background = False
|
|
132
|
+
self.horizontal = False
|
|
130
133
|
self.set_colors()
|
|
131
134
|
# --- core
|
|
132
135
|
self.stack = []
|
|
@@ -134,7 +137,6 @@ class Invocation_Tree:
|
|
|
134
137
|
self.prev_returned = []
|
|
135
138
|
self.paused = []
|
|
136
139
|
self.prev_paused = []
|
|
137
|
-
self.node_id = 0
|
|
138
140
|
self.node_id_to_table = {}
|
|
139
141
|
self.edges = []
|
|
140
142
|
self.is_highlighted = False
|
|
@@ -169,6 +171,12 @@ class Invocation_Tree:
|
|
|
169
171
|
self.in_dark_mode = dark
|
|
170
172
|
self.set_colors()
|
|
171
173
|
|
|
174
|
+
def layout(self, horizontal = None):
|
|
175
|
+
if horizontal is None:
|
|
176
|
+
self.horizontal = not self.horizontal
|
|
177
|
+
else:
|
|
178
|
+
self.horizontal = horizontal
|
|
179
|
+
|
|
172
180
|
def transparent_background(self, transparent = None):
|
|
173
181
|
if transparent is None:
|
|
174
182
|
self.in_transparent_background = not self.in_transparent_background
|
|
@@ -301,6 +309,7 @@ class Invocation_Tree:
|
|
|
301
309
|
graph_attr=graphviz_graph_attr,
|
|
302
310
|
node_attr=graphviz_node_attr,
|
|
303
311
|
edge_attr=graphviz_edge_attr)
|
|
312
|
+
graph.attr(rankdir= "LR" if self.horizontal else "TB")
|
|
304
313
|
return graph
|
|
305
314
|
|
|
306
315
|
def build_graph_from_nodes(self):
|
|
@@ -414,8 +423,7 @@ class Invocation_Tree:
|
|
|
414
423
|
self.update_node(previous, active=False)
|
|
415
424
|
self.paused.append(previous)
|
|
416
425
|
# create new node
|
|
417
|
-
self.stack.append(Tree_Node(
|
|
418
|
-
self.node_id += 1
|
|
426
|
+
self.stack.append(Tree_Node(frame, None))
|
|
419
427
|
if len(self.stack)>1:
|
|
420
428
|
self.add_edge(self.stack[-2], self.stack[-1])
|
|
421
429
|
self.paused.append(self.stack[-2])
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: invocation_tree
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.40
|
|
4
4
|
Summary: Generates an invocation tree of functions calls.
|
|
5
5
|
Author-email: Bas Terwijn <bterwijn@gmail.com>
|
|
6
6
|
License-Expression: BSD-2-Clause
|
|
@@ -48,9 +48,11 @@ The new `@ivt.show` [decorator interface](#decorator) now allows for **scaling**
|
|
|
48
48
|
|
|
49
49
|
[Collecting Results](#collecting-results)
|
|
50
50
|
|
|
51
|
+
[Mutability](#mutability)
|
|
52
|
+
|
|
51
53
|
[Quick Sort](#quick-sort)
|
|
52
54
|
|
|
53
|
-
[
|
|
55
|
+
[Tower of Hanoi](#tower-of-hanoi)
|
|
54
56
|
|
|
55
57
|
[Jugs Puzzle](#jugs-puzzle)
|
|
56
58
|
|
|
@@ -73,7 +75,7 @@ ___
|
|
|
73
75
|
|
|
74
76
|
# Iteration and Recursion #
|
|
75
77
|
|
|
76
|
-
Repetition can be implemented with **iteration** and **recursion**. As an example we compute the factorial of 4.
|
|
78
|
+
Repetition can in Python be implemented with **iteration** and **recursion**. As an example we compute the factorial of 4.
|
|
77
79
|
|
|
78
80
|
``` python
|
|
79
81
|
import math
|
|
@@ -147,9 +149,9 @@ Or see it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/
|
|
|
147
149
|
|
|
148
150
|
Each node in the invocation tree represents a function call, and the node's color indicates its state:
|
|
149
151
|
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
- Red:
|
|
152
|
+
- Green: the function is paused and will resume execution later
|
|
153
|
+
- White: the function is currently being executed
|
|
154
|
+
- Red: the function has completed execution and has returned
|
|
153
155
|
|
|
154
156
|
For every function call, the package displays its **local variables** and **return value**. Changes to the values of these variables over time are highlighted using bold text and gray shading to make them easier to track.
|
|
155
157
|
|
|
@@ -352,7 +354,7 @@ This would be much harder to implement with iteration and shows the power of rec
|
|
|
352
354
|
|
|
353
355
|
## Debug Prints ##
|
|
354
356
|
|
|
355
|
-
Adding temporarely debug print statements is in general a good technique to understand code, and is particularly helpful with recursion. Here we added a debug print statement when adding and removing a node from the path. As a result we can now in the output see how all paths are build step by step:
|
|
357
|
+
Adding temporarely debug print statements is in general a good technique to understand code, and is particularly helpful with recursion. Here we added a debug print statement when adding and removing a node from the path. As a result we can now, in the output, see how all paths are build step by step:
|
|
356
358
|
|
|
357
359
|
See it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/#codeurl=https://raw.githubusercontent.com/bterwijn/invocation_tree/refs/heads/main/src/print_paths_print_1.py&breakpoints=33&continues=1×tep=0.2&play)
|
|
358
360
|
|
|
@@ -538,6 +540,19 @@ Add a `key` argument so that we can use the `quick_sort(values, key=None)` funct
|
|
|
538
540
|
|
|
539
541
|
Sort the values as normal when `key` is `None`.
|
|
540
542
|
|
|
543
|
+
# Tower of Hanoi #
|
|
544
|
+
|
|
545
|
+
Another classic recursion problem is the Tower of Hanoi problem where we need to move all disks from A to C, by moving one disk at a time between any two positions, where a disk may never be on top of a smaller disk.
|
|
546
|
+
|
|
547
|
+

|
|
548
|
+
|
|
549
|
+
Doing this by hand can quickly get confusing, but the recursive solution is beautifully short. To move n disks we:
|
|
550
|
+
- first remove n-1 disks from the largest disk
|
|
551
|
+
- then move the largest disk
|
|
552
|
+
- and then move the n-1 disks back on top
|
|
553
|
+
|
|
554
|
+
See it in the [Invocation Tree Web Debugger](https://www.invocation-tree.com/#codeurl=https://raw.githubusercontent.com/bterwijn/invocation_tree/refs/heads/main/src/tower_of_hanoi.py×tep=0.5&play)
|
|
555
|
+
|
|
541
556
|
# Jugs Puzzle #
|
|
542
557
|
|
|
543
558
|
In the Jugs Puzzle we have a set of jugs of various capacities. Our goal is to get a jug with a certain amount of liquid in it. In each step we can take one of these actions:
|
|
@@ -729,6 +744,8 @@ tree = ivt.Invocation_Tree()
|
|
|
729
744
|
|
|
730
745
|
## Functions ##
|
|
731
746
|
|
|
747
|
+
- **mg.layout(horizontal: bool = None)**
|
|
748
|
+
- set tree layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
|
|
732
749
|
- **tree.dark_mode(b: bool = None)**
|
|
733
750
|
- set dark mode to 'True' or 'False', or 'None' to toggle.
|
|
734
751
|
- **tree.transparent_background(b: bool = None)**
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{invocation_tree-0.0.38 → invocation_tree-0.0.40}/invocation_tree.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|