-
Notifications
You must be signed in to change notification settings - Fork 6
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
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. |
There was a problem hiding this 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 :)
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.
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()
.
There was a problem hiding this comment.
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 ?
Co-authored-by: jaimergp <[email protected]>
I added a suggestion to consider making the warning show when napari is from conda-forge. |
Co-authored-by: Peter Sobolewski <[email protected]>
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! |
There was a problem hiding this 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!
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 True
part