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

Refactor depth filtering logic #10200

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

Julfried
Copy link
Contributor

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

Refactored the depth filtering logic, as discussed in #10077. Implementation should be much cleaner now :)

@Julfried Julfried requested a review from DudeNr33 as a code owner January 26, 2025 23:47
Copy link

codecov bot commented Jan 26, 2025

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.86%. Comparing base (05e83c4) to head (0e629d9).
Report is 31 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10200      +/-   ##
==========================================
+ Coverage   95.84%   95.86%   +0.02%     
==========================================
  Files         175      175              
  Lines       19056    19053       -3     
==========================================
+ Hits        18264    18265       +1     
+ Misses        792      788       -4     
Files with missing lines Coverage Ξ”
pylint/pyreverse/diadefslib.py 99.30% <100.00%> (+0.10%) ⬆️
pylint/pyreverse/main.py 91.66% <100.00%> (ΓΈ)
pylint/pyreverse/writer.py 100.00% <ΓΈ> (+0.84%) ⬆️
pylint/typing.py 100.00% <100.00%> (ΓΈ)

... and 10 files with indirect coverage changes

This comment has been minimized.

@Pierre-Sassoulas Pierre-Sassoulas added pyreverse Related to pyreverse component Skip news πŸ”‡ This change does not require a changelog entry labels Jan 27, 2025
@Julfried Julfried changed the title Refactor diagram class Refactor depth filtering logic Jan 27, 2025
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.

Thank you for the merge request ! LGTM, some nits:

@Julfried
Copy link
Contributor Author

Thanks for the review, your suggestions make sense.

One thing I noticed when playing around with it. If you call pyreverse for a subpackage and apply a depth limit. For example:

pyreverse --max-depth 1 package.subpackage 

The diagram is correctly generated and starts only at subpackage. However the depth limit is still calculated with respect to the root package. I think it would be more intuitive to calculate depth relative to subpackage in this case. What do you think?

This comment has been minimized.

@Julfried
Copy link
Contributor Author

However I am unsure how to achive this given that pyreverse lets you specify multiple packages to analyse

@Pierre-Sassoulas
Copy link
Member

Yeah hard to reconcile all the arguments. Maybe it's easier to add a warning like "You asked for depth=1 but linked package.subpackage which require depth=2 to be shown as pyreverse count depth from the root, did you meant package or depth=3 ? "

DudeNr33
DudeNr33 previously approved these changes Feb 2, 2025
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 refactor! I agree with Pierre, I would go for a warning right now for the case you mentioned.

@Julfried
Copy link
Contributor Author

Julfried commented Feb 3, 2025

Thanks for the review and for the suggestion regarding the warning! For properly implementing this warning I would need to implement this in main.py so that I dont have to gather the arguments passed. Maybe it makes more sense to just document this behavior instead?

@DudeNr33
Copy link
Collaborator

DudeNr33 commented Feb 3, 2025

Yes, maybe adding a short notice in the help text of the option that explains how the counting works/where it starts would be the best solution for now.

@Pierre-Sassoulas
Copy link
Member

From experience no one ever read the documentation, so I would favor a warning (unless it's really unreasonable to do it of course).

@Julfried
Copy link
Contributor Author

Julfried commented Feb 4, 2025

I agree with Pierre that documentation is hardly read, so a warning would be much more effective in guiding users. However, to properly detect this edge case, I would need access to the original specified by the user (self.args in main.py) inside DiadefsHandler. Right now, I don’t see a straightforward way to pass this information without modifying the argument flow, but I’ll think about possible solutions. If anyone has suggestions on a clean way to achieve this, I’d be happy to discuss!

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Julfried
Copy link
Contributor Author

Julfried commented Feb 23, 2025

Sorry for the delay, had to do prioritize some other stuff. I changed the depth logic to always choose the deepest packge (in other words the leaf nodes of the specified package tree). If a user specifies nested package names, a warning is now emitted to prevent confusion. I believe this approach is more intuitive and aligns with user expectations. Let me know what you thinkβ€”I'll update the documentation accordingly if you approve :)

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.

Thank you ! It's getting kinda big to review, we might want to do the refactor moving code from test_writer to test_diadefs in a prior refactor PR to ease this one.

My only actual request changes is on the logging that should be a warning :)

This comment has been minimized.

Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit 0e629d9

@Julfried
Copy link
Contributor Author

Thanks Pierre, I`ve applied your suggestions and fixed the tests. Regarding the warning, Ruff forced me to set a stacklevel for warnings.warn(). Based on my understanding, stacklevel=2 is appropriate for libraries as it makes the warning point to the calling code rather than our implementation details. Let me know what you think on that one.

I agree that the PR is getting quite large. However, since this PR moves all the filtering logic from writer.py to diadefslib.py, I am unsure if it is a good idea to move the tests in a seperate PR, prior to this one. How about updating docs in a follow up PR, since this is the last thing missing I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pyreverse Related to pyreverse component Skip news πŸ”‡ This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants