-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Pyreverse autocolor #4521
Pyreverse autocolor #4521
Conversation
Distinguish modules and packages.
…ibute in VCGPrinter
…modules is checked
… test does not work in tox env
…hod ``get_package_properties``. Rename ``get_values`` to ``get_class_properties``. VCGWriter and VCGPrinter thus no longer need special handling.
Add ChangeLog and whatsnew entry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey sorry for the delay in order to review. This looks nice and well tested, I think the pytest fixture were probably not used before (I see import from unittest_pyreverse_writer
that would not happen if there were proper fixtures already). You can do a small refactor to move to pytest first if you have time for that or simply introduce a default_config
fixture instead of the new _DEFAULT
import.
@@ -123,7 +153,41 @@ def get_title(self, obj): | |||
"""get project title""" | |||
return obj.title | |||
|
|||
def get_values(self, obj): | |||
def get_style(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_style(self): | |
def get_style(self) -> str: |
Could you add typing on new functions please ? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
def get_values(self, obj): | ||
def get_package_properties(self, obj): | ||
"""get label and shape for packages.""" | ||
return dict( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use NamedTuple
(or a child class) here, so we can have proper typing and not use dict everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that a NamedTuple would be the cleaner solution. However, the current (as in: this PR) implementation of the DiagramWriter
class and implementations of DotBackend
and VCGPrinter
do not allow for this. DotBackend
and VCGPrinter
rely on the data returned by the get_package_properties
and get_class_properties
methods, and the data structures they require are not the same.
That being said: I have already started working on the PlantUML backend, and while doing so I extracted a common interface for the Printer
classes. Using a NamedTuple
should be possible then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your other comment, it your implementation of plantuml make you upgrade the code with NamedTuple and proper typing it will be nice to rebase on it once it's merged.
@@ -21,7 +21,7 @@ | |||
|
|||
import astroid | |||
import pytest | |||
from unittest_pyreverse_writer import Config, get_project | |||
from unittest_pyreverse_writer import _DEFAULTS, Config, get_project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be defined in conftest.py
and used as a pytest fixtures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be a good idea to keep the dependencies of the test modules as minimal as possible. I will do that.
No problem, I fully understand that As I noted above, I already started working on the PlantUML implementation, and introducing |
@Pierre-Sassoulas quick question - I extracted the tests into a separate subdirectory and added a new
As |
It's a known problem with mypy, I don't know if you can exclude the file, if you can that's great, and I did not think of that because last time I put all my fixtures |
Yes, excluding works fine via the - repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
hooks:
- id: mypy
name: mypy
entry: mypy
language: python
types: [python]
args: ["--ignore-missing-imports", "--scripts-are-modules"]
require_serial: true
additional_dependencies: []
exclude: tests/functional/|tests/input|tests/extensions/data|tests/regrtest_data/|conftest.py|doc/|bin/ |
Ha good to know, thanks ! Maybe we can ignore only some of them and keep analyzing |
I see, being able to at least type check one |
Hey, just a heads up, we just merged #4551 so you'll probably want to rebase :) |
Thanks Pierre, I just submitted the new PR which also includes this feature as well as the requested changes in the review. |
Steps
doc/whatsnew/<current release.rst>
.Description
Running
pyreverse
on large projects can lead to diagrams with low clarity. Classes or modules might be scattered across the diagram.By coloring the diagrams, modules or classes of the same package can be easily spotted visually. For an example, see issue #4488.
This new feature is optional and can be activated by passing the
--colorized
option.The granularity can be influenced by passing
--max-color-depth
.Classes/modules from the standard library are always colored in grey.
However, this seems to not work reliably, at least it did not work inside the tox test environments (I therefore had to delete the unittest for it). It worked great in my venv that I use for development.
This feature only works with dot output. I could not find a suitable program that correctly displays the vcg files.
As there were no unittests for the VCG output as well (are VCG graphs even still a thing? Google finds relatively few discussions for it...), I chose to not implement it for this output format.
I added a regression test which ensures that the VCG files produced with the current Pylint release and after this PR are the same.
Type of Changes
Related Issue
Closes #4488