3

I have a large multi-file Python application I'd like to document graphically. But first, I made a small "dummy" app to test out different UML packages. (Note: I do have graphviz installed and in the path).

Here's my "dummy" code:

class User:
def __init__(self, level_security=0):
    self.level_security = level_security

def level_security_increment(level_security):
    level_security += 1
    return level_security

def printNice(aValue):
    if type(aValue) != "str":
        print(str(aValue))
    else:
        print(aValue)
    return

def main():
printNice("Process start")

for x in range(0,9):
    printNice(x)

myUser = User(3)
printNice(f"Sec lvl: {myUser.level_security}")

printNice("Process_done")

if __name__ == "__main__":
    main()

Here are the different pyreverse command-line codes I've used to get varying charts. I'll post the chart that came closest to what I want below these codes:

pyreverse test.py -S -m y -A -o png
pyreverse -ASmn test.py -b -o vdx
pyreverse -ASmy test.py -o emf
pyreverse -AS -m y test.py -o emf
pyreverse -p test.py -o emf
pyreverse -AS -b test.py -o emf
pyreverse -ASmy test.py -b -o png <-- closest

Now here is what that last one you see above produces: enter image description here

Finally, in case it is not clear, I'll reiterate what I want it to show: Classes, Definitions (functions), and - if possible - even variables. But I'd be happy for now to get just Classes and Definitions (functions). To be clear: I want to see function names.

Is it as simple as adding/removing a switch to the pyreverse command? Or is there some package I need to add to my "dummy" code?

ScotterMonkey
  • 1,007
  • 12
  • 25
  • What are you missing? The output diagrams looks complete. – qwerty_so Jul 31 '22 at 19:13
  • Thanks for asking. I want it to show: Classes, Definitions, and - if possible - even variables. – ScotterMonkey Aug 01 '22 at 11:11
  • Well, I see all of that in the diagram. Further: what is _Definition_ from your POV?? – qwerty_so Aug 01 '22 at 12:23
  • Can you please tell me where in the diagram you see level_security_increment(), printNice(), and main()? In Python a "definition" is a function. – ScotterMonkey Aug 01 '22 at 12:27
  • They have not `self` so are not considered class operations. – qwerty_so Aug 01 '22 at 12:29
  • Could there be an indentation problem in you code? It does not run as it is. If I do minimum indentation edits to get it running, it wouldn't have the level_security_increment() as member function (and it does by the way not have a self as first argument): so it's clearly not the code you've used to produce your diagram. Same question with main: is it just the first line, or is it all the subsequent lines? There are too many guesses required to reproduce the issue. – Christophe Aug 01 '22 at 15:26
  • Christophe thanks. The code runs for me. Maybe indentation got changed when I posted the code here. That said, I think both of you touched on - possibly - what is causing the lack of functions showing up being caused by need for self, yes? – ScotterMonkey Aug 01 '22 at 15:29
  • @ScotterMonkey no doubt that it's a copyu paste issue. Please compare your real code with what appears here and make the adjustments on the indentation using spaces. Keep in mind that that the four first spaces will not appear in code blocks. – Christophe Aug 01 '22 at 15:36

1 Answers1

2

pyreverse aims to produce a class diagram. It will show you classes, and non-filtered class members (see option -f), as well as associations that can be detected. In this regard, the diagram seems complete.

Instances (objects) at top level are not part of a class diagram. This is why pyreverse doesn't show them.

Free standing functions do not appear in class diagrams either as they are not classes. There is no consensus about what a free standing function should be in UML. They could be seen as instances of a more general function class (of all the functions with the same signature), or they could be considered as a specific functor class. As no UML rule is defined, pyrevere doesn't show them either. If you want pyreverse to detect them, you should rewrite them as a functor class.

Christophe
  • 68,716
  • 7
  • 72
  • 138