The purpose of this blog is to happily share my learning and ideas to help people, who actively seek solutions for the day-to-day problems faced.

Recent Posts

Using 'pyplantuml' - Creates UML diagrams (package and class structure) from Python source code

PyPlantUML:

PyPlantUML python package helps to get UML diagram for existing python test case and its respective libraries, thus it helps to understand the actual test case. Please refer the "Sample UML Diagram" below for better understanding,
Sample UML Diagram
Without any further delay let us jump straight into it and get our hands dirty, When I was using the package for the first time I have faced many issues and overcome the same but when searching for solutions it was very limited. Hence I'm sharing the problems faced and solutions for the same, so that it will help others as well,

Please find below the steps to make it work,

Official git repository:
https://github.com/cb109/pyplantuml

Dependencies:
1. pylint (can be installed via pip)
2. plantuml (can be downloaded from the link http://plantuml.com/ under download section)

Installation:
pip install pyplantuml
Issues faced:
Due to pylint package

Error:
$ sudo pip install pyplantuml
Collecting pyplantuml
  Downloading https://files.pythonhosted.org/packages/fb/66/1b53e89aff28f08732a8add33d048eaa9c85b37d4ba57d9252001657b3fc/pyplantuml-0.1.51.zip
Collecting astroid==1.3.2 (from pyplantuml)
  Downloading https://files.pythonhosted.org/packages/33/af/d766e486db232eb562429588bcfa4163684656f04b6e2f66885d897771cb/astroid-1.3.2-py2.py3-none-any.whl (163kB)
    100% |████████████████████████████████| 174kB 4.9MB/s
Collecting pylint==1.4 (from pyplantuml)
  Downloading https://files.pythonhosted.org/packages/d2/f0/814efdfcda086aacf010f46a4dd5f58ba008baf2b40d2976f3646bae9f83/pylint-1.4.0-py2.py3-none-any.whl (412kB)
    100% |████████████████████████████████| 419kB 5.5MB/s
Requirement already satisfied: logilab-common>=0.60.0 in /usr/lib/python2.7/dist-packages (from astroid==1.3.2->pyplantuml) (1.1.0)
Requirement already satisfied: six in /usr/lib/python2.7/dist-packages (from astroid==1.3.2->pyplantuml) (1.10.0)
Building wheels for collected packages: pyplantuml
  Running setup.py bdist_wheel for pyplantuml ... done
  Stored in directory: /root/.cache/pip/wheels/8a/a5/13/74e689971092e69950f359bfb2e9ad97322ac5ab4ca6daf55b
Successfully built pyplantuml
Installing collected packages: astroid, pylint, pyplantuml
  Found existing installation: astroid 1.4.4
    Uninstalling astroid-1.4.4:
      Successfully uninstalled astroid-1.4.4
  Found existing installation: pylint 1.5.2
Cannot uninstall 'pylint'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Resolution:
Remove the pylint disutil as shown below,
$ sudo apt-get remove pylint
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-138 linux-headers-4.4.0-138-generic linux-headers-4.4.0-139 linux-headers-4.4.0-139-generic linux-image-4.4.0-138-generic
  linux-image-4.4.0-139-generic python-astroid python-cffi-backend python-egenix-mxdatetime python-egenix-mxtools python-idna python-ipaddress
  python-lazy-object-proxy python-logilab-common python-wrapt
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  pylint
0 upgraded, 0 newly installed, 1 to remove and 183 not upgraded.
After this operation, 891 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 247115 files and directories currently installed.)
Removing pylint (1.5.2-1ubuntu1) ...
Remove pylint for emacs24
remove/pylint: purging byte-compiled files for emacs24
Processing triggers for man-db (2.7.5-1) ...
Now try to install pyplantuml again and you are good to go,
$ sudo pip install pyplantuml
Collecting pyplantuml
Collecting pylint==1.4 (from pyplantuml)
  Using cached https://files.pythonhosted.org/packages/d2/f0/814efdfcda086aacf010f46a4dd5f58ba008baf2b40d2976f3646bae9f83/pylint-1.4.0-py2.py3-none-any.whl
