Program that provides diagrams for documentation The general problem I'm trying to solve is that I have a code base that has zero documentation so I'm trying to automatically generate some diagrams of classes in package that I'm analyzing using erdantic.
Trying to make this as reusable as possible, so I have a generate_diagrams() function that should take in one argument, which is the package I want to iterate through.
I often feel like I throw the terms module and package around interchangeably — I might be doing it now — so I defaulted my argument to the name &quot;directory&quot;.  But I feel that's not right since I'm not passing in a path.
Should I change the argument in generate_diagrams() below? What's a more accurate name?
import erdantic as erd
import glob
import importlib
import example.models

from os import path, makedirs


def draw_diagram(module, cls_name, output_path):
    &quot;&quot;&quot;

    Args:
        module: module object
        cls_name: name of the class that's associated with  the module
        output_path: path where diagram to be saved

    Returns:
        void - outputs .png file at given path

    &quot;&quot;&quot;
    try:
        diagram = erd.create(module.__getattribute__(cls_name))
        diagram.models
        diagram.draw(f&quot;{output_path}/{cls_name}.png&quot;)

    except erd.errors.UnknownModelTypeError:
        pass


def generate_diagrams(directory):
    &quot;&quot;&quot;

    Args:
        directory: package you have imported that contains module(s) you wish to diagram

    Returns:
        void - generates diagram using draw_diagram function

    &quot;&quot;&quot;

    doc_path = path.dirname(__file__)
    modules = glob.glob(path.join(path.dirname(directory.__file__), &quot;*.py&quot;))
    module_names = [path.basename(f)[:-3] for f in modules if path.isfile(f) and not f.endswith('__init__.py')]

    for module_name in module_names:

        if not path.exists(path.join(doc_path, module_name)):
            print(f'Making {module_name} directory')
            makedirs(module_name)

        module = importlib.import_module(f'{directory.__name__}.{module_name}')
        classes = dict([(name, cls) for name, cls in module.__dict__.items() if isinstance(cls, type)])

        for name, cls in classes.items():
            print(f'Drawing {module_name}.{name} diagram')
            draw_diagram(module, cls_name=name, output_path=path.join(doc_path, module_name))


def main():
    generate_diagrams(directory=example.models)


if __name__ == &quot;__main__&quot;:
    main()
The Doxygen recommendation notwithstanding,

Consider adding PEP484 type hints, particularly to the signatures of functions such as draw_diagram. For that method, it's not really correct Python terminology to call the return value &quot;void&quot; - it's None.
Does the single-expression statement diagram.models actually have any effect? If so that deserves a comment.
Rather than glob.glob consider pathlib.Path.glob which has some usage niceties
path.basename(f)[:-3] is a very fragile way of acquiring a stem. Again, pathlib.Path can do a better job.

The line
dict([(name, cls) for name, cls in module.__dict__.items() if isinstance(cls, type)])

first of all should not use an inner list, since dict can directly accept a generator; and secondly would be better-represented as a dictionary comprehension:
{name: cls for name, cls in module.__dict__.items() if isinstance(cls, type)}

This loop:
    for name, cls in classes.items():
        print(f'Drawing {module_name}.{name} diagram')
        draw_diagram(module, cls_name=name, output_path=path.join(doc_path, module_name))

doesn't actually use cls, so should only iterate over the dictionary's keys, not its items.