Bare bones library to vizualize recursion with one line of code.
Project description
About viz.recurse
viz.recurse is a bare-bones library to easily visualize recursion without any significant overhead on the part of the user. This library utilizes common graph and visualization libraries (networkx, matplotlib, pygraphviz).
Latest PyPi release [1.1.3]
Visit https://pypi.org/project/vizrecurse/1.1.3/
Requirements
Python 3.10.13
pip 23.0.1
(graphviz compatibility)
brew install graphviz
(MacOS)
pip3 install -r requirements.txt
If running into problems installing pygraphviz
:
export GRAPHVIZ_DIR="$(brew --prefix graphviz)"
pip install pygraphviz \
--config-settings=--global-option=build_ext \
--config-settings=--global-option="-I$GRAPHVIZ_DIR/include" \
--config-settings=--global-option="-L$GRAPHVIZ_DIR/lib"
Usage
Attach @visualize
decorator to the top of your recursive function and run as normal. e.g.
@visualize
def my_function(*args, **kwargs): ...
res = my_function(x=1,y=2)
draw()
Examples
Visit the examples folder to run these for yourself. Each is runnable as a standalone script within the context.
How it works (execution flow)
@visualize
def toh(args, kwargs): ...
<__name__ = __main__ context> # <-- [snapshot_1] prev on call stack
This calls visualize(func) # no impact
visualize(func) his returns inner(*args, **kwargs)
inner(*args, **kwargs) is executed # <-- [snapshot_1] cur on call stack, [snapshot_2] prev on call stack
this calls custom function toh()
toh() calls visualize(func)
this returns inner(*args, **kwargs)
inner(*args, **kwargs) is executed # <-- [snapshot_2] cur on call stack
...
A poem from our silicon friends
In the realm of code where logic flows, A concept profound like a river that knows, There lies recursion, subtle and grand, A method that holds its own hand.
Oh, recursion, you elusive sprite, A function that calls itself in the night. You start with a base case, firm and true, A stopping point in the labyrinth's view.
Within your loops, a story we find, A mirrored path of the wandering mind. You take a step forward, then call once more, Repeating the journey of those gone before.
In Fibonacci's sequence or fractal's embrace, Your essence reveals a recursive trace. The Tower of Hanoi, a puzzle unfurled, Solved by the echoes of recursive world.
Beware, dear coder, of infinite plight, Without a base case, you're lost in the night. An endless call, a stack overflow, A recursive loop with nowhere to go.
Yet with careful craft and logic precise, Recursion becomes a coder's delight. Elegant, clear, a beauty retained, A self-referential dance unchained.
So here’s to recursion, a loop within, A cycle that folds, yet begins again. In the code’s deep heart, it softly sings, The endless echo of programming’s rings.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file vizrecurse-1.1.3.tar.gz
.
File metadata
- Download URL: vizrecurse-1.1.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0bd80728053ba91d6d9612968bc37f7cc775d647f5a45e242518a8163e2a195 |
|
MD5 | a39daca5f39a246a510a020343bb416a |
|
BLAKE2b-256 | 352275f38b8298f2e4b9794f7272c2bc714605fb7a8773d51a269ae48b387cf9 |
File details
Details for the file vizrecurse-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: vizrecurse-1.1.3-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40adaefadbf405b21f122b070eb0fe2c1a1aa7290fc3853155f5facce2fc0bdf |
|
MD5 | 67dcff3347d067e7fa4f2ea1424cee2a |
|
BLAKE2b-256 | 90112bb98f33f38a5fe6e762c8d622d347dd240fbced5b6f866f8cecfde20e09 |