I have this code repo
I created manual UML which look like this:
I am trying to auto generate the UML via pyreverse:
pyreverse -o png -p ShoppingCart ./mainService.py
Format png is not supported natively. Pyreverse will try to generate it using Graphviz...
Unfortunately, it gives me blank diagram. What can I do to get the project's classes in the diagram?
This is the file structure:
.
├── Entity
│ ├── Apple.py
│ ├── Buy1Get1FreeApple.py
│ ├── Buy3OnPriceOf2Orange.py
│ ├── Offer.py
│ ├── Orange.py
│ ├── Product.py
│ └── ShoppingCart.py
├── Enum
│ └── ProductType.py
└── mainService.py
Assuming the installation of pyreverse and graphviz is correct, all you need to do is to package your project adding some emplty __init__py files in each folder. Alternatively, you'd hjhave to add all the modules manually in the command line.
Assuming everything is installed correctly, your command line should give you the warning message, which is absolutely normal:
Format png is not supported natively. Pyreverse will try to generate it using Graphviz...
The diagram will stay empty because you tell pyreverse to analyse a single file and there is no class defined in that file. If you'd add manually the different modules to be analysed:
pyreverse -o png -p ShoppingCart mainService.py Entity\Apple.py Enum\ProductType.py Entity\Orange.py Entity\ShoppingCart.py
you would then very well obtain a rudimentary diagram:
If you would add the options -AS
upfront you'd get all ancestors in the project and all associated classes recursively:
This is cumbersome. Fortunately, there's little missing to package your project. For a full reference, you may look here. But in short, it is sufficient to add an empty __init__.py
file in your project folder, and each subfolder where you store the modules:
.
├── Entity
│ ├── __init__.py <<===== add this empty file
│ ├── Apple.py
│ ├── Buy1Get1FreeApple.py
│ ├── Buy3OnPriceOf2Orange.py
│ ├── Offer.py
│ ├── Orange.py
│ ├── Product.py
│ └── ShoppingCart.py
├── Enum
│ ├── __init__.py <<===== add this empty file
│ └── ProductType.py
├── __init__.py <<===== add this empty file
└── mainService.py
You will then be able to run the simpler command line:
pyreverse -AS -o png -p ShoppingCart .
and obtain this magnificient diagram:
The packaging helps python and pyreverse to understand that these are not files to be analysed in isolation, but in the context of a package made of subpackages, etc.