Falko Schindler 1 рік тому
батько
коміт
40b86e526a

+ 7 - 6
.github/workflows/update_citation.py

@@ -1,11 +1,13 @@
 import os
 import sys
+from pathlib import Path
+from typing import Tuple
 
 import requests
 import yaml
 
 
-def get_infos() -> str:
+def get_infos() -> Tuple[str]:
     headers = {
         'Accept': 'application/json',
     }
@@ -16,7 +18,7 @@ def get_infos() -> str:
         'status': 'published',
     }
     try:
-        response = requests.get('https://zenodo.org/api/records', params=params, headers=headers)
+        response = requests.get('https://zenodo.org/api/records', params=params, headers=headers, timeout=5)
         response.raise_for_status()
     # Hide all error details to avoid leaking the token
     except Exception:
@@ -27,8 +29,7 @@ def get_infos() -> str:
 
 
 if __name__ == '__main__':
-    with open('CITATION.cff', 'r') as file:
-        citation = yaml.safe_load(file)
+    path = Path('CITATION.cff')
+    citation = yaml.safe_load(path.read_text())
     citation['doi'], citation['version'], citation['date-released'] = get_infos()
-    with open('CITATION.cff', 'w') as file:
-        yaml.dump(citation, file, sort_keys=False, default_flow_style=False)
+    path.write_text(yaml.dump(citation, sort_keys=False, default_flow_style=False))

+ 0 - 0
nicegui/elements/__init__.py


+ 3 - 1
nicegui/elements/card.py

@@ -1,3 +1,5 @@
+from typing_extensions import Self
+
 from ..element import Element
 
 
@@ -18,7 +20,7 @@ class Card(Element):
         super().__init__('q-card')
         self._classes = ['nicegui-card']
 
-    def tight(self):
+    def tight(self) -> Self:
         """Removes padding and gaps between nested elements."""
         self._classes.clear()
         self._style.clear()

+ 12 - 11
nicegui/nicegui.py

@@ -13,7 +13,8 @@ from fastapi_socketio import SocketManager
 from nicegui import json
 from nicegui.json import NiceGUIJSONResponse
 
-from . import __version__, background_tasks, binding, favicon, globals, outbox, welcome
+from . import (__version__, background_tasks, binding, favicon, globals, outbox,  # pylint: disable=redefined-builtin
+               welcome)
 from .app import App
 from .client import Client
 from .dependencies import js_components, libraries
@@ -25,7 +26,7 @@ from .page import page
 globals.app = app = App(default_response_class=NiceGUIJSONResponse)
 # NOTE we use custom json module which wraps orjson
 socket_manager = SocketManager(app=app, mount_location='/_nicegui_ws/', json=json)
-globals.sio = sio = socket_manager._sio
+globals.sio = sio = socket_manager._sio  # pylint: disable=protected-access
 
 app.add_middleware(GZipMiddleware)
 static_files = StaticFiles(
@@ -34,7 +35,7 @@ static_files = StaticFiles(
 )
 app.mount(f'/_nicegui/{__version__}/static', static_files, name='static')
 
-globals.index_client = Client(page('/'), shared=True).__enter__()
+globals.index_client = Client(page('/'), shared=True).__enter__()  # pylint: disable=unnecessary-dunder-call
 
 
 @app.get('/')
@@ -176,7 +177,7 @@ def handle_event(client: Client, msg: Dict) -> None:
             msg['args'] = [None if arg is None else json.loads(arg) for arg in msg.get('args', [])]
             if len(msg['args']) == 1:
                 msg['args'] = msg['args'][0]
-            sender._handle_event(msg)
+            sender._handle_event(msg)  # pylint: disable=protected-access
 
 
 @sio.on('javascript_response')
@@ -200,13 +201,13 @@ def get_client(sid: str) -> Optional[Client]:
 
 async def prune_clients() -> None:
     while True:
-        stale = [
+        stale_clients = [
             id
             for id, client in globals.clients.items()
             if not client.shared and not client.has_socket_connection and client.created < time.time() - 60.0
         ]
-        for id in stale:
-            delete_client(id)
+        for client_id in stale_clients:
+            delete_client(client_id)
         await asyncio.sleep(10)
 
 
@@ -227,8 +228,8 @@ async def prune_slot_stacks() -> None:
         await asyncio.sleep(10)
 
 
-def delete_client(id: str) -> None:
-    binding.remove(list(globals.clients[id].elements.values()), Element)
-    for element in globals.clients[id].elements.values():
+def delete_client(client_id: str) -> None:
+    binding.remove(list(globals.clients[client_id].elements.values()), Element)
+    for element in globals.clients[client_id].elements.values():
         element.delete()
-    del globals.clients[id]
+    del globals.clients[client_id]

+ 2 - 2
nicegui/ui.py

@@ -119,7 +119,7 @@ from .elements.grid import Grid as grid
 from .elements.html import Html as html
 from .elements.icon import Icon as icon
 from .elements.image import Image as image
-from .elements.input import Input as input
+from .elements.input import Input as input  # pylint: disable=redefined-builtin
 from .elements.interactive_image import InteractiveImage as interactive_image
 from .elements.joystick import Joystick as joystick
 from .elements.json_editor import JsonEditor as json_editor
@@ -169,7 +169,7 @@ from .functions.download import download
 from .functions.html import add_body_html, add_head_html
 from .functions.javascript import run_javascript
 from .functions.notify import notify
-from .functions.open import open
+from .functions.open import open  # pylint: disable=redefined-builtin
 from .functions.refreshable import refreshable
 from .functions.timer import Timer as timer
 from .functions.update import update

+ 3 - 4
npm.py

@@ -1,6 +1,5 @@
 #!/usr/bin/env python3
-"""
-Update dependencies according to npm.json configurations using the NPM packagist.
+"""Update dependencies according to npm.json configurations using the NPM packagist.
 
 npm.json file is a JSON object key => dependency.
 
@@ -66,8 +65,8 @@ for key, dependency in dependencies.items():
 
     # Handle the special case of tailwind. Hopefully remove this soon.
     if 'download' in dependency:
-        path = download_buffered(dependency['download'])
-        shutil.copyfile(path, prepare(Path(destination, dependency['rename'])))
+        download_path = download_buffered(dependency['download'])
+        shutil.copyfile(download_path, prepare(Path(destination, dependency['rename'])))
 
     # Download and extract.
     tgz_file = prepare(Path(tmp, key, f'{key}.tgz'))

+ 1 - 1
setup.py

@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-from distutils.core import setup
+from setuptools import setup
 
 setup(
     name='NiceGUI',

+ 1 - 1
website/search.py

@@ -56,7 +56,7 @@ class Search:
                 self.results.clear()
                 for result in results:
                     href: str = result['item']['url']
-                    with ui.element('q-item').props(f'clickable') \
+                    with ui.element('q-item').props('clickable') \
                             .on('click', lambda href=href: self.open_url(href), []):
                         with ui.element('q-item-section'):
                             ui.label(result['item']['title'])