Skip to content

Commit

Permalink
Use hatch format settings for ruff.
Browse files Browse the repository at this point in the history
Type hint and type checking fixes.
Minimum Python v3.11.
  • Loading branch information
Alan Fleming committed Apr 6, 2024
1 parent 38e4015 commit 59febaa
Show file tree
Hide file tree
Showing 22 changed files with 799 additions and 332 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ repos:
- id: requirements-txt-fixer
- id: check-builtin-literals
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
rev: 0.28.1
hooks:
- id: check-github-workflows
- repo: https://github.com/ComPWA/mirrors-taplo
rev: 'v0.8.1'
hooks:
- id: taplo
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
rev: v0.3.5
hooks:
- id: ruff
types_or: [python, jupyter]
args: ['--fix', '--show-fixes']
args: ['--fix']
- id: ruff-format
types_or: [python, jupyter]
- repo: https://github.com/codespell-project/codespell
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
},
"editor.formatOnSave": true,
"python.terminal.activateEnvInCurrentTerminal": true,
"python.createEnvironment.trigger": "prompt"
"python.createEnvironment.trigger": "prompt",
"python.analysis.typeCheckingMode": "basic"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jupyter lab

```bash
# create a new conda environment
mamba create -n ipylab -c conda-forge jupyter-packaging nodejs python=3.10 -y
mamba create -n ipylab -c conda-forge jupyter-packaging nodejs python=3.11 -y

# activate the environment
conda activate ipylab
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations
from __future__ import annotations # noqa: INP001

extensions = ["myst_parser", "jupyterlite_sphinx"]

Expand Down
29 changes: 15 additions & 14 deletions examples/autostart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@
"source": [
"# @my_module.autostart.py\n",
"\n",
"import asyncio\n",
"\n",
"import ipylab\n",
"\n",
"\n",
"async def create_app():\n",
" # The code in this function is called in the new kernel (session).\n",
" # Ensure imports are performed inside the function.\n",
" global ma\n",
" import ipywidgets as ipw\n",
"\n",
" import ipylab\n",
"\n",
" global ma # noqa: PLW0603\n",
"\n",
" ma = ipylab.MainArea(name=\"My demo app\")\n",
" await ma.wait_ready()\n",
" ma.content.title.label = \"Simple app\"\n",
Expand All @@ -86,10 +91,8 @@
" tooltip=\"An error dialog will pop up when this is clicked.\\n\"\n",
" \"The dialog demonstrates the use of the `on_frontend_error` plugin.\",\n",
" )\n",
" console_button.on_click(\n",
" lambda b: ma.load_console() if ma.console_status == \"unloaded\" else ma.unload_console()\n",
" )\n",
" error_button.on_click(lambda b: ma.executeCommand(\"Not a command\"))\n",
" console_button.on_click(lambda _: ma.load_console() if ma.console_status == \"unloaded\" else ma.unload_console())\n",
" error_button.on_click(lambda _: ma.executeCommand(\"Not a command\"))\n",
" ma.content.children = [\n",
" ipw.HTML(f\"<h3>My simple app</h3> Welcome to my app.<br> kernel id: {ma.kernelId}\"),\n",
" ipw.HBox([console_button, error_button]),\n",
Expand All @@ -105,27 +108,25 @@
" class IpylabPlugins:\n",
" # Define plugins (see IpylabHookspec for available hooks)\n",
" @ipylab.hookimpl\n",
" def on_frontend_error(self, obj, error, content):\n",
" def on_frontend_error(self, obj, error, content): # noqa: ARG002\n",
" ma.app.dialog.show_error_message(\"Error\", str(error))\n",
"\n",
" # Register plugin for this kernel.\n",
" ipylab.hookspecs.pm.register(IpylabPlugins())\n",
" ipylab.hookspecs.pm.register(IpylabPlugins()) # type: ignore\n",
" await ma.load()\n",
"\n",
"\n",
"import asyncio\n",
"\n",
"import ipylab\n",
"\n",
"n = 0\n",
"app = ipylab.JupyterFrontEnd()\n",
"\n",
"\n",
"async def start_my_app(cwd):\n",
" global n\n",
"async def start_my_app(cwd): # noqa: ARG001\n",
" global n # noqa: PLW0603\n",
" n += 1\n",
" task = app.execEval(\n",
" code=create_app, user_expressions={\"main_area_widget\": \"create_app()\"}, path=f\"my app {n}\"\n",
" code=create_app,\n",
" user_expressions={\"main_area_widget\": \"create_app()\"},\n",
" path=f\"my app {n}\",\n",
" )\n",
" if app.current_widget_id.startswith(\"launcher\"):\n",
" await app.executeMethod(\"app.shell.currentWidget.dispose\")\n",
Expand Down
19 changes: 11 additions & 8 deletions examples/commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@
"metadata": {},
"outputs": [],
"source": [
"split_panel = ipylab.SplitPanel(\n",
" children=[ipw.Button(description=\"Item A\"), ipw.Button(description=\"Item B\")]\n",
")\n",
"split_panel = ipylab.SplitPanel(children=[ipw.Button(description=\"Item A\"), ipw.Button(description=\"Item B\")])\n",
"split_panel.addToShell()"
]
},
Expand All @@ -177,9 +175,7 @@
"outputs": [],
"source": [
"def toggle_orientation():\n",
" split_panel.orientation = list(\n",
" {\"horizontal\", \"vertical\"}.difference((split_panel.orientation,))\n",
" )[0]\n",
" split_panel.orientation = next(iter({\"horizontal\", \"vertical\"}.difference((split_panel.orientation,))))\n",
" split_panel.title.label = split_panel.orientation\n",
" return \"Data returned from this custom function 'toggle_orientation'\""
]
Expand Down Expand Up @@ -264,13 +260,20 @@
"Also the list of commands gets updated with the newly added command:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assert \"swap_orientation\" in app.command.commands"
"assert \"swap_orientation\" in app.command.commands # noqa: S101"
]
},
{
Expand Down Expand Up @@ -354,7 +357,7 @@
"metadata": {},
"outputs": [],
"source": [
"assert \"swap_orientation\" not in app.command.commands"
"assert \"swap_orientation\" not in app.command.commands # noqa: S101"
]
}
],
Expand Down
Loading

0 comments on commit 59febaa

Please sign in to comment.