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

Add a warning message when triggering an install action using PyPI source on a bundle/conda installation #111

Merged
merged 11 commits into from
Dec 4, 2024

Conversation

dalthviz
Copy link
Member

@dalthviz dalthviz commented Nov 5, 2024

Part of #110

Explores the option to add a warning message so users are better informed of the dangers of using the PyPI source option on bundle installations (mixing pip + conda). This particular implementation uses a dialog to show the warning. A preview:

pypi_warn

Note: Check locally the warning message triggering and dialog layout as seen from a bundle installation, you need to replace/change

def _warn_pypi_install(self):
return running_as_constructor_app() or is_conda_package(
'napari'
) # or True

and uncommenting the # or True part

Copy link

codecov bot commented Nov 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.53%. Comparing base (cccd4d1) to head (63adb5b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #111      +/-   ##
==========================================
+ Coverage   93.46%   93.53%   +0.07%     
==========================================
  Files          11       11              
  Lines        1943     1981      +38     
==========================================
+ Hits         1816     1853      +37     
- Misses        127      128       +1     

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

Copy link
Contributor

@goanpeca goanpeca left a comment

Choose a reason for hiding this comment

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

Hi @dalthviz is this good to go?

All looks good :)

@dalthviz
Copy link
Member Author

Hi there, technically yes but still not sure if whether this or #112 is the preferred approach to improve things in regards of issue #110 🤔 Will post a message over the Zulip discussion pointing to the PRs to see if we can gather more feedback 👍

@psobolewskiPhD
Copy link
Member

Technically pip will take into account existing site-packages right? but not necessarily namespace issues.
Plus if there are plugins that have napari[all]--which there are--that will likely break the bundle.

@jaimergp
Copy link
Contributor

Let's focus on this one to close #110.

@dalthviz dalthviz marked this pull request as ready for review November 27, 2024 17:09
@dalthviz
Copy link
Member Author

Should #113 be merged first so then I update/redo this on top of that work @jaimergp @goanpeca ?

@jaimergp
Copy link
Contributor

All yours! :)

if (
tool == InstallerTools.PIP
and action == InstallerActions.INSTALL
and self._on_bundle()
Copy link
Contributor

@jaimergp jaimergp Nov 28, 2024

Choose a reason for hiding this comment

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

Some folks might not want this behavior, on bundle or not. Let's turn this third condition into self._warn_pypi_install() and then users can choose what to do about it in their subclasses. In our case, _warn_pypi will call running_as_constructor_app().

Copy link
Member Author

@dalthviz dalthviz Nov 28, 2024

Choose a reason for hiding this comment

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

Thinking about how to generalize the warning dialog text, maybe another approach that could be done is to instead add a _action_validation method that should be implemented returning a boolean? So something like:

    def _action_validation(self, tool, action) -> bool:
        raise NotImplementedError

    def _action_requested(self):
        version = self.version_choice_dropdown.currentText()
        tool = self.get_installer_tool()
        action = (
            InstallerActions.INSTALL
            if self.action_button.objectName() == 'install_button'
            else InstallerActions.UNINSTALL
        )
        if self._action_validation(tool, action):
            self.actionRequested.emit(self.item, self.name, action, version, tool)

Then the napari implementation would be something like:

    def _action_validation(self, tool, action) -> bool:
        if (
            tool == InstallerTools.PIP
            and action == InstallerActions.INSTALL
            and (running_as_constructor_app() or is_conda_package('napari'))
        ):
            button_clicked = QMessageBox.warning(
                self,
                self._trans('PyPI installation on bundle'),
                self._trans(
                    'Installing from PyPI does not take into account existing installed packages, '
                    'so it can break existing installations. '
                    'If this happens the only solution is to reinstall the bundle.\n\n'
                    'Are you sure you want to install from PyPI?'
                ),
                buttons=QMessageBox.StandardButton.Ok
                | QMessageBox.StandardButton.Cancel,
                defaultButton=QMessageBox.StandardButton.Cancel,
            )
            if button_clicked != QMessageBox.StandardButton.Ok:
                return False
        return True

What do you think @jaimergp ?

@psobolewskiPhD
Copy link
Member

I added a suggestion to consider making the warning show when napari is from conda-forge.
I've broken envs using the plugin installer before like this, so it may be worth mentioning.
Perhaps should consider this for a followup PR perhaps, because we could expect non-bundle users to be more advanced, so they could find it annoying to dismiss tie dialog. I'd love a dont warn again checkbox--not sure where we can save that state though 😬 so that would certainly be a followup.

@dalthviz
Copy link
Member Author

I'd love a dont warn again checkbox--not sure where we can save that state though 😬 so that would certainly be a followup.

Yep, that makes sense to me. We could use a similar approach for settings as #95 or we could also check using QSettings (although maybe relying on Qt for that is not desired). Maybe there could be other ways 🤔

@dalthviz dalthviz changed the title Add a warning message when triggering an install action using PyPI source on a bundle installation Add a warning message when triggering an install action using PyPI source on a bundle/conda installation Nov 28, 2024
@jaimergp
Copy link
Contributor

jaimergp commented Dec 2, 2024

so that would certainly be a followup.

I'd advocate for that! Shall we merge here @dalthviz or do you prefer iterating on this PR?

@dalthviz
Copy link
Member Author

dalthviz commented Dec 2, 2024

I'd advocate for that! Shall we merge here @dalthviz or do you prefer iterating on this PR?

I think I could add here the checkbox to the dialog so at least on a per launch/session basis you can dismiss it. Then in a follow up PR we could check ways to add some persistence/settings. Does that make sense?

Besides that, what do you think about #111 (comment) @jaimergp ?

@psobolewskiPhD
Copy link
Member

@dalthviz

I think I could add here the checkbox to the dialog so at least on a per launch/session basis you can dismiss it.

i think this is a good idea as a stepping stone!
I suspect most people install some stuff--multiple plugins--and then don't for quite some time!
Only issue would be if someone restarts napari after each install, based on the warning?
🤷
Even this I'd be cool with it being it's own PR.

Copy link
Member

@psobolewskiPhD psobolewskiPhD left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@jaimergp
Copy link
Contributor

jaimergp commented Dec 4, 2024

Awesome, merging then @dalthviz.

@jaimergp jaimergp merged commit 84f79a0 into napari:main Dec 4, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants