8000 Implement app reinstall button by edan-bainglass · Pull Request #250 · aiidalab/aiidalab-home · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions home/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ def __init__(self, app, minimalistic=False):
self.update_button = ipw.Button(description="Update", disabled=True)
self.update_button.on_click(self._update_app)

self.reinstall_button = ipw.Button(description="Reinstall", disabled=True)
self.reinstall_button.on_click(self._reinstall_app)

self.issue_indicator = ipw.HTML()
self.blocked_ignore = ipw.Checkbox(description="Ignore")
self.blocked_ignore.layout.visibility = "hidden"
Expand Down Expand Up @@ -256,6 +259,7 @@ def __init__(self, app, minimalistic=False):
self.uninstall_button,
self.install_button,
self.update_button,
self.reinstall_button,
self.spinner,
]
),
Expand Down Expand Up @@ -372,6 +376,7 @@ def _refresh_widget_state(self, _=None):
can_switch and (detached or not latest_selected)
) or bool(not installed and available_versions)
can_uninstall = installed
can_reinstall = installed and self.app.core_compatible is True
try:
can_update = (
self.app.remote_update_status is AppStatus.UPDATE_AVAILABLE
Expand Down Expand Up @@ -451,6 +456,10 @@ def _refresh_widget_state(self, _=None):
else ""
)

self.reinstall_button.disabled = 8000 busy or not can_reinstall
self.reinstall_button.button_style = "info" if can_reinstall else ""
self.reinstall_button.icon = "refresh" if can_reinstall else ""

# Update the version_selector widget state.
more_than_one_version = (
len(self.version_selector.version_to_install.options) > 1
Expand Down Expand Up @@ -543,6 +552,17 @@ def _update_app(self, _):
self._show_msg_success("Updated app.")
self.dependencies_log.value = ""

def _reinstall_app(self, _):
"""Attempt to reinstall the app dependencies in place."""
self.dependencies_log.value = ""
try:
self.app.reinstall_app(stdout=self.dependencies_log)
except (RuntimeError, CalledProcessError) as error:
self._show_msg_failure(str(error))
else:
self._show_msg_success("Reinstalled app.")
self.dependencies_log.value = ""

def _uninstall_app(self, _):
"""Attempt to uninstall the app."""
try:
Expand Down
51 changes: 51 additions & 0 deletions tests/test_app_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from subprocess import CalledProcessError
from unittest.mock import Mock

import pytest

from home.app_manager import AppManagerWidget
from home.widgets import LogOutputWidget


@pytest.mark.parametrize(
"error",
[
None,
RuntimeError("pip failed"),
CalledProcessError(1, "post_install"),
],
ids=["success", "pip-failure", "post-install-failure"],
)
def test_reinstall_callback(error):
log = LogOutputWidget()
log.value = "previous operation output\n"

def reinstall(*, stdout):
assert stdout is log
assert stdout.value == ""
stdout.write("installation output\n")
if error is not None:
raise error

app = Mock()
app.reinstall_app.side_effect = reinstall
manager = AppManagerWidget.__new__(AppManagerWidget)
manager.app = app
manager.dependencies_log = log
manager._show_msg_success = Mock()
manager._show_msg_failure = Mock()

try:
AppManagerWidget._reinstall_app(manager, None)

app.reinstall_app.assert_called_once_with(stdout=log)
if error is None:
manager._show_msg_success.assert_called_once_with("Reinstalled app.")
manager._show_msg_failure.assert_not_called()
assert log.value == ""
else:
manager._show_msg_failure.assert_called_once_with(str(error))
manager._show_msg_success.assert_not_called()
assert log.value == "installation output\n"
finally:
log.close()
1 change: 1 addition & 0 deletions tests_notebooks/test_manage_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ def test_single_app(selenium_driver, final_screenshot):
selenium.set_window_size(1000, 1100)
selenium.find_element(By.XPATH, "//button[contains(.,'Uninstall')]")
selenium.find_element(By.XPATH, "//button[contains(.,'Install')]")
selenium.find_element(By.XPATH, "//button[contains(.,'Reinstall')]")
Loading
0