Requirement already satisfied: astroid==1.3.2 in /usr/local/lib/python2.7/dist-packages (from pyplantuml) (1.3.2)
Requirement already satisfied: logilab-common>=0.53.0 in /usr/lib/python2.7/dist-packages (from pylint==1.4->pyplantuml) (1.1.0)
Requirement already satisfied: six in /usr/lib/python2.7/dist-packages (from pylint==1.4->pyplantuml) (1.10.0)
Installing collected packages: pylint, pyplantuml
Successfully installed pylint-1.4.0 pyplantuml-0.1.51
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Usage:
cd <parent-dir-of-package>
pyplantuml [options] <package>
Issues faced:
Could not find a plantuml.jar on PATH.

Solution:
Add the below line at the end of your .bashrc file
export PATH=$PATH:$HOME/path_to_jar_file
and source the bashrc file as shown below,
source ~/.bashrc
Now try again,
$ pyplantuml clone.py
parsing clone.py...
clone.py_classes.txt
java.io.IOException: Cannot run program "/opt/local/bin/dot": error=2, No such file or directory
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
        at java.lang.Runtime.exec(Runtime.java:620)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.startThreads(ProcessRunner.java:163)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.runJob(ProcessRunner.java:123)
        at net.sourceforge.plantuml.api.TimeoutExecutor$MyThread.run(TimeoutExecutor.java:79)
Caused by: java.io.IOException: error=2, No such file or directory
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
        at java.lang.ProcessImpl.start(ProcessImpl.java:134)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        ... 4 more
java.io.IOException: Cannot run program "/opt/local/bin/dot": error=2, No such file or directory
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
        at java.lang.Runtime.exec(Runtime.java:620)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.startThreads(ProcessRunner.java:163)
        at net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner$MainThread.runJob(ProcessRunner.java:123)
        at net.sourceforge.plantuml.api.TimeoutExecutor$MyThread.run(TimeoutExecutor.java:79)
Caused by: java.io.IOException: error=2, No such file or directory
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
        at java.lang.ProcessImpl.start(ProcessImpl.java:134)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        ... 4 more
sh: 1: clone.py_classes.png: not found
Created: clone.py_classes.png
Issues faced:
This is because of the script not able to find the installation of GraphViz package

Solution:
Install the GraphViz package from your OS repository as show below,
$ sudo apt-get install graphviz
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-138 linux-headers-4.4.0-138-generic linux-headers-4.4.0-139 linux-headers-4.4.0-139-generic linux-image-4.4.0-138-generic
  linux-image-4.4.0-139-generic python-astroid python-cffi-backend python-egenix-mxdatetime python-egenix-mxtools python-idna python-ipaddress
  python-lazy-object-proxy python-logilab-common python-wrapt
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  fonts-liberation libcdt5 libcgraph6 libgvc6 libgvpr2 libpathplan4 libxaw7 libxmu6
Suggested packages:
  graphviz-doc
The following NEW packages will be installed:
  fonts-liberation graphviz libcdt5 libcgraph6 libgvc6 libgvpr2 libpathplan4 libxaw7 libxmu6
0 upgraded, 9 newly installed, 0 to remove and 191 not upgraded.
Need to get 2,583 kB of archives.
After this operation, 15.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://pxe.dev.com/ubuntu xenial/main amd64 fonts-liberation all 1.07.4-1 [829 kB]
Get:2 http://pxe.dev.com/ubuntu xenial-updates/main amd64 libcdt5 amd64 2.38.0-12ubuntu2.1 [23.4 kB]
Get:3 http://pxe.dev.com/ubuntu xenial-updates/main amd64 libcgraph6 amd64 2.38.0-12ubuntu2.1 [43.6 kB]
Get:4 http://pxe.dev.com/ubuntu xenial-updates/main amd64 libpathplan4 amd64 2.38.0-12ubuntu2.1 [26.6 kB]
Get:5 http://pxe.dev.com/ubuntu xenial-updates/main amd64 libgvc6 amd64 2.38.0-12ubuntu2.1 [591 kB]
Get:6 http://pxe.dev.com/ubuntu xenial-updates/main amd64 libgvpr2 amd64 2.38.0-12ubuntu2.1 [170 kB]
Get:7 http://pxe.dev.com/ubuntu xenial/main amd64 libxmu6 amd64 2:1.1.2-2 [46.0 kB]
Get:8 http://pxe.dev.com/ubuntu xenial/main amd64 libxaw7 amd64 2:1.0.13-1 [173 kB]
Get:9 http://pxe.dev.com/ubuntu xenial-updates/main amd64 graphviz amd64 2.38.0-12ubuntu2.1 [680 kB]
Fetched 2,583 kB in 0s (39.2 MB/s)
Selecting previously unselected package fonts-liberation.
(Reading database ... 247038 files and directories currently installed.)
Preparing to unpack .../fonts-liberation_1.07.4-1_all.deb ...
Unpacking fonts-liberation (1.07.4-1) ...
Selecting previously unselected package libcdt5.
Preparing to unpack .../libcdt5_2.38.0-12ubuntu2.1_amd64.deb ...
Unpacking libcdt5 (2.38.0-12ubuntu2.1) ...
Selecting previously unselected package libcgraph6.
Preparing to unpack .../libcgraph6_2.38.0-12ubuntu2.1_amd64.deb ...
Unpacking libcgraph6 (2.38.0-12ubuntu2.1) ...
Selecting previously unselected package libpathplan4.
Preparing to unpack .../libpathplan4_2.38.0-12ubuntu2.1_amd64.deb ...
Unpacking libpathplan4 (2.38.0-12ubuntu2.1) ...
Selecting previously unselected package libgvc6.
Preparing to unpack .../libgvc6_2.38.0-12ubuntu2.1_amd64.deb ...
Unpacking libgvc6 (2.38.0-12ubuntu2.1) ...
Selecting previously unselected package libgvpr2.
Preparing to unpack .../libgvpr2_2.38.0-12ubuntu2.1_amd64.deb ...
Unpacking libgvpr2 (2.38.0-12ubuntu2.1) ...
Selecting previously unselected package libxmu6:amd64.
Preparing to unpack .../libxmu6_2%3a1.1.2-2_amd64.deb ...
Unpacking libxmu6:amd64 (2:1.1.2-2) ...
Selecting previously unselected package libxaw7:amd64.
Preparing to unpack .../libxaw7_2%3a1.0.13-1_amd64.deb ...
Unpacking libxaw7:amd64 (2:1.0.13-1) ...
Selecting previously unselected package graphviz.
Preparing to unpack .../graphviz_2.38.0-12ubuntu2.1_amd64.deb ...
Unpacking graphviz (2.38.0-12ubuntu2.1) ...
Processing triggers for fontconfig (2.11.94-0ubuntu1.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up fonts-liberation (1.07.4-1) ...
Setting up libcdt5 (2.38.0-12ubuntu2.1) ...
Setting up libcgraph6 (2.38.0-12ubuntu2.1) ...
Setting up libpathplan4 (2.38.0-12ubuntu2.1) ...
Setting up libgvc6 (2.38.0-12ubuntu2.1) ...
Setting up libgvpr2 (2.38.0-12ubuntu2.1) ...
Setting up libxmu6:amd64 (2:1.1.2-2) ...
Setting up libxaw7:amd64 (2:1.0.13-1) ...
Setting up graphviz (2.38.0-12ubuntu2.1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Once the installation is done successfully, try executing the pyplantuml again and here you are presented with your corresponding .png file containing the UML relationship,
$ pyplantuml vvol_clone.py
parsing vvol_clone.py...
Created: /home/clone.py_classes.txt
sh: 1: clone.py_classes.png: not found
Created: /home/clone.py_classes.png
Make use of the png file. Cheers

1 comment: