8000 Sort plugin manifests in alphabetical order for registration by DragaDoncila · Pull Request #7266 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Sort plugin manifests in alphabetical order for registration #7266

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 9 commits into from
Sep 19, 2024

Conversation

DragaDoncila
Copy link
Contributor
@DragaDoncila DragaDoncila commented Sep 13, 2024

References and relevant issues

Closes #5500

Description

This PR ensures that when the viewer is launched, plugin manifests (and therefore their actions) are registered in alphabetical order of manifest's display name (if available) or plugin name.

Note:

  • if a plugin is installed/enabled while the viewer is launched, this plugin will go to the bottom of the list, not in its correct spot. It will be correctly sorted on viewer relaunch. See zulip thread for more discussion on this.
  • Plugins that offer single commands will still be sorted in plugin name order, not action name order, and that may still be confusing. This is a non-trivial fix. Will continue to look at that.

I think just merging this PR as-is is still a great improvement, and I can follow up with the re-sorting in a separate PR. Otherwise if folks think this is not acceptable, we can leave this open while I figure out the re-ordering on plugin install/enable, and the single action sorting.

@DragaDoncila DragaDoncila mentioned this pull request Sep 13, 2024
Copy link
Contributor
@kephale kephale left a comment

Choose a reason for hiding this comment

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

Awesome, thank you so much @DragaDoncila

@psobolewskiPhD psobolewskiPhD added enhancement UI/UX ready to merge Last chance for comments! Will be merged in ~24h labels Sep 13, 2024
@psobolewskiPhD psobolewskiPhD added this to the 0.5.4 milestone Sep 13, 2024
Copy link
codecov bot commented Sep 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.75%. Comparing base (1c073a2) to head (a281d69).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7266      +/-   ##
==========================================
- Coverage   92.83%   92.75%   -0.09%     
==========================================
  Files         623      623              
  Lines       57072    57159      +87     
==========================================
+ Hits        52980    53015      +35     
- Misses       4092     4144      +52     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator
@Czaki Czaki left a comment

Choose a reason for hiding this comment

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

I like this PR. I have added a suggestion for fix problem with ordering single widget contribution

8000
for mf in manifests:
sorted_manifests = sorted(
manifests,
key=lambda mf: mf.display_name if mf.display_name else mf.name,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may provide here better key function.

def _get_plugin_sort_key(mf: PluginManifest) -> str:
    if len(mf.contributions.widgets) == 1:
        return mf.contributions.widgets[0].display_name
    if mf.display_name:
        return mf.display_name
    return mf.name

This will solve the problem of ordering single widget contribution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Omg duh 😂 thanks @Czaki will fix up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm actually this will solve the Plugins menu case, but then Samples menu may be incorrectly ordered, right? I don't think there's a way we can get both correct at this stage in the code. We'd have to collect all contributions and sort before registering the actions with app-model.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I know how to do it with minimal intervention actually. I'll follow up. If this PR gets merged beforehand that's fine

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that, the best solution, will be to improve build_qmodel_menu and QModelMenu For get dict of id -> sorting function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I'd say let's merge this PR as is, and we'll follow up for the single-contribution case

@lucyleeow
Copy link
Contributor
lucyleeow commented Sep 13, 2024

Do we want to add a test..?

(Can be done in the follow up I guess, it would be good ensure we are doing the right thing for samples and plugins menu)

@github-actions github-actions bot added the tests Something related to our tests label Sep 18, 2024
@github-actions github-actions bot added the qt Relates to qt label Sep 18, 2024
Copy link
Contributor
@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

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

Thanks for adding tests, seems reasonable to me!

@DragaDoncila
Copy link
Contributor Author

Since I just added tests now I'll re-start the 24hr clock and merge tomorrow if there are no objections!

Copy link
Collaborator
@Czaki Czaki left a comment

Choose a reason for hiding this comment

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

To solve coverage report

DragaDoncila and others added 2 commits September 19, 2024 13:37
Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
@DragaDoncila DragaDoncila merged commit e8c41ab into napari:main Sep 19, 2024
36 checks passed
@DragaDoncila DragaDoncila deleted the sorting-plugins branch September 19, 2024 04:38
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label Sep 19, 2024
DragaDoncila pushed a commit that referenced this pull request Sep 21, 2024
…d of `mock_app_model` and `get_app_model` (#7283)

# References and relevant issues

CI over main is failing due to the issue this PR fixes

# Description

Since PR #7269 and PR #7266 where being worked on in parallel merging
both caused some tests to fail (due to their usage of `mock_app` and
`get_app`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement qt Relates to qt tests Something related to our tests UI/UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort plugin list
5 participants
0