Skip to content

Commit

Permalink
add check for QEAppComputationalResourcesWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed May 1, 2024
1 parent 86d646c commit 9227290
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
9 changes: 4 additions & 5 deletions plugin_list.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,19 @@
" command = [\"pip\", \"install\", pip]\n",
" else:\n",
" command = [\"pip\", \"install\", \"git+\" + github]\n",
" message_container.value = \"\"\n",
" message_container.value = f\"\"\"<div style=\"color: #000000;\">Installing {package_name}...</div>\"\"\"\n",
" result = execute_command_with_output(command, output_container, install_btn, remove_btn)\n",
" # if the package was installed successfully\n",
" if result:\n",
" message_container.value = \"\"\"<div style=\"color: #008000;\">Plugin installed successfully.</div>\"\"\"\n",
" message_container.value += \"\"\"<div style=\"color: #008000;\">Initiating test to load the plugin...</div>\"\"\"\n",
" # Test plugin functionality\n",
" command = [sys.executable, '-m', 'aiidalab_qe', 'test-plugin', plugin_name]\n",
" command = [sys.executable, '-m', 'aiidalab_qe', 'test-plugin', package_name]\n",
" # Execute the command\n",
" result = subprocess.run(command, capture_output=True, text=True)\n",
" if result.returncode == 0:\n",
" # restart daemon\n",
" message_container.value = \"\"\"<div style=\"color: #008000;\">Plugin installed successfully.</div>\"\"\"\n",
" message_container.value += \"\"\"<div style=\"color: #008000;\">Loading plugin test passed.</div>\"\"\"\n",
" message_container.value = \"\"\"<div style=\"color: #008000;\">Loading plugin test passed.</div>\"\"\"\n",
" message_container.value += \"\"\"<div style=\"color: #008000;\">Plugin installed successfully.</div>\"\"\"\n",
" accordion.set_title(index, f\"{accordion.get_title(index)[:-2]} ✅\")\n",
" command = [\"verdi\", \"daemon\", \"restart\"]\n",
" subprocess.run(command, capture_output=True, shell=False)\n",
Expand Down
1 change: 0 additions & 1 deletion src/aiidalab_qe/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def test_plugin(plugin_name, profile):

try:
success, message = test_plugin_functionality(plugin_name)
print(f"success: {success}, message: {message}")
if success:
click.secho("Plugin is loaded successfully!", fg="green")
else:
Expand Down
21 changes: 15 additions & 6 deletions src/aiidalab_qe/app/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,24 @@ def get_entry_points_for_package(


def test_plugin_functionality(plugin_name):
"""Test the functionality of the plugin by loading all entry points."""
"""Test the functionality of the plugin.
1) loading all entry points.
2) check if the plugin use correct QEAppComputationalResourcesWidget
"""
from aiidalab_qe.common.widgets import QEAppComputationalResourcesWidget

try:
eps = get_entry_points_for_package(plugin_name)
# check if we can load all entry points
try:
for ep in eps:
ep.load()
except Exception as e:
return False, f"Failed to load entry point {ep.name}: {e}"
for ep in eps:
loaded_ep = ep.load()
# check if the code uses the correct widget
for name, code in loaded_ep.get("code", {}).items():
if not isinstance(code, QEAppComputationalResourcesWidget):
return (
False,
f"\nPlugin {plugin_name} code {name} must use QEAppComputationalResourcesWidget class",
)
except Exception as e:
return False, f"Failed to get entry points for package {plugin_name}: {e}"
return True, ""

0 comments on commit 9227290

Please sign in to comment.