Graphviz

予早 2025-02-21 01:08:24
Categories: Tags:

https://www.graphviz.org/

https://www.graphviz.org/download/

安装完成后,bin配置到PATH

验证

# 查看版本
dot -V
pip install graphviz
# https://github.com/gak/pycallgraph
# 不再维护
pip install pycallgraph

# https://github.com/Lewiscowles1986/py-call-graph
pip install python-call-graph

用法一

from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput


class Calculator:
    def __init__(self):
        self.result = 0

    def add(self, a, b):
        self.result = a + b
        return self.result

    def subtract(self, a, b):
        self.result = a - b
        return self.result


def get_numbers():
    num1 = float(input("Enter the first number: "))
    num2 = float(input("Enter the second number: "))
    return num1, num2


def main():
    calc = Calculator()
    num1, num2 = get_numbers()

    print("1. Add")
    print("2. Subtract")
    choice = input("Choose an operation (1/2): ")

    if choice == '1':
        result = calc.add(num1, num2)
        print(f"The result is: {result}")
    elif choice == '2':
        result = calc.subtract(num1, num2)
        print(f"The result is: {result}")
    else:
        print("Invalid choice")


if __name__ == "__main__":
    with PyCallGraph(output=GraphvizOutput()):
        main()

在执行结束之后会生成流程图

用法二,执行命令行

pycallgraph graphviz – main.py

Windows上不太行

pip install pylint

生成UML 类图

pyreverse  -o pdf main.py