Skip to content
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

Adopt more ruff rules to align with AWB codebase #785

Merged
merged 9 commits into from
Jul 31, 2024
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
18 changes: 3 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,16 @@ repos:
hooks:
- id: check-github-workflows

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
hooks:
- id: nbqa-pyupgrade
args: [--py38-plus]
- id: nbqa-isort
args: [--profile=black]
- id: nbqa-ruff
# suppress E402
args: [--ignore=E402]

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
rev: v0.5.5
hooks:
# Run the linter.
- id: ruff
types_or: [python, pyi, jupyter]
args: [--fix]
# Run the formatter.
- id: ruff-format
types_or: [python, pyi, jupyter]
48 changes: 29 additions & 19 deletions delete.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
"import urllib.parse as urlparse\n",
"\n",
"import ipywidgets as widgets\n",
"from IPython.display import Markdown, display\n",
"\n",
"from aiida import load_profile\n",
"from aiida.orm import load_node\n",
"from aiida.tools import delete_nodes\n",
"from IPython.display import Markdown, display\n",
"\n",
"# Load AiiDA profile\n",
"load_profile()\n",
"\n",
"# Parse the primary key from the Jupyter notebook URL\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa F821\n",
"url = urlparse.urlsplit(jupyter_notebook_url) # noqa F821\n",
"query = urlparse.parse_qs(url.query)\n",
"pk = int(query['pk'][0])\n",
"pk = int(query[\"pk\"][0])\n",
"\n",
"\n",
"def display_node_details(pk):\n",
Expand All @@ -41,7 +42,7 @@
" print(f\"Description: {node.description}\")\n",
" print(f\"Creation Time: {node.ctime}\")\n",
" except Exception as e:\n",
" print(f\"Error loading node: {str(e)}\")\n",
" print(f\"Error loading node: {e!s}\")\n",
" return False\n",
" return True\n",
"\n",
Expand All @@ -50,31 +51,36 @@
" if dry_run:\n",
" _, was_deleted = delete_nodes([pk], dry_run=True)\n",
" if was_deleted:\n",
" print(f'Dry run: Node {pk} can be deleted.')\n",
" print(f\"Dry run: Node {pk} can be deleted.\")\n",
" return\n",
" \n",
"\n",
" _, was_deleted = delete_nodes([pk], dry_run=False)\n",
" if was_deleted:\n",
" print(f'Node {pk} deleted successfully.')\n",
" print(f\"Node {pk} deleted successfully.\")\n",
"\n",
"\n",
"def confirm_deletion(b):\n",
" if delete_confirmation.value.lower() in ['y', 'yes']:\n",
"def confirm_deletion(_):\n",
" if delete_confirmation.value.lower() in (\"y\", \"yes\"):\n",
" delete_node(pk, dry_run=False)\n",
" else:\n",
" print('Deletion aborted.')\n",
" print(\"Deletion aborted.\")\n",
"\n",
"\n",
"def find_linked_qeapp_jobs(root_node_pk, process_label='QeAppWorkChain'):\n",
"def find_linked_qeapp_jobs(root_node_pk, process_label=\"QeAppWorkChain\"):\n",
" \"\"\"Query all linked node with process_label = QeAppWorkChain.\"\"\"\n",
" from aiida.orm import Node, QueryBuilder\n",
" from aiida.orm.nodes.process.workflow.workchain import WorkChainNode\n",
"\n",
" qb = QueryBuilder()\n",
" qb.append(WorkChainNode, filters={'id': root_node_pk}, tag='root')\n",
" qb.append(Node, with_incoming='root', tag='calcjob')\n",
" qb.append(WorkChainNode, filters={\"id\": root_node_pk}, tag=\"root\")\n",
" qb.append(Node, with_incoming=\"root\", tag=\"calcjob\")\n",
" # There are seems a bug with `with_ancestors` in the QueryBuilder, so we have to use `with_incoming` instead.\n",
" # For the moment, it's safe to use `with_incoming` since we check it very time we delete a QEApp \n",
" qb.append(WorkChainNode, filters={'attributes.process_label': 'QeAppWorkChain'}, with_incoming='calcjob')\n",
" # For the moment, it's safe to use `with_incoming` since we check it very time we delete a QEApp\n",
" qb.append(\n",
" WorkChainNode,\n",
" filters={\"attributes.process_label\": process_label},\n",
" with_incoming=\"calcjob\",\n",
" )\n",
" results = qb.all()\n",
" if len(results) == 0:\n",
" return None\n",
Expand All @@ -96,12 +102,16 @@
" else:\n",
" # Ask for confirmation\n",
" nodes, _ = delete_nodes([pk], dry_run=True)\n",
" display(Markdown(f'**YOU ARE ABOUT TO DELETE `{len(nodes)}` NODES! THIS CANNOT BE UNDONE!**'))\n",
" display(\n",
" Markdown(\n",
" f\"**YOU ARE ABOUT TO DELETE `{len(nodes)}` NODES! THIS CANNOT BE UNDONE!**\"\n",
" )\n",
" )\n",
" delete_confirmation = widgets.Text(\n",
" value='',\n",
" value=\"\",\n",
" placeholder='Type \"yes\" to confirm',\n",
" description='Confirm:',\n",
" disabled=False\n",
" description=\"Confirm:\",\n",
" disabled=False,\n",
" )\n",
" confirm_button = widgets.Button(description=\"Delete Node\")\n",
" confirm_button.on_click(confirm_deletion)\n",
Expand Down
9 changes: 1 addition & 8 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
import time

# sys.path.insert(0, os.path.abspath('.'))

# -- Project information -----------------------------------------------------

version = "v24.10.0a1"
Expand All @@ -30,9 +25,7 @@
if current_year == copyright_first_year
else f"{copyright_first_year}-{current_year}"
)
copyright = "{}, {}. All rights reserved".format(
copyright_year_string, copyright_owners
)
copyright = f"{copyright_year_string}, {copyright_owners}. All rights reserved" # noqa: A001

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
Expand Down
Loading