8000 Deprecate usage of `get_app` functions to get `QApplication` or `NapariApplication` instances by dalthviz · Pull Request #7269 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Deprecate usage of get_app functions to get QApplication or NapariApplication instances #7269

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 10 commits into from
Sep 20, 2024

Conversation

dalthviz
Copy link
Member
@dalthviz dalthviz commented Sep 13, 2024

References and relevant issues

Closes #6054

Description

Use get_qapp to get a QApplication instance and get_app_model for a NapariApplication one. Add a deprecation warning when trying to access via the respective get_app functions without removing them.

Using the get_app functions with the changes here should give you a warning:

imagen
imagen

…riApplication' instances

Use 'get_qapp' for 'QApplication' and 'get_app_model' for 'NapariApplication'
@dalthviz dalthviz self-assigned this Sep 13, 2024
@github-actions github-actions bot added tests Something related to our tests qt Relates to qt labels Sep 13, 2024
@dalthviz dalthviz changed the title Deprecate usage of 'get_app' functions to get 'QApplication' or 'NapariApplication' instances Deprecate usage of get_app functions to get QApplication or NapariApplication instances Sep 13, 2024
Copy link
codecov bot commented Sep 13, 2024

Codecov Report

Attention: Patch coverage is 97.32143% with 3 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@022f023). Learn more about missing BASE report.
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
napari/_qt/widgets/qt_theme_sample.py 0.00% 2 Missing ⚠️
napari/_qt/widgets/qt_splash_screen.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7269   +/-   ##
=======================================
  Coverage        ?   92.74%           
=======================================
  Files           ?      623           
  Lines           ?    57134           
  Branches        ?        0           
=======================================
  Hits            ?    52991           
  Misses          ?     4143           
  Partials        ?        0           

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

qapp = get_qapp()
with pytest.warns(FutureWarning):
deprecated_qapp = get_app()
assert qapp == deprecated_qapp


@pytest.mark.skipif(os.name != 'Windows', reason='Windows specific')
Copy link
Member Author

Choose a reason for hiding this comment

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

Just in case, while checking the test addition over this file, I noticed this skip, shouldn't it be something like:

@pytest.mark.skipif(os.name != 'nt', reason='Windows specific')

?

As it is, the test is skipped on Windows. However, if you do the skip definition change above the test is run but it fails on Windows. Not related to the changes here but maybe worthy of an issue 🤔?

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #7278 to follow up this 👍

@dalthviz dalthviz marked this pull request as ready for review September 16, 2024 16:37
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.

PR looks ok, but test should be improved to check if proper warning is emitted.

assert app.name == 'test_app'
assert list(app.menus)
assert list(app.commands)
# assert list(app.keybindings) # don't have any yet
with pytest.warns(FutureWarning):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use match argument with matching string to check if a proper future warning is emmited

Comment on lines 19 to 20
with pytest.warns(FutureWarning):
deprecated_qapp = get_app()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also use match argument

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.

Thank you for doing this @dalthviz !

Some nits.

Also are you happy to amend other uses of get_app in the napari org (potentially there will be some in docs, maybe cookie cutter? etc). (in follow up PRs of course)

@@ -143,7 +143,7 @@ def pytest_runtest_makereport(item, call):
def mock_app():
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be changed to mock_app_model now?


from app_model import Application

from napari._app_model.actions._layerlist_context_actions import (
LAYERLIST_CONTEXT_ACTIONS,
LAYERLIST_CONTEXT_SUBMENUS,
)
from napari.utils.translations import trans

APP_NAME = 'napari'

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets change the NapariApplication method get_app to get_app_model, and update the mock_app as well. Thanks!

@@ -61,7 +61,59 @@ def set_app_id(app_id):
_IPYTHON_WAS_HERE_FIRST = 'IPython' in sys.modules


def get_app(
def get_app(*args, **kwargs) -> QApplication:
"""Get or create the Qt QApplication.
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we can just delete this docstring and just say, deprecated, use get_qapp.

Maybe we could add a todo to say delete in napari 0.6.0 (I assume next major release dep is fine?) Also lets add the todo to the other get_app as well!

@@ -57,5 +59,19 @@ def _public_types(module):


def get_app() -> NapariApplication:
"""Get the Napari Application singleton."""
Copy link
Contributor

Choose a reason for hiding this comment

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

As with the other, lets just say deprecated, use get_app_model, to deprecate 0.6.0

… 'NapariApplication.get_app_model' and update deprecated methods docstrings
@dalthviz
Copy link
Member Author

Also are you happy to amend other uses of get_app in the napari org (potentially there will be some in docs, maybe cookie cutter? etc). (in follow up PRs of course)

Created a couple of PRs for that 👍:

One pending repo to update from my quick search over the napari org is https://github.com/napari/napari-language-packs/tree/main Seems like over there the translations strings are kept? Maybe an update command needs to be run so the base strings get updated/added to the .pot file there (although it seems like the repo is kind of outdated? 🤔)

Is there any other place where changes need to be done? Let me know!

@Czaki
Copy link
Collaborator
Czaki commented Sep 17, 2024

We should decide if we want to remove get_app in 0.6.0 or in 0.7.0. Then update warning message and will be ready.

@DragaDoncila
Copy link
Contributor

I had a look at this and everything looks good. I agree we should add the version it'll be removed in, and I think it should be 0.6.0 as the majority of usage is internal, and I wouldn't expect many repos to be affected. @dalthviz do you want to add that version to the warning message?

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.

Thank you! Just some nits and agree with adding deprecation version to message!

def get_app(
def get_app(*args, **kwargs) -> QApplication:
"""Get or create the Qt QApplication. Now deprecated, use `get_qapp`."""
# TODO: Remove in napari 0.6.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry nit, can you put this comment above the get_app function?

Co-authored-by: Lucy Liu <jliu176@gmail.com>
dalthviz and others added 3 commits September 18, 2024 09:35
…comment

Co-authored-by: Lucy Liu <jliu176@gmail.com>
Co-authored-by: Draga Doncila Pop <17995243+DragaDoncila@users.noreply.github.com>
Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
@lucyleeow
Copy link
Contributor

One pending repo to update from my quick search over the napari org is https://github.com/napari/napari-language-packs/tree/main Seems like over there the translations strings are kept? Maybe an update command needs to be run so the base strings get updated/added to the .pot file there (although it seems like the repo is kind of outdated? 🤔)

No idea about this one, maybe @goanpeca knows? 🙏

Copy link
Contributor
@DragaDoncila DragaDoncila left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @dalthviz ❤️

@DragaDoncila DragaDoncila added maintenance PR with maintance changes, ready to merge Last chance for comments! Will be merged in ~24h and removed tests Something related to our tests labels Sep 19, 2024
@DragaDoncila DragaDoncila added this to the 0.5.4 milestone Sep 19, 2024
@DragaDoncila DragaDoncila merged commit e861f80 into napari:main Sep 20, 2024
48 checks passed
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label Sep 20, 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`)
jni pushed a commit to napari/docs that referenced this pull request Sep 27, 2024
# References and relevant issues

Part of napari/napari#6054

# Description

Use `get_qapp` instead of `get_app` (being deprecated over PR
napari/napari#7269)

---------

Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance PR with maintance changes, qt Relates to qt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Two get_app functions
4 participants
0