Add a warning message when triggering an install action using PyPI source on a bundle/conda installation#111
Conversation
…rce on a bundle installation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
|
Technically pip will take into account existing site-packages right? but not necessarily namespace issues. |
|
Let's focus on this one to close #110. |
|
All yours! :) |
| if ( | ||
| tool == InstallerTools.PIP | ||
| and action == InstallerActions.INSTALL | ||
| and self._on_bundle() |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
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 TrueWhat do you think @jaimergp ?
Co-authored-by: jaimergp <jaimergp@users.noreply.github.com>
|
I added a suggestion to consider making the warning show when napari is from conda-forge. |
Co-authored-by: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com>
for more information, see https://pre-commit.ci
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 🤔 |
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 ? |
i think this is a good idea as a stepping stone! |
|
Awesome, merging then @dalthviz. |
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:
Note: Check locally the warning message triggering and dialog layout as seen from a bundle installation, you need to replace/change
napari-plugin-manager/napari_plugin_manager/qt_plugin_dialog.py
Lines 131 to 134 in 3260704
and uncommenting the
# or Truepart