1
0
forked from clan/clan-core

api: fix typing issues

This commit is contained in:
Johannes Kirschbauer 2024-05-21 15:57:27 +02:00
parent 21104a0465
commit c1e7e25641
Signed by: hsjobeki
SSH Key Fingerprint: SHA256:vX3utDqig7Ph5L0JPv87ZTPb/w7cMzREKVZzzLFg9qU
8 changed files with 19 additions and 18 deletions

View File

@ -21,7 +21,6 @@
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =

View File

@ -1,9 +1,10 @@
from collections.abc import Callable
from typing import Any
class _MethodRegistry:
def __init__(self):
self._registry = {}
def __init__(self) -> None:
self._registry: dict[str, Callable] = {}
def register(self, fn: Callable) -> Callable:
self._registry[fn.__name__] = fn
@ -13,9 +14,10 @@ class _MethodRegistry:
# Import only when needed
import json
from typing import get_type_hints
from clan_cli.api.util import type_to_dict
api_schema = {
api_schema: dict[str, Any] = {
"$comment": "An object containing API methods. ",
"type": "object",
"additionalProperties": False,

View File

@ -1,7 +1,7 @@
import dataclasses
from types import NoneType, UnionType
from typing import Any, Callable, Union, get_type_hints
import pathlib
from types import NoneType, UnionType
from typing import Any, Union
def type_to_dict(t: Any, scope: str = "") -> dict:
@ -46,7 +46,7 @@ def type_to_dict(t: Any, scope: str = "") -> dict:
"type": "object",
}
raise BaseException(f"Error api type not yet supported {str(t)}")
raise BaseException(f"Error api type not yet supported {t!s}")
elif isinstance(t, type):
if t is str:
@ -74,6 +74,6 @@ def type_to_dict(t: Any, scope: str = "") -> dict:
if t is NoneType:
return {"type": "null"}
raise BaseException(f"Error primitive type not supported {str(t)}")
raise BaseException(f"Error primitive type not supported {t!s}")
else:
raise BaseException(f"Error type not supported {str(t)}")
raise BaseException(f"Error type not supported {t!s}")

View File

@ -3,9 +3,10 @@ import json
import logging
from pathlib import Path
from clan_cli.api import API
from ..cmd import run
from ..nix import nix_config, nix_eval
from clan_cli.api import API
log = logging.getLogger(__name__)

View File

@ -2,16 +2,16 @@ import json
import logging
import sys
import threading
from threading import Lock
from collections.abc import Callable
from pathlib import Path
from typing import Any, Union
from threading import Lock
from typing import Any
import gi
gi.require_version("WebKit", "6.0")
from gi.repository import GLib, GObject, WebKit
from gi.repository import GLib, WebKit
site_index: Path = (
Path(sys.argv[0]).absolute()

View File

@ -2,7 +2,7 @@ import logging
import threading
import gi
from clan_cli.api import API
from clan_cli.history.list import list_history
from clan_vm_manager.components.interfaces import ClanConfig
@ -14,11 +14,10 @@ from clan_vm_manager.views.list import ClanList
from clan_vm_manager.views.logs import Logs
from clan_vm_manager.views.webview import WebView
from clan_cli.api import API
gi.require_version("Adw", "1")
from gi.repository import Adw, Gio, GLib, Gtk
from clan_vm_manager.components.trayicon import TrayIcon
log = logging.getLogger(__name__)

View File

@ -145,7 +145,7 @@ python3.pkgs.buildPythonApplication rec {
# TODO: place webui in lib/python3.11/site-packages/clan_vm_manager
postInstall = ''
mkdir -p $out/clan_vm_manager/.webui
cp -r ${webview-ui}/dist/* $out/clan_vm_manager/.webui
cp -r ${webview-ui}/lib/node_modules/@clan/webview-ui/dist/* $out/clan_vm_manager/.webui
'';
# Don't leak python packages into a devshell.

View File

@ -56,7 +56,7 @@ mkShell {
# Add the webview-ui to the .webui directory
rm -rf ./clan_vm_manager/.webui/*
mkdir -p ./clan_vm_manager/.webui
cp -a ${webview-ui}/dist/* ./clan_vm_manager/.webui
cp -a ${webview-ui}/lib/node_modules/@clan/webview-ui/dist/* ./clan_vm_manager/.webui
chmod -R +w ./clan_vm_manager/.webui
'';
}