Skip to content

Pyreverse: print package import stats #8974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 31, 2023

Conversation

nickdrozd
Copy link
Contributor

Type of Changes

Type
✨ New feature

Description

Here is what Pyreverse currently prints:

$ pyreverse pylint/pyreverse/
parsing pylint/pyreverse/__init__.py...
parsing /home/nick/pylint/pylint/pyreverse/inspector.py...
parsing /home/nick/pylint/pylint/pyreverse/plantuml_printer.py...
parsing /home/nick/pylint/pylint/pyreverse/printer.py...
parsing /home/nick/pylint/pylint/pyreverse/mermaidjs_printer.py...
parsing /home/nick/pylint/pylint/pyreverse/writer.py...
parsing /home/nick/pylint/pylint/pyreverse/__init__.py...
parsing /home/nick/pylint/pylint/pyreverse/dot_printer.py...
parsing /home/nick/pylint/pylint/pyreverse/main.py...
parsing /home/nick/pylint/pylint/pyreverse/printer_factory.py...
parsing /home/nick/pylint/pylint/pyreverse/diadefslib.py...
parsing /home/nick/pylint/pylint/pyreverse/utils.py...
parsing /home/nick/pylint/pylint/pyreverse/diagrams.py...

Here is what it prints with this change:

$ pyreverse pylint/pyreverse/
Modules: 12
Imports: 25

There are many ways this could be changed, but I think this is a good first attempt for more useful printing.

Closes #8973

@nickdrozd nickdrozd requested a review from DudeNr33 as a code owner August 23, 2023 14:47
@Pierre-Sassoulas Pierre-Sassoulas added the Needs review 🔍 Needs to be reviewed by one or multiple more persons label Aug 23, 2023
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong opinion about this but I'm not sure it's better than before. When debugging counting the module is bothersome, and you don't need that info when not debugging. Introducing a verbose option would be better imo.

Copy link
Collaborator

@DudeNr33 DudeNr33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think there can be value in printing the module names.
But it not necessarily needs to be the "default", and having the stats is also quite nice.

My suggestion would be:

  • keep the stats and output them by default
  • add a verbose option
  • output the module names only in verbose mode

@nickdrozd
Copy link
Contributor Author

nickdrozd commented Aug 24, 2023

Sounds good! I'll update this PR with a force-push.

@nickdrozd
Copy link
Contributor Author

Updated the PR to add a --verbose flag. New output:

$ pyreverse pylint/pyreverse/
Modules: 12
Imports: 25
$ pyreverse --verbose pylint/pyreverse/
parsing pylint/pyreverse/__init__.py...
parsing /home/nick/pylint/pylint/pyreverse/inspector.py...
parsing /home/nick/pylint/pylint/pyreverse/plantuml_printer.py...
parsing /home/nick/pylint/pylint/pyreverse/printer.py...
parsing /home/nick/pylint/pylint/pyreverse/mermaidjs_printer.py...
parsing /home/nick/pylint/pylint/pyreverse/writer.py...
parsing /home/nick/pylint/pylint/pyreverse/__init__.py...
parsing /home/nick/pylint/pylint/pyreverse/dot_printer.py...
parsing /home/nick/pylint/pylint/pyreverse/main.py...
parsing /home/nick/pylint/pylint/pyreverse/printer_factory.py...
parsing /home/nick/pylint/pylint/pyreverse/diadefslib.py...
parsing /home/nick/pylint/pylint/pyreverse/utils.py...
parsing /home/nick/pylint/pylint/pyreverse/diagrams.py...
Modules: 12
Imports: 25

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty good already, just some nits 👍

Comment on lines 107 to 108
print(f"Modules: {len(module_info)}")
print(f'Imports: {sum(mod["imports"] for mod in module_info.values())}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it should be in non verbose mode but I'll let Andreas decide.

Suggested change
print(f"Modules: {len(module_info)}")
print(f'Imports: {sum(mod["imports"] for mod in module_info.values())}')
if verbose: # TODO add verbose in this function parameters if we do that
print(f"Modules: {len(module_info)}")
print(f'Imports: {sum(mod["imports"] for mod in module_info.values())}')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought was to print that by default. After all, it isn't debugging information, it's just information. There are questions about module relations that Pyreverse is well-suited to answer since it's looking at module relations anyway. So I figure, why not print it?

There are lots of other stats that could be added. Which module is the most / least imported? Which module has the most / fewest imports? How many transitive dependencies are there? I've found that some design and organization improvements can reveal themselves through investigating anomalous import stats.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess clever warning about module stats should go in pylint or another standalone tool (there's a bunch of clever high level design check that are only in the litterature on arxiv or design books) . I see pyreverse more as a graphical display of uml diagram

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the output I would print it by default, I feel it gives a nice concise feedback how much was analysed.
What do you think of printing it like "Analysed X modules with a total of Y imports"?
Alternatively at least:

Analysed modules: X
Total imports: Y

As for the other stats, I agree with Pierre. This can be very useful information, but I don't think it belongs in pyreverse. If at all in Pylint and not a dedicated design. checker, it would be more of a use case for a report.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like "Analysed X modules with a total of Y imports" in one line 👍

@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #8974 (15b0118) into main (cb82423) will increase coverage by 0.00%.
Report is 2 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8974   +/-   ##
=======================================
  Coverage   95.75%   95.76%           
=======================================
  Files         173      173           
  Lines       18604    18616   +12     
=======================================
+ Hits        17815    17827   +12     
  Misses        789      789           
Files Changed Coverage Δ
pylint/pyreverse/main.py 93.87% <ø> (ø)
pylint/pyreverse/inspector.py 79.89% <100.00%> (+0.10%) ⬆️
pylint/pyreverse/writer.py 100.00% <100.00%> (ø)

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component pyreverse Related to pyreverse component and removed Needs review 🔍 Needs to be reviewed by one or multiple more persons labels Aug 25, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.0.0a8 milestone Aug 25, 2023
@DudeNr33
Copy link
Collaborator

To test the verbose option and bump the coverage you may take a look at how other tests checking the output of running pyreverse are done, for example here:

https://github.dev/nickdrozd/pylint/blob/9ca26d9e3e643f2a18fe253548903c8273bf7854/tests/pyreverse/test_main.py#L93-L108

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Collaborator

@DudeNr33 DudeNr33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the addition, and sorry for the delay in review!

@DudeNr33 DudeNr33 merged commit dcebc74 into pylint-dev:main Aug 31, 2023
@nickdrozd nickdrozd deleted the pyreverse-printing branch October 7, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component pyreverse Related to pyreverse component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More useful printing for Pyreverse
3 participants