pythonumlclass-diagrampyreverse

How to get Class diagram from Python source code?


I try to get a class diagram from Python source code in Client folder with pyreverse but it requires __init__.py

(venv) C:\Users\User\Desktop\project> pyreverse Client
parsing Client\__init__.py...
Failed to import module Client\__init__.py with error:
No module named Client\__init__.py.

I don't find any solution for this. Is there a way to get the diagram?

Update: There are many files in Client folder:

Client.py
GUI.py
script.py
...

This is a part of the Client.py code:

import threading


class Client:
    def __init__(self):
        self.socket = None
        self.listen_socket = None
        self.buff_dict = {}
        self.message_list_dict = {}
        self.lock = threading.Lock()
        self.target = None
        self.listen_flag = True

This is a part of the GUI.py code:

import tkinter as tk


class Window(object):
    def __init__(self, title, font, client):
        self.title = title
        self.font = font
        self.client = client
        self.root = tk.Tk()
        self.root.title(title)
        self.build_window()

    def build_window(self):
        pass


class LoginWindow(Window):
    def __init__(self, client, font):
        super(LoginWindow, self).__init__('Login', font, client)
        self.build_window()

Solution

  • Thanks to @Anwarvic and @bruno, I came up with the solution for this.

    Firstly, create empty __init__.py file inside Client folder:

    (venv) C:\Users\User\Desktop\project\Client> type NUL >  __init__.py
    

    Then go to the parent folder of the Client folder where I want to get the class diagram:

    (venv) C:\Users\User\Desktop\project> pyreverse Client -o png
    

    But I got this error:

    The output format 'png' is currently not available.
    Please install 'Graphviz' to have other output formats than 'dot' or 'vcg'.
    

    After some findings, I found this solution. Then I can run the pyreverse without any error.

    This is the class diagram I got using pyreverse:

    enter image description here