forked from clan/clan-core
api: fix typing issues
This commit is contained in:
parent
21104a0465
commit
c1e7e25641
@ -21,7 +21,6 @@
|
|||||||
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
|
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
|
||||||
treefmt-nix.url = "github:numtide/treefmt-nix";
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
||||||
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class _MethodRegistry:
|
class _MethodRegistry:
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
self._registry = {}
|
self._registry: dict[str, Callable] = {}
|
||||||
|
|
||||||
def register(self, fn: Callable) -> Callable:
|
def register(self, fn: Callable) -> Callable:
|
||||||
self._registry[fn.__name__] = fn
|
self._registry[fn.__name__] = fn
|
||||||
@ -13,9 +14,10 @@ class _MethodRegistry:
|
|||||||
# Import only when needed
|
# Import only when needed
|
||||||
import json
|
import json
|
||||||
from typing import get_type_hints
|
from typing import get_type_hints
|
||||||
|
|
||||||
from clan_cli.api.util import type_to_dict
|
from clan_cli.api.util import type_to_dict
|
||||||
|
|
||||||
api_schema = {
|
api_schema: dict[str, Any] = {
|
||||||
"$comment": "An object containing API methods. ",
|
"$comment": "An object containing API methods. ",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
from types import NoneType, UnionType
|
|
||||||
from typing import Any, Callable, Union, get_type_hints
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
from types import NoneType, UnionType
|
||||||
|
from typing import Any, Union
|
||||||
|
|
||||||
|
|
||||||
def type_to_dict(t: Any, scope: str = "") -> dict:
|
def type_to_dict(t: Any, scope: str = "") -> dict:
|
||||||
@ -46,7 +46,7 @@ def type_to_dict(t: Any, scope: str = "") -> dict:
|
|||||||
"type": "object",
|
"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):
|
elif isinstance(t, type):
|
||||||
if t is str:
|
if t is str:
|
||||||
@ -74,6 +74,6 @@ def type_to_dict(t: Any, scope: str = "") -> dict:
|
|||||||
if t is NoneType:
|
if t is NoneType:
|
||||||
return {"type": "null"}
|
return {"type": "null"}
|
||||||
|
|
||||||
raise BaseException(f"Error primitive type not supported {str(t)}")
|
raise BaseException(f"Error primitive type not supported {t!s}")
|
||||||
else:
|
else:
|
||||||
raise BaseException(f"Error type not supported {str(t)}")
|
raise BaseException(f"Error type not supported {t!s}")
|
||||||
|
@ -3,9 +3,10 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from clan_cli.api import API
|
||||||
|
|
||||||
from ..cmd import run
|
from ..cmd import run
|
||||||
from ..nix import nix_config, nix_eval
|
from ..nix import nix_config, nix_eval
|
||||||
from clan_cli.api import API
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -2,16 +2,16 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from threading import Lock
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Union
|
from threading import Lock
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("WebKit", "6.0")
|
gi.require_version("WebKit", "6.0")
|
||||||
|
|
||||||
from gi.repository import GLib, GObject, WebKit
|
from gi.repository import GLib, WebKit
|
||||||
|
|
||||||
site_index: Path = (
|
site_index: Path = (
|
||||||
Path(sys.argv[0]).absolute()
|
Path(sys.argv[0]).absolute()
|
||||||
|
@ -2,7 +2,7 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
from clan_cli.api import API
|
||||||
from clan_cli.history.list import list_history
|
from clan_cli.history.list import list_history
|
||||||
|
|
||||||
from clan_vm_manager.components.interfaces import ClanConfig
|
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.logs import Logs
|
||||||
from clan_vm_manager.views.webview import WebView
|
from clan_vm_manager.views.webview import WebView
|
||||||
|
|
||||||
from clan_cli.api import API
|
|
||||||
|
|
||||||
gi.require_version("Adw", "1")
|
gi.require_version("Adw", "1")
|
||||||
|
|
||||||
from gi.repository import Adw, Gio, GLib, Gtk
|
from gi.repository import Adw, Gio, GLib, Gtk
|
||||||
|
|
||||||
from clan_vm_manager.components.trayicon import TrayIcon
|
from clan_vm_manager.components.trayicon import TrayIcon
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -145,7 +145,7 @@ python3.pkgs.buildPythonApplication rec {
|
|||||||
# TODO: place webui in lib/python3.11/site-packages/clan_vm_manager
|
# TODO: place webui in lib/python3.11/site-packages/clan_vm_manager
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
mkdir -p $out/clan_vm_manager/.webui
|
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.
|
# Don't leak python packages into a devshell.
|
||||||
|
@ -56,7 +56,7 @@ mkShell {
|
|||||||
# Add the webview-ui to the .webui directory
|
# Add the webview-ui to the .webui directory
|
||||||
rm -rf ./clan_vm_manager/.webui/*
|
rm -rf ./clan_vm_manager/.webui/*
|
||||||
mkdir -p ./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
|
chmod -R +w ./clan_vm_manager/.webui
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user