Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#174)
Browse files Browse the repository at this point in the history
* Fix lints in notebooks

updates:
- [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](pre-commit/pre-commit-hooks@v4.6.0...v5.0.0)
- [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.6.9](astral-sh/ruff-pre-commit@v0.5.0...v0.6.9)
- [github.com/sirosen/check-jsonschema: 0.28.6 → 0.29.3](python-jsonschema/check-jsonschema@0.28.6...0.29.3)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Hollas <daniel.hollas@bristol.ac.uk>
  • Loading branch information
pre-commit-ci[bot] and danielhollas authored Oct 14, 2024
1 parent 8aaee5c commit 42e317c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-json
- id: check-yaml
Expand All @@ -14,7 +14,7 @@ repos:
exclude: miscellaneous/structures/SiO2.xyz

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.6.9
hooks:
- id: ruff-format
exclude: ^docs/.*
Expand All @@ -27,7 +27,7 @@ repos:
- id: yamlfmt

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.28.6
rev: 0.29.3
hooks:
- id: check-github-workflows

Expand Down
3 changes: 2 additions & 1 deletion appstore.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"outputs": [],
"source": [
"import ipywidgets as ipw\n",
"\n",
"from home.app_store import AiidaLabAppStore"
]
},
Expand All @@ -31,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"display(ipw.HTML(\"\"\"/<a href=\"start.ipynb\"> home </a>/ appstore\"\"\"))\n"
"display(ipw.HTML(\"\"\"/<a href=\"start.ipynb\"> home </a>/ appstore\"\"\"))"
]
},
{
Expand Down
31 changes: 20 additions & 11 deletions open_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"outputs": [],
"source": [
"import urllib.parse as urlparse\n",
"\n",
"import ipywidgets as ipw"
]
},
Expand All @@ -19,23 +20,24 @@
"outputs": [],
"source": [
"import sys\n",
"\n",
"from aiidalab.__main__ import _find_version_to_install, _parse_requirement\n",
"from aiidalab.utils import PEP508CompliantUrl\n",
"\n",
"\n",
"def identify_app_and_version(app_query, prereleases, force): \n",
"def identify_app_and_version(app_query, prereleases, force):\n",
" try:\n",
" requirement = _parse_requirement(app_query)\n",
" except Exception as error:\n",
" raise RuntimeError(str(error)) from error\n",
" \n",
"\n",
" try:\n",
" return _find_version_to_install(\n",
" requirement,\n",
" dependencies=\"install\",\n",
" force=force,\n",
" python_bin=sys.executable,\n",
" prereleases=prereleases)\n",
" prereleases=prereleases,\n",
" )\n",
" except Exception as error:\n",
" raise RuntimeError(str(error)) from error"
]
Expand All @@ -47,7 +49,7 @@
"metadata": {},
"outputs": [],
"source": [
"url = urlparse.urlsplit(jupyter_notebook_url)\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n",
"\n",
"query = urlparse.parse_qs(url.query)"
]
Expand All @@ -59,9 +61,10 @@
"metadata": {},
"outputs": [],
"source": [
"from home.widgets import LogOutputWidget, Spinner, StatusHTML\n",
"from IPython.display import Javascript\n",
"\n",
"from home.widgets import LogOutputWidget, Spinner\n",
"\n",
"header = ipw.HTML()\n",
"logs = LogOutputWidget(layout=ipw.Layout(min_height=\"250px\", max_height=\"100px\"))\n",
"spinner = Spinner()\n",
Expand All @@ -73,11 +76,13 @@
" app_query = query[\"app\"][0]\n",
" except KeyError:\n",
" raise RuntimeError(\"No app to install specified.\")\n",
" \n",
"\n",
" force = query.get(\"force\", [False])[0]\n",
" prereleases = query.get(\"prereleases\", [False])[0]\n",
" \n",
" app, version = identify_app_and_version(query[\"app\"][0], force=force, prereleases=prereleases)\n",
"\n",
" app, version = identify_app_and_version(\n",
" query[\"app\"][0], force=force, prereleases=prereleases\n",
" )\n",
"except Exception as error:\n",
" header.value = f\"Error: {error}\"\n",
"\n",
Expand All @@ -99,8 +104,12 @@
"else:\n",
" redirect = query.get(\"redirect\", None)\n",
" if redirect:\n",
" redirect_url = urlparse.urlunsplit(url._replace(path=redirect[0], query=None, fragment=None))\n",
" header.value = f'Redirecting now to <a href=\"{redirect_url}\">{redirect_url}</a>...'\n",
" redirect_url = urlparse.urlunsplit(\n",
" url._replace(path=redirect[0], query=None, fragment=None)\n",
" )\n",
" header.value = (\n",
" f'Redirecting now to <a href=\"{redirect_url}\">{redirect_url}</a>...'\n",
" )\n",
" js = Javascript(f\"window.location = '{redirect_url}'\")\n",
" display(js)\n",
"finally:\n",
Expand Down
30 changes: 18 additions & 12 deletions single_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
"outputs": [],
"source": [
"import urllib.parse as urlparse\n",
"from IPython.lib import backgroundjobs as bg\n",
"import ipywidgets as ipw\n",
"\n",
"import ipywidgets as ipw\n",
"from aiidalab.app import AiidaLabApp\n",
"from aiidalab.config import AIIDALAB_APPS, AIIDALAB_REGISTRY\n",
"from aiidalab.config import AIIDALAB_APPS\n",
"from aiidalab.utils import load_app_registry_entry\n",
"\n",
"from home.app_manager import AppManagerWidget"
Expand All @@ -38,11 +37,11 @@
"metadata": {},
"outputs": [],
"source": [
"url = urlparse.urlsplit(jupyter_notebook_url)\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n",
"try:\n",
" name = urlparse.parse_qs(url.query)['app'][0]\n",
" name = urlparse.parse_qs(url.query)[\"app\"][0]\n",
"except KeyError:\n",
" raise Exception(\"No app specified\")\n",
" raise Exception(\"No app specified\") # noqa: TRY002\n",
" exit()"
]
},
Expand All @@ -64,7 +63,11 @@
"metadata": {},
"outputs": [],
"source": [
"display(ipw.HTML(\"\"\"/<a href=\"start.ipynb\"> home </a>/<a href=\"appstore.ipynb\"> appstore </a>/ {}\"\"\".format(name)))"
"display(\n",
" ipw.HTML(\n",
" f\"\"\"/<a href=\"start.ipynb\"> home </a>/<a href=\"appstore.ipynb\"> appstore </a>/ {name}\"\"\"\n",
" )\n",
")"
]
},
{
Expand All @@ -78,11 +81,14 @@
"try:\n",
" display(AppManagerWidget(app_base, minimalistic=False))\n",
"except Exception as error: # pylint: disable=broad-except\n",
" display(ipw.HTML(\n",
" '<div style=\"font-size: 30px; text-align:center;\">'\n",
" f'Unable to show app widget due to error: {error}'\n",
" '</div>',\n",
" layout={'width': '600px'}))"
" display(\n",
" ipw.HTML(\n",
" '<div style=\"font-size: 30px; text-align:center;\">'\n",
" f\"Unable to show app widget due to error: {error}\"\n",
" \"</div>\",\n",
" layout={\"width\": \"600px\"},\n",
" )\n",
" )"
]
}
],
Expand Down
79 changes: 51 additions & 28 deletions start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" import urllib.parse as urlparse\n",
"except ImportError:\n",
" import urlparse\n",
"parsed_url = urlparse.parse_qs(urlparse.urlsplit(jupyter_notebook_url).query)"
"import urllib.parse as urlparse\n",
"\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa: F821\n",
"parsed_url = urlparse.parse_qs(url.query)"
]
},
{
Expand All @@ -35,46 +34,70 @@
"outputs": [],
"source": [
"import aiida\n",
"\n",
"home = None\n",
"\n",
"if aiida.__version__ < '1.0.0':\n",
"if aiida.__version__ < \"1.0.0\":\n",
" import datetime\n",
" import os\n",
" import sys\n",
" import shutil\n",
" import ipywidgets as ipw\n",
" import subprocess\n",
" import datetime\n",
"\n",
" display(ipw.HTML(\"\"\"<font size=\"4\">Warning! The aiidalab-home application is incompatible\n",
" with AiiDA {} that is currently installed on your system. To fix\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>\"\"\".format(aiida.__version__)))\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 = home_app_path + '-backup-' + datetime.datetime.now().isoformat()\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",
" 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:\n",
" except Exception:\n",
" pass\n",
" subprocess.call(['git', 'clone', 'https://github.com/aiidalab/aiidalab-home.git', home_app_path])\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(ipw.HTML(\"\"\"<font size=\"4\">Downgrade successful. The old home app was placed under {} folder.\n",
" Please, reload the page to see the downgraded home app.</font>\"\"\".format(home_app_new_path)))\n",
" \n",
" update_btn = ipw.Button(description='Downgrade home app', layout={'width': 'initial'}, button_style='danger')\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",
"\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",
" 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 All @@ -87,7 +110,7 @@
"%%javascript\n",
"// in case an app was moved up or down\n",
"// I need to remove the corresponding variable from the url\n",
"// othervise if I update page again the same move will happen\n",
"// otherwise if I update page again the same move will happen\n",
"\n",
"var url = window.location.toString();\n",
"function getQueryVariable(variable)\n",
Expand Down

0 comments on commit 42e317c

Please sign in to comment.