Skip to content

Commit

Permalink
Remove support for AiiDA 0.x in start.ipynb (#175)
Browse files Browse the repository at this point in the history
* Cleanup start.ipynb
* Add comment about where jupyter_notebook_url comes from
  • Loading branch information
danielhollas authored Oct 21, 2024
1 parent 42e317c commit 59a5c08
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 75 deletions.
1 change: 1 addition & 0 deletions open_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"metadata": {},
"outputs": [],
"source": [
"# variable `jupyter_notebook_url` is injected by appmode\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n",
"\n",
"query = urlparse.parse_qs(url.query)"
Expand Down
3 changes: 2 additions & 1 deletion single_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"metadata": {},
"outputs": [],
"source": [
"# variable `jupyter_notebook_url` is injected by appmode\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n",
"try:\n",
" name = urlparse.parse_qs(url.query)[\"app\"][0]\n",
Expand Down Expand Up @@ -80,7 +81,7 @@
"\n",
"try:\n",
" display(AppManagerWidget(app_base, minimalistic=False))\n",
"except Exception as error: # pylint: disable=broad-except\n",
"except Exception as error:\n",
" display(\n",
" ipw.HTML(\n",
" '<div style=\"font-size: 30px; text-align:center;\">'\n",
Expand Down
81 changes: 14 additions & 67 deletions start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
"source": [
"import urllib.parse as urlparse\n",
"\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n",
"parsed_url = urlparse.parse_qs(url.query)"
"# variable `jupyter_notebook_url` is injected by appmode\n",
"try:\n",
" url = urlparse.urlsplit(jupyter_notebook_url)\n",
"except NameError:\n",
" parsed_url = \"\"\n",
"else:\n",
" parsed_url = urlparse.parse_qs(url.query)"
]
},
{
Expand All @@ -33,72 +38,14 @@
"metadata": {},
"outputs": [],
"source": [
"import aiida\n",
"\n",
"home = None\n",
"\n",
"if aiida.__version__ < \"1.0.0\":\n",
" import datetime\n",
" import os\n",
" import shutil\n",
" import subprocess\n",
"\n",
" import ipywidgets as ipw\n",
"\n",
" display(\n",
" ipw.HTML(\n",
" f\"\"\"<font size=\"4\">Warning! The aiidalab-home application is incompatible\n",
" with AiiDA {aiida.__version__} that is currently installed on your system. To fix\n",
" the problem you should switch to the 'support/aiida-0.12.x' branch.\n",
" This can be done either manually or by clicking on the button \n",
" below.</font>\"\"\"\n",
" )\n",
" )\n",
"\n",
" def update_home(_=None):\n",
" home = os.path.expanduser(\"~\")\n",
" home_app_path = os.path.join(home, \"apps\", \"home\")\n",
" home_app_new_path = (\n",
" home_app_path + \"-backup-\" + datetime.datetime.now().isoformat()\n",
" )\n",
" try:\n",
" os.chdir(home) # Before removing app folder - move to the user's home.\n",
" shutil.move(home_app_path, home_app_new_path)\n",
" except Exception:\n",
" pass\n",
" subprocess.call(\n",
" [\n",
" \"git\",\n",
" \"clone\",\n",
" \"https://github.com/aiidalab/aiidalab-home.git\",\n",
" home_app_path,\n",
" ]\n",
" )\n",
" os.chdir(home_app_path)\n",
" subprocess.call([\"git\", \"checkout\", \"support/aiida-0.12.x\"])\n",
" display(\n",
" ipw.HTML(\n",
" f\"\"\"<font size=\"4\">Downgrade successful. The old home app was placed under {home_app_new_path} folder.\n",
" Please, reload the page to see the downgraded home app.</font>\"\"\"\n",
" )\n",
" )\n",
"\n",
" update_btn = ipw.Button(\n",
" description=\"Downgrade home app\",\n",
" layout={\"width\": \"initial\"},\n",
" button_style=\"danger\",\n",
" )\n",
" update_btn.on_click(update_home)\n",
" display(update_btn)\n",
"else:\n",
" from home.start_page import AiidaLabHome\n",
"from home.start_page import AiidaLabHome\n",
"\n",
" home = AiidaLabHome()\n",
" if \"move_up\" in parsed_url:\n",
" home.move_updown(parsed_url[\"move_up\"][0], -1)\n",
" elif \"move_down\" in parsed_url:\n",
" home.move_updown(parsed_url[\"move_down\"][0], +1)\n",
" display(home.render())"
"home = AiidaLabHome()\n",
"if \"move_up\" in parsed_url:\n",
" home.move_updown(parsed_url[\"move_up\"][0], -1)\n",
"elif \"move_down\" in parsed_url:\n",
" home.move_updown(parsed_url[\"move_down\"][0], +1)\n",
"display(home.render())"
]
},
{
Expand Down
14 changes: 7 additions & 7 deletions terminal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"outputs": [],
"source": [
"%%javascript\n",
"// https://github.com/jupyter/notebook/blob/master/notebook/static/tree/js/terminallist.js#L45\n",
"// https://github.com/jupyter/notebook/blob/6.4.x/notebook/static/tree/js/terminallist.js#L45\n",
"\n",
"requirejs([\"base/js/utils\"], function(utils) {\n",
" var base_url = utils.get_body_data(\"baseUrl\")\n",
Expand All @@ -33,23 +33,23 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
"pygments_lexer": "ipython3",
"version": "3.13.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit 59a5c08

Please sign in to comment.