from pathlib import Path result = list(Path("../cerc_persistence/cerc_persistence/models").rglob("*.[pP][yY]")) dot_file = './source/uml.dot' dot = 'digraph { \n ratio="fill"; \nsize="16.6,23.4!";\nmargin=0; \n \n' class_line = None for file_path in result: with open(file_path) as file: lines = file.readlines() for line in lines: if 'class ' == line[0:6]: line = line.replace('class ', '"')\ .replace(':', '"')\ .replace('(', '" -> "')\ .replace(')', '"[arrowhead="empty"] ')\ .replace(' "', '')\ .replace('->', '-> "') class_line = line if ' -> ' in line: class_line = line.split(' -> ')[0] if '"City"' == line[0:6]: line = line[0:6] + ' [pos="0,1!"]\n' dot += line if 'def ' in line[2:8]: if ' -> ' in line: reference = line.split(' -> ')[1].replace(':', '').strip(' ()[]{},').replace('\n', '') reference = reference.replace('Union', '').replace('List', '').replace('float', '').replace('str', '') reference = reference.replace('bool', '').replace('None', '').replace(',', '') reference = reference.replace(' ', '').replace('np.ndarray', '').replace('dict', '') reference = reference.replace('[', '').replace(']', '').replace('Path', '').replace('pd.DataFrame', '') reference = reference.replace('Trimesh', '').replace('}', '').replace('Edge)', '') reference = reference.replace('(', '').replace(')', '') if 'Point' not in reference: reference = reference.replace('int', '') if reference != '': dot += f'"{reference}"-> {class_line}[arrowhead="diamond"] ' dot += '}' with open(dot_file, 'w') as file: file.write(dot.replace(' \n', ' ').replace('\n', ' ').replace('ABC, ', '').replace(' " ', ' '))