From dbb3e889e1b5cb3b9da957fb2314e9a0a21130ce Mon Sep 17 00:00:00 2001 From: Qubasa Date: Thu, 10 Jul 2025 14:20:57 +0700 Subject: [PATCH] clan-lib: Fix @API.register_abstract not throwing correct error when called directly without implementation clan-app: Fix mypy lint clan-lib: Mark test as with_core --- pkgs/clan-app/clan_app/app.py | 8 +++++--- pkgs/clan-app/clan_app/deps/webview/webview.py | 2 +- pkgs/clan-cli/clan_lib/api/__init__.py | 2 +- pkgs/clan-cli/clan_lib/clan/check_test.py | 2 ++ pkgs/clan-cli/clan_lib/clan/get.py | 4 ++++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-app/clan_app/app.py b/pkgs/clan-app/clan_app/app.py index 3e3667611..d9ec619a9 100644 --- a/pkgs/clan-app/clan_app/app.py +++ b/pkgs/clan-app/clan_app/app.py @@ -10,7 +10,7 @@ from clan_lib.dirs import user_data_dir from clan_lib.log_manager import LogGroupConfig, LogManager from clan_lib.log_manager import api as log_manager_api -from clan_app.api.file_gtk import open_file +from clan_app.api.file_gtk import open_clan_folder, open_file from clan_app.api.middleware import ( ArgumentParsingMiddleware, LoggingMiddleware, @@ -56,10 +56,9 @@ def app_run(app_opts: ClanAppOptions) -> int: # Populate the API global with all functions load_in_all_api_functions() - API.overwrite_fn(open_file) # Create a shared threads dictionary for both HTTP and Webview modes - shared_threads = {} + shared_threads: dict[str, tasks.WebThread] = {} tasks.BAKEND_THREADS = shared_threads # Start HTTP API server if requested @@ -114,6 +113,9 @@ def app_run(app_opts: ClanAppOptions) -> int: shared_threads=shared_threads, ) + API.overwrite_fn(open_file) + API.overwrite_fn(open_clan_folder) + # Add middleware to the webview webview.add_middleware(ArgumentParsingMiddleware(api=API)) webview.add_middleware(LoggingMiddleware(log_manager=log_manager)) diff --git a/pkgs/clan-app/clan_app/deps/webview/webview.py b/pkgs/clan-app/clan_app/deps/webview/webview.py index 093638e4e..b2dcc72ef 100644 --- a/pkgs/clan-app/clan_app/deps/webview/webview.py +++ b/pkgs/clan-app/clan_app/deps/webview/webview.py @@ -126,7 +126,7 @@ class Webview: ) else: bridge = WebviewBridge( - webview=self, middleware_chain=tuple(self._middleware) + webview=self, middleware_chain=tuple(self._middleware), threads={} ) self._bridge = bridge return bridge diff --git a/pkgs/clan-cli/clan_lib/api/__init__.py b/pkgs/clan-cli/clan_lib/api/__init__.py index 70fe330ea..681845640 100644 --- a/pkgs/clan-cli/clan_lib/api/__init__.py +++ b/pkgs/clan-cli/clan_lib/api/__init__.py @@ -97,7 +97,7 @@ class MethodRegistry: def register_abstract(self, fn: Callable[..., T]) -> Callable[..., T]: @wraps(fn) - def wrapper(*args: Any, op_key: str, **kwargs: Any) -> ApiResponse[T]: + def wrapper(*args: Any, **kwargs: Any) -> ApiResponse[T]: msg = f"""{fn.__name__} - The platform didn't implement this function. --- diff --git a/pkgs/clan-cli/clan_lib/clan/check_test.py b/pkgs/clan-cli/clan_lib/clan/check_test.py index 1e664352e..8f60e9a1f 100644 --- a/pkgs/clan-cli/clan_lib/clan/check_test.py +++ b/pkgs/clan-cli/clan_lib/clan/check_test.py @@ -1,11 +1,13 @@ from pathlib import Path +import pytest from clan_cli.tests.fixtures_flakes import FlakeForTest from clan_lib.clan.check import check_clan_valid from clan_lib.flake import Flake +@pytest.mark.with_core def test_check_clan_valid( temporary_home: Path, test_flake_with_core: FlakeForTest, test_flake: FlakeForTest ) -> None: diff --git a/pkgs/clan-cli/clan_lib/clan/get.py b/pkgs/clan-cli/clan_lib/clan/get.py index 3127c80bd..d1627b666 100644 --- a/pkgs/clan-cli/clan_lib/clan/get.py +++ b/pkgs/clan-cli/clan_lib/clan/get.py @@ -1,9 +1,13 @@ +import logging + from clan_lib.api import API from clan_lib.errors import ClanError from clan_lib.flake import Flake from clan_lib.nix_models.clan import InventoryMeta from clan_lib.persist.inventory_store import InventoryStore +log = logging.getLogger(__name__) + @API.register def get_clan_details(flake: Flake) -> InventoryMeta: