Skip to content

Commit

Permalink
chore: mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
makkus committed Mar 26, 2024
1 parent db969c1 commit eb49c3a
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/kiara/context/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/kiara/interfaces/cli/type/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/kiara/interfaces/python_api/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/kiara/interfaces/python_api/models/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/kiara/interfaces/python_api/models/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/kiara/registries/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/kiara/renderers/included_renderers/api/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Any,
Iterable,
Mapping,
Union,
Union, Dict, Set,
)

from pydantic.fields import Field
Expand Down Expand Up @@ -164,15 +164,15 @@ 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
)


class BaseToKiaraApiRenderer(BaseApiRenderer):

_renderer_name = "base_api_kiara_api_renderer"
_inputs_schema = BaseApiRenderKiaraApiInputsSchema
_inputs_schema = BaseApiRenderKiaraApiInputsSchema # type: ignore
_renderer_config_cls = BaseApiRendererConfig

def __init__(
Expand All @@ -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():
Expand Down Expand Up @@ -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")

Expand Down
12 changes: 6 additions & 6 deletions src/kiara/renderers/included_renderers/api/kiara_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")


Expand All @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions src/kiara/utils/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions src/kiara/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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":
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/kiara/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eb49c3a

Please sign in to comment.