Skip to content
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

Pyreverse: Use dashed lines for type-checking imports #8824

Merged

Conversation

nickdrozd
Copy link
Collaborator

@nickdrozd nickdrozd commented Jul 4, 2023

Type of Changes

Type
✨ New feature

Description

This PR modifies the Pyreverse package diagram generator so that if module A only imports from module B under the TYPE_CHECKING flag, an empty arrow is used.

Closes #8112

Here is an example of the output:

packages

In this diagram, the instrs module is only imported for type checking, the tape module is sometimes imported for type checking and sometimes imported for real, and the rest of the modules are all imported for real.

There is an interesting interaction with the (still unreleased) --no-standalone option. Namely, a module only imported for type checking appears as a ghost module:

packages

I hadn't considered this in my implementation, but I think it actually works out pretty well.

TODO

  • Documentation
  • Testing
  • Add output for writers other than dot.

@nickdrozd nickdrozd requested a review from DudeNr33 as a code owner July 4, 2023 20:17
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.

Those "empty arrows" have a meaning in UML it means generalization, i.e. "inherit from". The proper UML convention needs to be used, possibly dotted line with the same arrow for "dependency" see (14) here : https://stackoverflow.com/a/2293763/2519059.

@codecov
Copy link

codecov bot commented Jul 4, 2023

Codecov Report

Merging #8824 (abcfcc2) into main (f815e9f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8824   +/-   ##
=======================================
  Coverage   95.89%   95.90%           
=======================================
  Files         173      173           
  Lines       18511    18523   +12     
=======================================
+ Hits        17752    17765   +13     
+ Misses        759      758    -1     
Impacted Files Coverage Δ
pylint/pyreverse/dot_printer.py 85.86% <ø> (ø)
pylint/pyreverse/mermaidjs_printer.py 98.18% <ø> (ø)
pylint/pyreverse/plantuml_printer.py 100.00% <ø> (ø)
pylint/pyreverse/diagrams.py 93.10% <100.00%> (+0.93%) ⬆️
pylint/pyreverse/inspector.py 79.79% <100.00%> (+0.10%) ⬆️
pylint/pyreverse/printer.py 100.00% <100.00%> (ø)
pylint/pyreverse/writer.py 100.00% <100.00%> (ø)

@Pierre-Sassoulas Pierre-Sassoulas added the pyreverse Related to pyreverse component label Jul 4, 2023
@github-actions

This comment has been minimized.

@nickdrozd nickdrozd added the Enhancement ✨ Improvement to a component label Jul 5, 2023
@nickdrozd
Copy link
Collaborator Author

Using dashed lines instead for type-checking-only dependencies:

packages

@nickdrozd nickdrozd changed the title Pyreverse: Use empty arrows for type-checking imports Pyreverse: Use dashed lines for type-checking imports Jul 5, 2023
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@nickdrozd
Copy link
Collaborator Author

@DudeNr33 Something is off with the tests, but I can't what it is. There's some kind of interference with clientmodule_test, but I don't know where it's coming from.

@DudeNr33
Copy link
Collaborator

DudeNr33 commented Jul 5, 2023

We currently do not have a equivalent to the functional test of class diagrams for package diagrams.
The current tests are configured to create diagrams for the packages/modules found under tests/data:

@pytest.fixture()
def setup_type_check_imports_dot(
    type_check_imports_dot_config: PyreverseConfig, get_project: GetProjectCallable
) -> Iterator[None]:
    writer = DiagramWriter(type_check_imports_dot_config)
    project = get_project(TEST_DATA_DIR, name="type_check_imports")
    yield from _setup(project, type_check_imports_dot_config, writer)

The first argument to get_project is the directory to analyze.
The content of your packages_type_check_imports.dot however looks like it expects the result of analyzing tests/pyreverse/functional/package_diagrams.

The cleanest solution would probably be to come up with a working functional test harness for package diagrams as well.

@github-actions

This comment has been minimized.

Comment on lines 317 to 318
except KeyError:
continue
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These two lines are uncovered, and I don't know how to cover them. Any ideas? They could also be cut, or just ignore the coverage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The check is definitely required. But I can't figure out exactly what triggers it.

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 think this look dope, great change (especially in conjunction with the other option) ! Although I would appreciate a second / third opinion regarding the UML symbolic before we commit to it.

@Pierre-Sassoulas Pierre-Sassoulas added the Needs review 🔍 Needs to be reviewed by one or multiple more persons label Jul 6, 2023
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@DudeNr33
Copy link
Collaborator

DudeNr33 commented Jul 7, 2023

I think this look dope, great change (especially in conjunction with the other option) ! Although I would appreciate a second / third opinion regarding the UML symbolic before we commit to it.

I am not an UML expert myself, but the link you provided sounds pretty reasonable to me!

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 Nick for the new feature. I like it.

I left some remarks.

I also think we should try to introduce real functional package diagram tests rather sooner than later after this PR. The functional tests for class diagram work more or less the same as the functional tests for messages - that is, you only need to create the input, output, and optionally config file and they will be picked up automatically in the test run.
This is not yet the case for the files below functional/package_diagram, but the naming convention could make you believe it is.

pylint/pyreverse/printer.py Outdated Show resolved Hide resolved
tests/pyreverse/conftest.py Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

@DudeNr33 DudeNr33 removed the Needs review 🔍 Needs to be reviewed by one or multiple more persons label Jul 9, 2023
@DudeNr33
Copy link
Collaborator

DudeNr33 commented Jul 9, 2023

codecov seems to be stuck. @Pierre-Sassoulas what's the best fix for this? Close/reopen the PR?

@Pierre-Sassoulas
Copy link
Member

Yeah, let's try !

@Pierre-Sassoulas
Copy link
Member

There's some trickery with astroid's version but I'm not sure why readthedoc alone fail. Maybe bad caching. I'm half inclined to "just merge it ™️".

@Pierre-Sassoulas
Copy link
Member

Waiting for #7767 and a rebase might be best.

@Pierre-Sassoulas Pierre-Sassoulas added the Blocked 🚧 Blocked by a particular issue label Jul 9, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.0.0a7 milestone Jul 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 9, 2023

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit abcfcc2

@jacobtylerwalls jacobtylerwalls removed the Blocked 🚧 Blocked by a particular issue label Jul 10, 2023
@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Jul 10, 2023

There's some trickery with astroid's version but I'm not sure why readthedoc alone fail.

Yeah, I didn't bother to pin the astroid commit in the docs/requirements.txt, so it was pulling from astroid 3.0.0a7. Should be good now 👍

@Pierre-Sassoulas Pierre-Sassoulas merged commit ffe1e71 into pylint-dev:main Jul 11, 2023
79 of 80 checks passed
}
mod_b --> mod_a
mod_d --> mod_a
mod_c -.-> mod_a
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not valid mermaid.

it should be:
mod_c ..> mod_a
as documented here:
https://mermaid.js.org/syntax/classDiagram.html#defining-relationship

github renders mermaid files, and if we try to open this one we get an error, see:
https://github.com/pylint-dev/pylint/blob/ffe1e714a3cfe83b5a627ade6d723489f2e10621/tests/pyreverse/functional/package_diagrams/type_check_imports/packages.mmd

@agusdmb agusdmb mentioned this pull request Sep 12, 2023
@@ -24,6 +24,7 @@ class MermaidJSPrinter(Printer):
EdgeType.ASSOCIATION: "--*",
EdgeType.AGGREGATION: "--o",
EdgeType.USES: "-->",
EdgeType.TYPE_DEPENDENCY: "-.->",
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the actual wrong line

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Would you be willing to provide a PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

yep... just did!
#9031

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.

Idea: Pyreverse should distinguish between functional imports and type checking imports
5 participants