diff --git a/src/kiara/context/__init__.py b/src/kiara/context/__init__.py index 5983da2f9..647fd058c 100644 --- a/src/kiara/context/__init__.py +++ b/src/kiara/context/__init__.py @@ -106,7 +106,8 @@ class Kiara(object): def instance(cls) -> "Kiara": """The default *kiara* context. In most cases, it's recommended you create and manage your own, though.""" - return BaseAPI.instance().context + raise NotImplementedError("Kiara.instance() is not implemented yet.") + # return BaseAPI.instance().context def __init__( self, diff --git a/src/kiara/interfaces/cli/type/commands.py b/src/kiara/interfaces/cli/type/commands.py index 1597c774a..cab4f6bb6 100644 --- a/src/kiara/interfaces/cli/type/commands.py +++ b/src/kiara/interfaces/cli/type/commands.py @@ -110,8 +110,9 @@ def hierarchy(ctx, include_internal) -> None: @click.pass_context def explain_data_type(ctx, type_name: str, format: str): """Print details of a data type.""" - from kiara.interfaces.python_api import DataTypeClassInfo + from kiara.interfaces.python_api.models.info import DataTypeClassInfo + kiara_obj: Kiara = ctx.obj.kiara data_type = kiara_obj.type_registry.retrieve_data_type( diff --git a/src/kiara/interfaces/python_api/base_api.py b/src/kiara/interfaces/python_api/base_api.py index 46d6991d7..fd85ecbe2 100644 --- a/src/kiara/interfaces/python_api/base_api.py +++ b/src/kiara/interfaces/python_api/base_api.py @@ -2117,7 +2117,7 @@ def import_values( for a in alias_map[alias]: new_alias_map.setdefault(field, []).append(a) - result = self.store_values( + result: StoreValuesResult = self.store_values( values=new_values, alias_map=new_alias_map, allow_alias_overwrite=allow_alias_overwrite, @@ -2191,7 +2191,7 @@ def export_values( **target_store_params, ) - result = self.store_values( + result: StoreValuesResult = self.store_values( values=values, alias_map=alias_map, allow_alias_overwrite=allow_alias_overwrite, @@ -2555,7 +2555,7 @@ def copy_archive( else: alias_map = False - result = self.store_values( + result: StoreValuesResult = self.store_values( source_values, alias_map=alias_map, store=target_archive_ref ) return result diff --git a/src/kiara/interfaces/python_api/models/archive.py b/src/kiara/interfaces/python_api/models/archive.py index 9a6e30971..cba5a37f0 100644 --- a/src/kiara/interfaces/python_api/models/archive.py +++ b/src/kiara/interfaces/python_api/models/archive.py @@ -71,17 +71,17 @@ def load_kiarchive( jobs_archive_config = None jobs_archive = None - archives = [ + _archives = [ x for x in (data_archive, alias_archive, metadata_archive, jobs_archive) if x is not None ] - if not archives: + if not _archives: raise Exception(f"No archive found in file: {path}") else: - archive_id = archives[0].archive_id - archive_alias = archives[0].archive_name - for archive in archives: + archive_id = _archives[0].archive_id + archive_alias = _archives[0].archive_name + for archive in _archives: if archive.archive_id != archive_id: raise Exception( f"Multiple different archive ids found in file: {path}" @@ -175,7 +175,7 @@ def create_kiarchive( ) alias_store_config = alias_store.config - job_store: JobStore = create_new_archive( + job_store: JobStore = create_new_archive( # type: ignore archive_name=archive_name, store_base_path=archive_base_path, store_type="sqlite_job_store", diff --git a/src/kiara/interfaces/python_api/models/info.py b/src/kiara/interfaces/python_api/models/info.py index f4dbc5a71..0a6b5c594 100644 --- a/src/kiara/interfaces/python_api/models/info.py +++ b/src/kiara/interfaces/python_api/models/info.py @@ -73,6 +73,12 @@ from kiara.utils.json import orjson_dumps from kiara.utils.output import extract_renderable +try: + from typing import Self # type: ignore +except ImportError: + from typing_extensions import Self # type: ignore + + if TYPE_CHECKING: from kiara.context import Kiara from kiara.data_types import DataType @@ -327,7 +333,7 @@ def base_info_class(cls) -> Type[TypeInfo]: @classmethod def create_from_type_items( cls, kiara: "Kiara", group_title: Union[str, None] = None, **items: Type - ) -> "TypeInfoItemGroup": + ) -> Self: type_infos: Mapping[str, TypeInfo[Any]] = { k: cls.base_info_class().create_from_type_class(type_cls=v, kiara=kiara) diff --git a/src/kiara/registries/jobs/__init__.py b/src/kiara/registries/jobs/__init__.py index 8e34f5b13..9ee5ae4e5 100644 --- a/src/kiara/registries/jobs/__init__.py +++ b/src/kiara/registries/jobs/__init__.py @@ -254,13 +254,15 @@ def default_job_store(self) -> str: raise Exception("No default job store set (yet).") return self._default_job_store # type: ignore - def get_archive(self, store_id: Union[str, None] = None) -> JobArchive: + def get_archive(self, store_id: Union[str, None, uuid.UUID] = None) -> JobArchive: if store_id is None: store_id = self.default_job_store if store_id is None: raise Exception("Can't retrieve deafult job archive, none set (yet).") + if isinstance(store_id, uuid.UUID): + raise NotImplementedError("Can't retrieve job archive by (uu)id (yet).") return self._job_archives[store_id] @property diff --git a/src/kiara/renderers/included_renderers/api/base_api.py b/src/kiara/renderers/included_renderers/api/base_api.py index d7978167e..4a8004061 100644 --- a/src/kiara/renderers/included_renderers/api/base_api.py +++ b/src/kiara/renderers/included_renderers/api/base_api.py @@ -7,7 +7,7 @@ Any, Iterable, Mapping, - Union, + Union, Dict, Set, ) from pydantic.fields import Field @@ -164,7 +164,7 @@ class BaseApiRenderKiaraApiInputsSchema(BaseApiRenderInputsSchema): template_file: str = Field( description="The file that should contain the rendered code." ) - target_file: Union[str] = Field( + target_file: Union[str, None] = Field( description="The file to write the rendered code to.", default=None ) @@ -172,7 +172,7 @@ class BaseApiRenderKiaraApiInputsSchema(BaseApiRenderInputsSchema): class BaseToKiaraApiRenderer(BaseApiRenderer): _renderer_name = "base_api_kiara_api_renderer" - _inputs_schema = BaseApiRenderKiaraApiInputsSchema + _inputs_schema = BaseApiRenderKiaraApiInputsSchema # type: ignore _renderer_config_cls = BaseApiRendererConfig def __init__( @@ -194,6 +194,8 @@ def _render( self, instance: BaseAPI, render_config: BaseApiRenderInputsSchema ) -> Any: + assert isinstance(render_config, BaseApiRenderKiaraApiInputsSchema) + template_file = Path(render_config.template_file) if not template_file.is_file(): @@ -230,7 +232,7 @@ def _render( # endpoints = find_base_api_endpoints(BaseAPI, label=tag) endpoint_data = [] - imports = {} + imports: Dict[str, Set[str]] = {} imports.setdefault("typing", set()).add("Dict") imports.setdefault("typing", set()).add("ClassVar") diff --git a/src/kiara/renderers/included_renderers/api/kiara_api.py b/src/kiara/renderers/included_renderers/api/kiara_api.py index 325b11ad1..7f7dcd6cb 100644 --- a/src/kiara/renderers/included_renderers/api/kiara_api.py +++ b/src/kiara/renderers/included_renderers/api/kiara_api.py @@ -29,15 +29,15 @@ class ApiRenderInputsSchema(RenderInputsSchema): - filter: Union[str, Iterable[str]] = Field( - description="One or a list of filter tokens -- if provided -- all of which must match for the api endpoing to be in the render result.", - default_factory=list, - ) + pass class ApiRendererConfig(KiaraRendererConfig): - pass + filter: Union[str, Iterable[str]] = Field( + description="One or a list of filter tokens -- if provided -- all of which must match for the api endpoing to be in the render result.", + default_factory=list, + ) # target_type: str = Field(description="The target type to render the api as.") @@ -55,7 +55,7 @@ def __init__( super().__init__(kiara=kiara, renderer_config=renderer_config) - filters = self.renderer_config.filter + filters: Union[None, str, Iterable[str]] = self.renderer_config.filter if not filters: filters = None elif isinstance(filters, str): diff --git a/src/kiara/utils/cli/run.py b/src/kiara/utils/cli/run.py index f4d6ebc5c..3b9ae4e1f 100644 --- a/src/kiara/utils/cli/run.py +++ b/src/kiara/utils/cli/run.py @@ -16,9 +16,10 @@ KiaraException, NoSuchExecutionTargetException, ) -from kiara.interfaces.python_api.base_api import BaseAPI, ValueMap +from kiara.interfaces.python_api.base_api import BaseAPI from kiara.interfaces.python_api.utils import create_save_config from kiara.models.module.operation import Operation +from kiara.models.values.value import ValueMap # from kiara.interfaces.python_api.operation import KiaraOperation from kiara.utils import log_exception @@ -57,7 +58,7 @@ def validate_operation_in_terminal( # operation_config=module_config, # ) try: - operation = api.get_operation(operation=module_or_operation) + operation: Operation = api.get_operation(operation=module_or_operation) # validate that operation config is valid, ignoring inputs for now # kiara_op.operation except NoSuchExecutionTargetException as nset: diff --git a/src/kiara/utils/db.py b/src/kiara/utils/db.py index fc1ad1859..24286c034 100644 --- a/src/kiara/utils/db.py +++ b/src/kiara/utils/db.py @@ -7,13 +7,16 @@ import os from pathlib import Path -from typing import Any +from typing import Any, TYPE_CHECKING, Dict import orjson from kiara import is_debug from kiara.utils import log_message +if TYPE_CHECKING: + from sqlalchemy.engine import Engine + def get_kiara_db_url(base_path: str): @@ -39,6 +42,7 @@ def orm_json_deserialize(obj: str) -> Any: return orjson.loads(obj) + def create_archive_engine( db_path: Path, force_read_only: bool, use_wal_mode: bool ) -> "Engine": @@ -51,8 +55,8 @@ def create_archive_engine( # execution_options = {"sqlite_wal_mode": True} # else: - connect_args = {} - execution_options = {} + connect_args: Dict[str, Any] = {} + execution_options: Dict[str, Any] = {} # TODO: enable this for read-only mode? # def _pragma_on_connect(dbapi_con, con_record): diff --git a/src/kiara/utils/metadata.py b/src/kiara/utils/metadata.py index 51c6be927..6645b60f4 100644 --- a/src/kiara/utils/metadata.py +++ b/src/kiara/utils/metadata.py @@ -76,6 +76,6 @@ def get_metadata_model_for_data_type(kiara: "Kiara", data_type: str) -> "Metadat if data_type in supported: matching_types[name] = metadata_cls - result = MetadataTypeClassesInfo.create_from_type_items(kiara=kiara, group_title=f"Metadata models for type '{data_type}'", **matching_types) + result: MetadataTypeClassesInfo = MetadataTypeClassesInfo.create_from_type_items(kiara=kiara, group_title=f"Metadata models for type '{data_type}'", **matching_types) return result