Last active
March 7, 2021 19:23
-
-
Save t4n1o/87a8949589e1aefd6542f1887fd654d3 to your computer and use it in GitHub Desktop.
pyverse automation into docs/uml folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
"""A script to make UML diagrams out of python source code and saves it to the docs directory. | |
For this to work you need to first install: | |
-pylint | |
`python3 -m pip install pylint` | |
-graphviz | |
`sudo apt-get install graphviz` | |
""" | |
import shutil | |
import pathlib | |
import os | |
# Configuration | |
UML_PATH = pathlib.Path.cwd() / 'docs' / 'UML' # Where to save the output files | |
PACKAGE_NAME = 'calculator' | |
EXCLUDE = ['__init__.py'] | |
# Start of the script | |
cwd = pathlib.Path.cwd() | |
print(f'Current Working Directory: {cwd}') | |
print('Making directories...') | |
UML_PATH.mkdir(mode=0o777, parents=True, exist_ok=True) | |
project_doc_path = UML_PATH / PACKAGE_NAME | |
project_doc_path.mkdir(mode=0o777, parents=True, exist_ok=True) | |
# Make the main file that includes everything | |
os.system(f"pyreverse -f ALL -Amy {PACKAGE_NAME} -o png -p {PACKAGE_NAME}") | |
shutil.move(f"./classes_{PACKAGE_NAME}.png", UML_PATH / f'classes_{PACKAGE_NAME}.png') | |
shutil.move(f"./packages_{PACKAGE_NAME}.png", UML_PATH / f'packages_{PACKAGE_NAME}.png') | |
# Recursively go through every single file finding .py files and making detailed diagrams for them: | |
p = pathlib.Path(PACKAGE_NAME) | |
for src_file in p.rglob('*'): | |
if src_file.suffix == '.py' and src_file.name not in EXCLUDE: | |
print(src_file) | |
a_path = UML_PATH / src_file.name / '.png' | |
os.system(f"pyreverse -f ALL -ASmy {src_file} -o png") | |
shutil.move("./classes.png", UML_PATH / src_file.with_suffix('.png')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment