From 4f029dc29eda50b1580e51a14a331451b30d80d2 Mon Sep 17 00:00:00 2001 From: Markus Binsteiner Date: Tue, 26 Mar 2024 19:50:09 +0100 Subject: [PATCH] chore: fix linting issues & general cleanup --- pyproject.toml | 3 ++- src/kiara/context/__init__.py | 1 - src/kiara/defaults.py | 1 + src/kiara/interfaces/cli/type/commands.py | 2 +- src/kiara/interfaces/python_api/base_api.py | 3 +-- src/kiara/interfaces/python_api/kiara_api.py | 1 - .../interfaces/python_api/models/archive.py | 1 - src/kiara/interfaces/python_api/proxy.py | 10 ++++---- .../models/values/value_metadata/__init__.py | 2 -- .../included_renderers/api/base_api.py | 7 ++++-- src/kiara/utils/archives.py | 7 ++++-- src/kiara/utils/db.py | 3 +-- src/kiara/utils/introspection.py | 2 +- src/kiara/utils/metadata.py | 23 ++++++++++++------- 14 files changed, 36 insertions(+), 30 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a6d883311..5d6478173 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -400,7 +400,8 @@ exclude = [ "dist", "node_modules", "venv", - "examples/" + "examples/", + "dev/" ] # Assume Python 3.10. diff --git a/src/kiara/context/__init__.py b/src/kiara/context/__init__.py index 647fd058c..0b8b846e1 100644 --- a/src/kiara/context/__init__.py +++ b/src/kiara/context/__init__.py @@ -15,7 +15,6 @@ from kiara.data_types import DataType from kiara.exceptions import KiaraContextException from kiara.interfaces import get_console -from kiara.interfaces.python_api.base_api import BaseAPI from kiara.interfaces.python_api.models.info import ( DataTypeClassesInfo, InfoItemGroup, diff --git a/src/kiara/defaults.py b/src/kiara/defaults.py index 89f557299..59ca1d10e 100644 --- a/src/kiara/defaults.py +++ b/src/kiara/defaults.py @@ -144,6 +144,7 @@ CHUNK_CACHE_DIR_DEPTH = 2 CHUNK_CACHE_DIR_WIDTH = 1 + class SpecialValue(Enum): NOT_SET = "__not_set__" diff --git a/src/kiara/interfaces/cli/type/commands.py b/src/kiara/interfaces/cli/type/commands.py index cab4f6bb6..a41e09e57 100644 --- a/src/kiara/interfaces/cli/type/commands.py +++ b/src/kiara/interfaces/cli/type/commands.py @@ -112,7 +112,7 @@ def explain_data_type(ctx, type_name: str, format: str): """Print details of a data type.""" 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 fd85ecbe2..f85291fa2 100644 --- a/src/kiara/interfaces/python_api/base_api.py +++ b/src/kiara/interfaces/python_api/base_api.py @@ -2199,8 +2199,7 @@ def export_values( ) if export_related_metadata: - print("TODO: Export related metadata.") - # raise NotImplementedError("xx") + raise NotImplementedError("Exporting related metadata not implemented yet.") if additional_archive_metadata: for k, v in additional_archive_metadata.items(): diff --git a/src/kiara/interfaces/python_api/kiara_api.py b/src/kiara/interfaces/python_api/kiara_api.py index f56f19967..20ffa9354 100644 --- a/src/kiara/interfaces/python_api/kiara_api.py +++ b/src/kiara/interfaces/python_api/kiara_api.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import uuid -from collections.abc import Iterable, Mapping from pathlib import Path # BEGIN AUTO-GENERATED-IMPORTS diff --git a/src/kiara/interfaces/python_api/models/archive.py b/src/kiara/interfaces/python_api/models/archive.py index cba5a37f0..5ca5a4682 100644 --- a/src/kiara/interfaces/python_api/models/archive.py +++ b/src/kiara/interfaces/python_api/models/archive.py @@ -7,7 +7,6 @@ from kiara.defaults import CHUNK_COMPRESSION_TYPE from kiara.models import KiaraModel -from kiara.registries.jobs import JobArchive if TYPE_CHECKING: from kiara.context import Kiara diff --git a/src/kiara/interfaces/python_api/proxy.py b/src/kiara/interfaces/python_api/proxy.py index 9ad62fb78..7ba4b2dd8 100644 --- a/src/kiara/interfaces/python_api/proxy.py +++ b/src/kiara/interfaces/python_api/proxy.py @@ -272,12 +272,10 @@ def api_endpint_names(self) -> List[str]: temp = [] - avail_methods = [ - member - for member in inspect.getmembers( - self._api_cls, predicate=inspect.isfunction - ) - ] + avail_methods = list( + inspect.getmembers(self._api_cls, predicate=inspect.isfunction) + ) + avail_methods.sort(key=lambda x: inspect.getsourcelines(x[1])[1]) method_names = [x[0] for x in avail_methods] diff --git a/src/kiara/models/values/value_metadata/__init__.py b/src/kiara/models/values/value_metadata/__init__.py index 0371b6b7b..493d5319c 100644 --- a/src/kiara/models/values/value_metadata/__init__.py +++ b/src/kiara/models/values/value_metadata/__init__.py @@ -44,5 +44,3 @@ def _retrieve_id(self) -> str: def _retrieve_data_to_hash(self) -> Any: return {"metadata": self.model_dump(), "schema": self.schema_json()} - - diff --git a/src/kiara/renderers/included_renderers/api/base_api.py b/src/kiara/renderers/included_renderers/api/base_api.py index 4a8004061..bf1169232 100644 --- a/src/kiara/renderers/included_renderers/api/base_api.py +++ b/src/kiara/renderers/included_renderers/api/base_api.py @@ -5,9 +5,11 @@ from typing import ( TYPE_CHECKING, Any, + Dict, Iterable, Mapping, - Union, Dict, Set, + Set, + Union, ) from pydantic.fields import Field @@ -323,6 +325,7 @@ def _render( target_file = Path(render_config.target_file) target_file.parent.mkdir(parents=True, exist_ok=True) target_file.write_text(new_content) - print(f"Rendered api to file '{target_file}'.") + terminal_print() + terminal_print(f"Rendered api to file '{target_file}'.") else: return new_content diff --git a/src/kiara/utils/archives.py b/src/kiara/utils/archives.py index da8d04db7..9c4b0ee7b 100644 --- a/src/kiara/utils/archives.py +++ b/src/kiara/utils/archives.py @@ -1,17 +1,20 @@ +# -*- coding: utf-8 -*- from functools import lru_cache -from typing import Union, Dict, TYPE_CHECKING +from typing import TYPE_CHECKING, Dict, Union if TYPE_CHECKING: + from kiara.context import Kiara from kiara.interfaces.python_api.models.info import TypeInfo from kiara.models.archives import ArchiveTypeClassesInfo + @lru_cache(maxsize=None) def find_archive_types( alias: Union[str, None] = None, only_for_package: Union[str, None] = None ) -> "ArchiveTypeClassesInfo": - from kiara.utils.class_loading import find_all_archive_types from kiara.models.archives import ArchiveTypeClassesInfo + from kiara.utils.class_loading import find_all_archive_types archive_types = find_all_archive_types() diff --git a/src/kiara/utils/db.py b/src/kiara/utils/db.py index 24286c034..8df68a0f1 100644 --- a/src/kiara/utils/db.py +++ b/src/kiara/utils/db.py @@ -7,7 +7,7 @@ import os from pathlib import Path -from typing import Any, TYPE_CHECKING, Dict +from typing import TYPE_CHECKING, Any, Dict import orjson @@ -42,7 +42,6 @@ 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": diff --git a/src/kiara/utils/introspection.py b/src/kiara/utils/introspection.py index 9dd1fe23e..c899685fb 100644 --- a/src/kiara/utils/introspection.py +++ b/src/kiara/utils/introspection.py @@ -143,7 +143,7 @@ def create_signature_string( def extract_arg_names(func: Callable) -> typing.List[str]: sig = inspect.signature(func) - return [name for name in sig.parameters.keys()] + return list(sig.parameters.keys()) def extract_proxy_arg_str(func: Callable) -> str: diff --git a/src/kiara/utils/metadata.py b/src/kiara/utils/metadata.py index 6645b60f4..016f522ea 100644 --- a/src/kiara/utils/metadata.py +++ b/src/kiara/utils/metadata.py @@ -1,18 +1,20 @@ # -*- coding: utf-8 -*- from functools import lru_cache + # Copyright (c) 2021, University of Luxembourg / DHARPA project # Copyright (c) 2021, Markus Binsteiner # # Mozilla Public License, version 2.0 (see LICENSE or https://www.mozilla.org/en-US/MPL/2.0/) - -from typing import Dict, Type, Union, Mapping, TYPE_CHECKING +from typing import TYPE_CHECKING, Dict, Type, Union from kiara.models.values.value_metadata import ValueMetadata from kiara.registries.models import ModelRegistry if TYPE_CHECKING: from kiara.context import Kiara - from kiara.interfaces.python_api.models.info import MetadataTypeClassesInfo, MetadataTypeInfo + from kiara.interfaces.python_api.models.info import ( + MetadataTypeClassesInfo, + ) @lru_cache() @@ -45,7 +47,9 @@ def find_metadata_models( return group -def get_metadata_model_for_data_type(kiara: "Kiara", data_type: str) -> "MetadataTypeClassesInfo": +def get_metadata_model_for_data_type( + kiara: "Kiara", data_type: str +) -> "MetadataTypeClassesInfo": """ Return all available metadata extract operations for the provided type (and it's parent types). @@ -60,9 +64,8 @@ def get_metadata_model_for_data_type(kiara: "Kiara", data_type: str) -> "Metadat from kiara.interfaces.python_api.models.info import MetadataTypeClassesInfo - lineage = set( - kiara.type_registry.get_type_lineage(data_type_name=data_type) - ) + # TODO: add models for parent types? + # lineage = set(kiara.type_registry.get_type_lineage(data_type_name=data_type)) model_registry = ModelRegistry.instance() all_metadata_models = model_registry.get_models_of_type(ValueMetadata) @@ -76,6 +79,10 @@ 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 = 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