From a7a0c3dbd3b28ace4f4faf1ac2a8bb8994ec8597 Mon Sep 17 00:00:00 2001 From: Alan Fleming <> Date: Tue, 30 Jan 2024 07:53:13 +1100 Subject: [PATCH] Ran hatch fmt (provides addnl rules for ruff) --- examples/autostart.ipynb | 24 +++++--- examples/commands.ipynb | 36 +++++++----- examples/icons.ipynb | 16 +++-- examples/ipytree.ipynb | 44 +++++++------- examples/main_area.ipynb | 19 +++--- examples/sessions.ipynb | 7 +-- examples/widgets.ipynb | 87 ++++++++++++++-------------- ipylab/__init__.py | 4 +- ipylab/_frontend.py | 3 +- ipylab/asyncwidget.py | 16 ++--- ipylab/commands.py | 4 +- ipylab/hookspecs.py | 9 +-- ipylab/jupyterfrontend_subsection.py | 2 +- ipylab/main_area.py | 2 +- pyproject.toml | 1 + 15 files changed, 148 insertions(+), 126 deletions(-) diff --git a/examples/autostart.ipynb b/examples/autostart.ipynb index db1fe45..6140225 100644 --- a/examples/autostart.ipynb +++ b/examples/autostart.ipynb @@ -40,18 +40,21 @@ "metadata": {}, "outputs": [], "source": [ - "# @my_module.autostart.py \n", + "# @my_module.autostart.py\n", "\n", - "import pluggy\n", "import asyncio\n", + "\n", "import ipylab\n", + "\n", "app = ipylab.JupyterFrontEnd()\n", "\n", + "\n", "def create_app():\n", " # Ensure this function provides all the imports.\n", - " import ipylab\n", " import ipywidgets as ipw\n", - " \n", + "\n", + " import ipylab\n", + "\n", " ma = ipylab.MainArea(name=\"My demo app\")\n", " console_button = ipw.Button(description=\"Toggle console\")\n", " console_button.on_click(\n", @@ -62,22 +65,25 @@ " console_button,\n", " ]\n", " ma.load()\n", - " print('Finshed creating my app')\n", + " print(\"Finshed creating my app\")\n", "\n", " # Retun ma so it doesn't accidentally get garbage collected.\n", - " return ma \n", + " return ma\n", + "\n", "\n", "async def load_app_async():\n", - " session = await app.newNotebook(path='my app')\n", - " kernelId = session['kernel']['id']\n", + " session = await app.newNotebook(path=\"my app\")\n", + " kernelId = session[\"kernel\"][\"id\"]\n", " await app.injectCode(kernelId, create_app)\n", " print(\"Done\")\n", "\n", + "\n", "class MyPlugins:\n", " @ipylab.hookspecs.hookimpl()\n", " def run_once_at_startup(self):\n", " asyncio.create_task(load_app_async())\n", - " \n", + "\n", + "\n", "MyPlugins()" ] }, diff --git a/examples/commands.ipynb b/examples/commands.ipynb index f1d9412..6c05450 100644 --- a/examples/commands.ipynb +++ b/examples/commands.ipynb @@ -29,9 +29,10 @@ "metadata": {}, "outputs": [], "source": [ - "import ipylab\n", "import ipywidgets as ipw\n", "\n", + "import ipylab\n", + "\n", "app = ipylab.JupyterFrontEnd()" ] }, @@ -77,7 +78,7 @@ " \"console:create\",\n", " insertMode=\"split-right\",\n", " kernelPreference={\"id\": app.kernelId},\n", - " transform={\"mode\": ipylab.TransformMode.attribute, \"parts\": [\"id\"]}, #optional\n", + " transform={\"mode\": ipylab.TransformMode.attribute, \"parts\": [\"id\"]}, # optional\n", ")" ] }, @@ -103,7 +104,7 @@ "metadata": {}, "outputs": [], "source": [ - "app.commands.execute('apputils:change-theme', theme = 'JupyterLab Dark')" + "app.commands.execute(\"apputils:change-theme\", theme=\"JupyterLab Dark\")" ] }, { @@ -112,7 +113,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.commands.execute('apputils:change-theme', theme = 'JupyterLab Light')" + "t = app.commands.execute(\"apputils:change-theme\", theme=\"JupyterLab Light\")" ] }, { @@ -137,7 +138,7 @@ "metadata": {}, "outputs": [], "source": [ - "app.commands.execute('terminal:create-new')\n", + "app.commands.execute(\"terminal:create-new\")\n", "# It can take up to 10 seconds for the terminal to show up after the cell returns." ] }, @@ -156,7 +157,9 @@ "metadata": {}, "outputs": [], "source": [ - "split_panel = ipylab.SplitPanel(children = [ipw.Button(description=\"Item A\"), ipw.Button(description=\"Item B\")])\n", + "split_panel = ipylab.SplitPanel(\n", + " children=[ipw.Button(description=\"Item A\"), ipw.Button(description=\"Item B\")]\n", + ")\n", "split_panel.addToShell()" ] }, @@ -174,7 +177,9 @@ "outputs": [], "source": [ "def toggle_orientation():\n", - " split_panel.orientation = list({'horizontal', 'vertical'}.difference((split_panel.orientation,)))[0]\n", + " split_panel.orientation = list(\n", + " {\"horizontal\", \"vertical\"}.difference((split_panel.orientation,))\n", + " )[0]\n", " split_panel.title.label = split_panel.orientation\n", " return \"Data returned from this custom function 'toggle_orientation'\"" ] @@ -203,7 +208,12 @@ "metadata": {}, "outputs": [], "source": [ - "app.commands.addPythonCommand('swap_orientation', execute=toggle_orientation, label=\"Swap orientation\", icon_class=\"jp-PythonIcon\")" + "app.commands.addPythonCommand(\n", + " \"swap_orientation\",\n", + " execute=toggle_orientation,\n", + " label=\"Swap orientation\",\n", + " icon_class=\"jp-PythonIcon\",\n", + ")" ] }, { @@ -219,7 +229,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.commands.execute('swap_orientation')" + "t = app.commands.execute(\"swap_orientation\")" ] }, { @@ -260,7 +270,7 @@ "metadata": {}, "outputs": [], "source": [ - "assert 'swap_orientation' in app.commands.commands" + "assert \"swap_orientation\" in app.commands.commands" ] }, { @@ -283,7 +293,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.command_pallet.add_item('swap_orientation', 'Python Commands')" + "t = app.command_pallet.add_item(\"swap_orientation\", \"Python Commands\")" ] }, { @@ -317,7 +327,7 @@ "metadata": {}, "outputs": [], "source": [ - "app.commands.remove_command('swap_orientation')" + "app.commands.remove_command(\"swap_orientation\")" ] }, { @@ -326,7 +336,7 @@ "metadata": {}, "outputs": [], "source": [ - "assert 'swap_orientation' not in app.commands.commands" + "assert \"swap_orientation\" not in app.commands.commands" ] } ], diff --git a/examples/icons.ipynb b/examples/icons.ipynb index acf0d3e..7f3f598 100644 --- a/examples/icons.ipynb +++ b/examples/icons.ipynb @@ -35,10 +35,12 @@ }, "outputs": [], "source": [ - "import ipylab\n", + "import json\n", + "\n", "import ipywidgets as ipw\n", "import traitlets\n", - "import json" + "\n", + "import ipylab" ] }, { @@ -116,7 +118,9 @@ "background = ipw.SelectionSlider(description=\"background\", options=options)\n", "foreground = ipw.SelectionSlider(description=\"foreground\", options=options)\n", "\n", - "repaint = lambda: SVG.replace(\"jp-icon3\", background.value).replace(\"jp-contrast0\", foreground.value)\n", + "repaint = lambda: SVG.replace(\"jp-icon3\", background.value).replace(\n", + " \"jp-contrast0\", foreground.value\n", + ")\n", "\n", "traitlets.dlink((background, \"value\"), (icon, \"svgstr\"), lambda x: SVG.replace(\"jp-icon3\", x))\n", "traitlets.dlink((foreground, \"value\"), (icon, \"svgstr\"), lambda x: SVG.replace(\"jp-contrast0\", x))\n", @@ -171,11 +175,10 @@ }, "outputs": [], "source": [ - "\n", - "\n", "def noop(value):\n", " return value\n", "\n", + "\n", "def as_json(value):\n", " try:\n", " return json.loads(value)\n", @@ -188,7 +191,7 @@ " link_fn = noop\n", " placeholder = \"\"\n", " if field_name == \"dataset\":\n", - " placeholder = \"{}\" \n", + " placeholder = \"{}\"\n", " link_fn = as_json\n", " field = ipw.Text(description=field_name, placeholder=placeholder)\n", " traitlets.dlink((field, \"value\"), (panel.title, field_name), link_fn)\n", @@ -221,6 +224,7 @@ "import asyncio\n", "import random\n", "\n", + "\n", "async def randomize_icon(count=10):\n", " for i in range(count):\n", " background.value = random.choice(options)\n", diff --git a/examples/ipytree.ipynb b/examples/ipytree.ipynb index 4731ebc..dd73a29 100644 --- a/examples/ipytree.ipynb +++ b/examples/ipytree.ipynb @@ -31,7 +31,6 @@ "outputs": [], "source": [ "import os\n", - "\n", "from pathlib import PurePath" ] }, @@ -57,7 +56,7 @@ " \"lib\",\n", " \"node_modules\",\n", " \"__pycache__\",\n", - " \".ipynb_checkpoints\"\n", + " \".ipynb_checkpoints\",\n", "}" ] }, @@ -74,7 +73,7 @@ "metadata": {}, "outputs": [], "source": [ - "def collect_files(root_path='..'):\n", + "def collect_files(root_path=\"..\"):\n", " files = []\n", " for dirpath, dirnames, filenames in os.walk(root_path, followlinks=True):\n", " dirnames[:] = [d for d in dirnames if d not in EXCLUDES]\n", @@ -190,13 +189,13 @@ " if len(children) == 0:\n", " leaf = TreeNode(name)\n", " leaf.fullpath = os.path.join(*fullpath)\n", - " leaf.icon = 'file'\n", - " leaf.icon_style = 'warning'\n", + " leaf.icon = \"file\"\n", + " leaf.icon_style = \"warning\"\n", " node.add_node(leaf)\n", " else:\n", " subtree = create_tree_widget(children, fullpath, depth + 1)\n", - " subtree.icon = 'folder'\n", - " subtree.icon_style = 'info'\n", + " subtree.icon = \"folder\"\n", + " subtree.icon_style = \"info\"\n", " subtree.name = name\n", " node.add_node(subtree)\n", " return node" @@ -273,16 +272,12 @@ "metadata": {}, "outputs": [], "source": [ - "from ipywidgets import Button, Layout, HBox\n", + "from ipywidgets import Button, HBox, Layout\n", "\n", - "open_button = Button(description='Open', button_style='success', icon='folder')\n", - "expand_button = Button(description='Expand', button_style='info', icon='chevron-down')\n", - "collapse_button = Button(description='Collapse', button_style='info', icon='chevron-right')\n", - "hbox = HBox([\n", - " open_button,\n", - " expand_button,\n", - " collapse_button\n", - "], layout=Layout(overflow='unset'))\n", + "open_button = Button(description=\"Open\", button_style=\"success\", icon=\"folder\")\n", + "expand_button = Button(description=\"Expand\", button_style=\"info\", icon=\"chevron-down\")\n", + "collapse_button = Button(description=\"Collapse\", button_style=\"info\", icon=\"chevron-right\")\n", + "hbox = HBox([open_button, expand_button, collapse_button], layout=Layout(overflow=\"unset\"))\n", "hbox" ] }, @@ -303,13 +298,15 @@ " for node in tree.nodes:\n", " node.opened = expand\n", "\n", + "\n", "def on_expand_click(b):\n", " expand_tree(file_tree)\n", "\n", - " \n", + "\n", "def on_collapse_click(b):\n", " expand_tree(file_tree, False)\n", "\n", + "\n", "expand_button.on_click(on_expand_click)\n", "collapse_button.on_click(on_collapse_click)" ] @@ -331,7 +328,8 @@ " for node in file_tree.selected_nodes:\n", " filepath = node.fullpath\n", " if filepath:\n", - " app.commands.execute('docmanager:open', { 'path': filepath})\n", + " app.commands.execute(\"docmanager:open\", {\"path\": filepath})\n", + "\n", "\n", "open_button.on_click(on_open_clicked)" ] @@ -350,7 +348,7 @@ "outputs": [], "source": [ "expand_tree(file_tree, False)\n", - "file_tree.layout = Layout(overflow='auto')" + "file_tree.layout = Layout(overflow=\"auto\")" ] }, { @@ -369,9 +367,9 @@ "from ipylab import Panel\n", "\n", "panel = Panel(children=[hbox, file_tree])\n", - "panel.title.label = 'File Browser'\n", - "panel.title.icon_class = 'jp-FileIcon'\n", - "panel.layout = Layout(overflow='auto')" + "panel.title.label = \"File Browser\"\n", + "panel.title.icon_class = \"jp-FileIcon\"\n", + "panel.layout = Layout(overflow=\"auto\")" ] }, { @@ -387,7 +385,7 @@ "metadata": {}, "outputs": [], "source": [ - "app.shell.add(panel, 'left', {'rank': 10000})" + "app.shell.add(panel, \"left\", {\"rank\": 10000})" ] }, { diff --git a/examples/main_area.ipynb b/examples/main_area.ipynb index 7bd749d..8515f24 100644 --- a/examples/main_area.ipynb +++ b/examples/main_area.ipynb @@ -27,8 +27,9 @@ "metadata": {}, "outputs": [], "source": [ - "import ipylab\n", - "import ipywidgets as ipw" + "import ipywidgets as ipw\n", + "\n", + "import ipylab" ] }, { @@ -37,7 +38,7 @@ "metadata": {}, "outputs": [], "source": [ - "ma = ipylab.MainArea(name='My main area')" + "ma = ipylab.MainArea(name=\"My main area\")" ] }, { @@ -67,11 +68,15 @@ "outputs": [], "source": [ "some_html = ipw.HTML(\"This children can be swapped out as required.\")\n", - "console_button = ipw.Button(description='Toggle console')\n", + "console_button = ipw.Button(description=\"Toggle console\")\n", + "\n", + "\n", "def on_click(b):\n", " ma.load_console() if not ma.console_loaded else ma.unload_console()\n", + "\n", + "\n", "console_button.on_click(on_click)\n", - "close_button = ipw.Button(description='Close')\n", + "close_button = ipw.Button(description=\"Close\")\n", "close_button.on_click(lambda b: ma.close())\n", "ma.content.children = [some_html, console_button, close_button]" ] @@ -106,7 +111,7 @@ } ], "source": [ - "ma.load(area='main')" + "ma.load(area=\"main\")" ] }, { @@ -115,7 +120,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = ma.load_console(name='my console',mode=ipylab.InsertMode.merge_left, path='my own path')" + "t = ma.load_console(name=\"my console\", mode=ipylab.InsertMode.merge_left, path=\"my own path\")" ] }, { diff --git a/examples/sessions.ipynb b/examples/sessions.ipynb index 65f9dce..4163ae8 100644 --- a/examples/sessions.ipynb +++ b/examples/sessions.ipynb @@ -22,8 +22,7 @@ "metadata": {}, "outputs": [], "source": [ - "import ipylab\n", - "import asyncio" + "import ipylab" ] }, { @@ -81,7 +80,7 @@ "metadata": {}, "outputs": [], "source": [ - "app.commands.execute('console:create', **app.current_session)" + "app.commands.execute(\"console:create\", **app.current_session)" ] }, { @@ -90,7 +89,7 @@ "metadata": {}, "outputs": [], "source": [ - "app.commands.execute('notebook:create-console')" + "app.commands.execute(\"notebook:create-console\")" ] } ], diff --git a/examples/widgets.ipynb b/examples/widgets.ipynb index c4c9576..ac3a8e4 100644 --- a/examples/widgets.ipynb +++ b/examples/widgets.ipynb @@ -22,8 +22,9 @@ "metadata": {}, "outputs": [], "source": [ - "import ipylab\n", - "import ipywidgets as ipw" + "import ipywidgets as ipw\n", + "\n", + "import ipylab" ] }, { @@ -82,7 +83,7 @@ "metadata": {}, "outputs": [], "source": [ - "panel.title.label = 'This panel has a dropdown'" + "panel.title.label = \"This panel has a dropdown\"" ] }, { @@ -122,7 +123,7 @@ "outputs": [], "source": [ "slider = ipw.IntSlider()\n", - "panel.app.shell.addToShell(slider,area='top')" + "panel.app.shell.addToShell(slider, area=\"top\")" ] }, { @@ -164,22 +165,24 @@ " min=0,\n", " max=100,\n", " step=1,\n", - " description='Loading:',\n", - " bar_style='info',\n", - " orientation='horizontal',\n", - " layout={\"height\":'30px'}\n", + " description=\"Loading:\",\n", + " bar_style=\"info\",\n", + " orientation=\"horizontal\",\n", + " layout={\"height\": \"30px\"},\n", + ")\n", + "slider_ctrl = ipw.IntSlider(\n", + " min=0,\n", + " max=100,\n", + " step=1,\n", + " description=\"Slider Control:\",\n", ")\n", - "slider_ctrl = ipw.IntSlider(min=0, max=100, step=1, description='Slider Control:',)\n", "\n", "# link the slider to the progress bar\n", - "ipw.jslink((slider_ctrl, 'value'), (progress, 'value'))\n", + "ipw.jslink((slider_ctrl, \"value\"), (progress, \"value\"))\n", "\n", "# add the widgets to the split panel\n", - "split_panel.children = [\n", - " progress,\n", - " slider_ctrl\n", - "]\n", - "ipw.Box(children=[split_panel], layout={'height':'100px'})" + "split_panel.children = [progress, slider_ctrl]\n", + "ipw.Box(children=[split_panel], layout={\"height\": \"100px\"})" ] }, { @@ -188,8 +191,8 @@ "metadata": {}, "outputs": [], "source": [ - "split_panel.title.label = 'A SplitPanel '\n", - "split_panel.title.icon_class = 'jp-PythonIcon'\n", + "split_panel.title.label = \"A SplitPanel \"\n", + "split_panel.title.icon_class = \"jp-PythonIcon\"\n", "split_panel.title.closable = True" ] }, @@ -206,7 +209,7 @@ "metadata": {}, "outputs": [], "source": [ - "split_panel.addToShell('main', mode= 'split-bottom')" + "split_panel.addToShell(\"main\", mode=\"split-bottom\")" ] }, { @@ -222,7 +225,7 @@ "metadata": {}, "outputs": [], "source": [ - "split_panel.orientation = 'horizontal'" + "split_panel.orientation = \"horizontal\"" ] }, { @@ -238,7 +241,7 @@ "metadata": {}, "outputs": [], "source": [ - "split_panel.orientation = 'vertical'" + "split_panel.orientation = \"vertical\"" ] }, { @@ -270,13 +273,8 @@ "metadata": {}, "outputs": [], "source": [ - "play = ipw.Play(\n", - " min=0,\n", - " max=100,\n", - " step=1,\n", - " description=\"Press play\"\n", - ")\n", - "ipw.jslink((play, 'value'), (slider_ctrl, 'value'))\n", + "play = ipw.Play(min=0, max=100, step=1, description=\"Press play\")\n", + "ipw.jslink((play, \"value\"), (slider_ctrl, \"value\"))\n", "split_panel.children += (play,)" ] }, @@ -295,7 +293,7 @@ "metadata": {}, "outputs": [], "source": [ - "split_panel.addToShell(area='left', rank = 1000)\n", + "split_panel.addToShell(area=\"left\", rank=1000)\n", "split_panel.app.shell.expandLeft()" ] }, @@ -312,7 +310,7 @@ "metadata": {}, "outputs": [], "source": [ - "split_panel.addToShell(area='right', rank = 1000)\n", + "split_panel.addToShell(area=\"right\", rank=1000)\n", "split_panel.app.shell.expandRight()" ] }, @@ -324,7 +322,7 @@ }, "outputs": [], "source": [ - "t= split_panel.app.execute_method('app.shell.expandRight')" + "t = split_panel.app.execute_method(\"app.shell.expandRight\")" ] }, { @@ -351,7 +349,7 @@ "outputs": [], "source": [ "app = ipylab.JupyterFrontEnd()\n", - "assert app is panel.app is split_panel.app " + "assert app is panel.app is split_panel.app" ] }, { @@ -389,7 +387,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.dialog.get_item('Select an item', [1,2,3])" + "t = app.dialog.get_item(\"Select an item\", [1, 2, 3])" ] }, { @@ -414,7 +412,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.dialog.get_boolean('Select boolean value')" + "t = app.dialog.get_boolean(\"Select boolean value\")" ] }, { @@ -439,7 +437,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.dialog.get_number('Provide a numeric value')" + "t = app.dialog.get_number(\"Provide a numeric value\")" ] }, { @@ -464,7 +462,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.dialog.get_text('Enter text')" + "t = app.dialog.get_text(\"Enter text\")" ] }, { @@ -491,7 +489,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.dialog.get_password('Provide a password')" + "t = app.dialog.get_password(\"Provide a password\")" ] }, { @@ -509,7 +507,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "t = app.dialog.show_dialog(\n", " \"A custom dialog\",\n", " \"It returns the raw result, and there is no cancellation\",\n", @@ -521,7 +518,7 @@ " \"iconLabel\": \"\",\n", " \"caption\": \"Accept the result\",\n", " \"className\": \"\",\n", - " \"accept\": 'accept',\n", + " \"accept\": \"accept\",\n", " \"actions\": [],\n", " \"displayType\": \"warn\",\n", " },\n", @@ -543,7 +540,7 @@ " \"className\": \"my-checkbox\", # Additional checkbox CSS class\n", " \"checked\": True, # Default checkbox state\n", " },\n", - " hasClose=False\n", + " hasClose=False,\n", ")" ] }, @@ -562,8 +559,10 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.dialog.show_error_message('My error', 'Please acknowledge',\n", - " buttons=[\n", + "t = app.dialog.show_error_message(\n", + " \"My error\",\n", + " \"Please acknowledge\",\n", + " buttons=[\n", " {\n", " \"ariaLabel\": \"Accept\",\n", " \"label\": \"Accept\",\n", @@ -571,10 +570,12 @@ " \"iconLabel\": \"\",\n", " \"caption\": \"Accept the result\",\n", " \"className\": \"\",\n", - " \"accept\": 'accept',\n", + " \"accept\": \"accept\",\n", " \"actions\": [],\n", " \"displayType\": \"warn\",\n", - " }])" + " }\n", + " ],\n", + ")" ] }, { diff --git a/ipylab/__init__.py b/ipylab/__init__.py index e874112..a29f841 100644 --- a/ipylab/__init__.py +++ b/ipylab/__init__.py @@ -2,7 +2,7 @@ # Distributed under the terms of the Modified BSD License. from __future__ import annotations -from ._version import __version__ # noqa: F401 +from ._version import __version__ __all__ = [ "__version__", @@ -22,13 +22,13 @@ ] """Marker to be imported and used in plugins (and for own implementations)""" +from ipylab import hookspecs from ipylab.asyncwidget import TransformMode, pack from ipylab.hasapp import HasApp from ipylab.jupyterfrontend import JupyterFrontEnd, LauncherOptions from ipylab.main_area import MainArea from ipylab.shell import Area, InsertMode from ipylab.widgets import Icon, Panel, SplitPanel -from ipylab import hookspecs def _jupyter_labextension_paths(): diff --git a/ipylab/_frontend.py b/ipylab/_frontend.py index cf9a65d..745bc80 100644 --- a/ipylab/_frontend.py +++ b/ipylab/_frontend.py @@ -1,4 +1,5 @@ -import pathlib, json +import json +import pathlib module_name = "ipylab" diff --git a/ipylab/asyncwidget.py b/ipylab/asyncwidget.py index cecf62d..23fcaa3 100644 --- a/ipylab/asyncwidget.py +++ b/ipylab/asyncwidget.py @@ -5,7 +5,8 @@ import asyncio import enum import uuid -from typing import Any, Callable, Coroutine +from collections.abc import Callable, Coroutine +from typing import Any from IPython.core.getipython import get_ipython from ipywidgets import Widget, register, widget_serialization @@ -44,8 +45,8 @@ class TransformMode(enum.StrEnum): --------- ``` transform = { - mode: 'attribute', - parts: ['dotted.attribute.name', ...] # default transform is 'raw' + mode: "attribute", + parts: ["dotted.attribute.name", ...], # default transform is 'raw' } ``` @@ -61,12 +62,7 @@ class TransformMode(enum.StrEnum): JS code defining a function and returning data. ``` - transform = { - mode: 'function', - code: 'function (obj) { return String(obj); }' - } - - """ + transform = {mode: "function", code: "function (obj) { return String(obj); }"}""" raw = "raw" done = "done" @@ -107,7 +103,7 @@ class AsyncWidgetBase(WidgetBase): """The base for all widgets that need async comms with the frontend model.""" kernelId = Unicode(KERNEL_ID, read_only=True).tag(sync=True) - _ipylab_model_register: dict[str, "AsyncWidgetBase"] = {} + _ipylab_model_register: dict[str, AsyncWidgetBase] = {} _singleton_register: dict[type, str] = {} SINGLETON = False _ready_response = Instance(Response, ()) diff --git a/ipylab/commands.py b/ipylab/commands.py index 62ca60d..5e69a52 100644 --- a/ipylab/commands.py +++ b/ipylab/commands.py @@ -2,12 +2,12 @@ # Distributed under the terms of the Modified BSD License. import asyncio -from typing import Callable +from collections.abc import Callable from traitlets import Dict, Tuple, Unicode, observe -from ipylab.hookspecs import pm from ipylab.asyncwidget import AsyncWidgetBase, TransformMode, pack, register +from ipylab.hookspecs import pm from ipylab.widgets import Icon diff --git a/ipylab/hookspecs.py b/ipylab/hookspecs.py index bb748a5..c2d08ac 100644 --- a/ipylab/hookspecs.py +++ b/ipylab/hookspecs.py @@ -55,12 +55,13 @@ def run_once_at_startup(self): """The function will run once when Ipylab is activated (requires entry point as explained below). ``` python - @ipylab.hookimpl(specname="run_once_at_startup") def plugin_my_launcher() -> LauncherOptions: - options = LauncherOptions(name="Launch my app", - tooltip="My app is great...", - entry_point='my_module.my_attr.start_my_app') + options = LauncherOptions( + name="Launch my app", + tooltip="My app is great...", + entry_point="my_module.my_attr.start_my_app", + ) return options ``` diff --git a/ipylab/jupyterfrontend_subsection.py b/ipylab/jupyterfrontend_subsection.py index 9763a04..659e26c 100644 --- a/ipylab/jupyterfrontend_subsection.py +++ b/ipylab/jupyterfrontend_subsection.py @@ -2,7 +2,7 @@ # Distributed under the terms of the Modified BSD License. import asyncio -from typing import Callable, Coroutine +from collections.abc import Callable, Coroutine from ipylab import TransformMode from ipylab.hasapp import HasApp diff --git a/ipylab/main_area.py b/ipylab/main_area.py index 02eb469..a326781 100644 --- a/ipylab/main_area.py +++ b/ipylab/main_area.py @@ -22,7 +22,7 @@ class MainArea(AsyncWidgetBase, HasApp): Also provides methods to open/close a console using the context of the loaded widget. """ - _main_area_names: dict[str, "MainArea"] = {} + _main_area_names: dict[str, MainArea] = {} _model_name = Unicode("MainAreaModel").tag(sync=True) path = Unicode(read_only=True).tag(sync=True) diff --git a/pyproject.toml b/pyproject.toml index 2f297a9..dea927e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,6 +86,7 @@ before-build-python = ["jlpm clean:all"] [tool.check-wheel-contents] ignore = ["W002"] + [tool.ruff] target-version = "py311" line-length = 100