Skip to content

Commit

Permalink
fix ruff and mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
msaipraneeth committed Sep 25, 2024
1 parent 8b3ef34 commit 316cd23
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 27 deletions.
4 changes: 2 additions & 2 deletions cmem_plugin_base/dataintegration/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ def __call__(self, func: type):
def retrieve_parameters(self, plugin_class: type) -> list[PluginParameter]:
"""Retrieve parameters from a plugin class and matches them with the user parameter defs"""
# Only return parameters for user-defined init methods.
if not hasattr(plugin_class.__init__, "__code__"): # type: ignore[misc]
if not hasattr(plugin_class.__init__, "__code__"): # type: ignore[misc]
return []
# Collect parameters from init method
params = []
sig = inspect.signature(plugin_class.__init__) # type: ignore[misc]
sig = inspect.signature(plugin_class.__init__) # type: ignore[misc]
for name in sig.parameters:
if name != "self":
param = next((p for p in self.parameters if p.name == name), None)
Expand Down
7 changes: 5 additions & 2 deletions cmem_plugin_base/dataintegration/parameter/choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def label(
return self.choice_list[value]

def autocomplete(
self, query_terms: list[str], depend_on_parameter_values: list[Any], context: PluginContext,
self,
query_terms: list[str],
depend_on_parameter_values: list[Any],
context: PluginContext,
) -> list[Autocompletion]:
"""Autocompletion request - Returns all results that match ALL provided query terms."""
result = []
Expand All @@ -38,5 +41,5 @@ def autocomplete(
for term in query_terms:
if term.lower() in label.lower():
result.append(Autocompletion(value=identifier, label=label)) # noqa: PERF401
result.sort(key=lambda x: x.label) # type: ignore[return-value, arg-type]
result.sort(key=lambda x: x.label) # type: ignore[return-value, arg-type]
return list(set(result))
5 changes: 4 additions & 1 deletion cmem_plugin_base/dataintegration/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import re
from typing import IO

from cmem.cmempy.workspace.projects.datasets.dataset import post_resource

Expand Down Expand Up @@ -70,7 +71,9 @@ def split_task_id(task_id: str) -> tuple:
return project_part, task_part


def write_to_dataset(dataset_id: str, file_resource=None, context: UserContext | None = None):
def write_to_dataset( # noqa: ANN201
dataset_id: str, file_resource: IO | None = None, context: UserContext | None = None
):
"""Write to a dataset.
Args:
Expand Down
4 changes: 2 additions & 2 deletions cmem_plugin_base/dataintegration/utils/entity_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def _get_entity(
values.append(
[f"{data.get(_.path)}"]
if _.is_single_value
else [f"{_v}" for _v in data.get(_.path)]
else [f"{_v}" for _v in data.get(_.path)] # type: ignore[union-attr]
)
else:
_data = [data.get(_.path)] if _.is_single_value else data.get(_.path)
_data: list[dict] = [data.get(_.path)] if _.is_single_value else data.get(_.path) # type: ignore[assignment,list-item]
sub_entities_uri = []
for _v in _data:
sub_entity_path = f"{path_from_root}/{_.path}"
Expand Down
19 changes: 10 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ def _json_dataset() -> Generator[dict, None, None]:
delete_project(PROJECT_NAME)


@dataclass
class JSONResourceFixtureDate:
"""fixture dataclass"""

project_name: str
resource_name: str


@pytest.fixture(name="json_resource", scope="module")
def _json_resource() -> object:
def _json_resource() -> Generator[JSONResourceFixtureDate, None, None]:
"""Set up json resource"""
_project_name = "resource_test_project"
_resource_name = "sample_test.json"
Expand All @@ -46,13 +54,6 @@ def _json_resource() -> object:
replace=True,
)

@dataclass
class FixtureDate:
"""fixture dataclass"""

project_name = _project_name
resource_name = _resource_name

_ = FixtureDate()
_ = JSONResourceFixtureDate(project_name=_project_name, resource_name=_resource_name)
yield _
delete_project(_project_name)
16 changes: 8 additions & 8 deletions tests/parameter_types/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class MyTransformPlugin(TransformPlugin):

def __init__( # pylint: disable=too-many-arguments # noqa: PLR0913
self,
xml: XmlCode = XmlCode("<xml></xml>"), # noqa: B008
json: JsonCode = JsonCode("{}"), # noqa: B008
jinja: JinjaCode = JinjaCode(""), # noqa: B008
sql: SqlCode = SqlCode(""), # noqa: B008
yaml: YamlCode = YamlCode(""), # noqa: B008
sparql: SparqlCode = SparqlCode(""), # noqa: B008
turtle: TurtleCode = TurtleCode(""), # noqa: B008
python: PythonCode = PythonCode(""), # noqa: B008
xml: XmlCode = XmlCode("<xml></xml>"), # noqa: B008
json: JsonCode = JsonCode("{}"), # noqa: B008
jinja: JinjaCode = JinjaCode(""), # noqa: B008
sql: SqlCode = SqlCode(""), # noqa: B008
yaml: YamlCode = YamlCode(""), # noqa: B008
sparql: SparqlCode = SparqlCode(""), # noqa: B008
turtle: TurtleCode = TurtleCode(""), # noqa: B008
python: PythonCode = PythonCode(""), # noqa: B008
) -> None:
self.xml = xml
self.json = json
Expand Down
3 changes: 2 additions & 1 deletion tests/parameter_types/test_resource.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""resource parameter type tests"""

from cmem_plugin_base.dataintegration.parameter.resource import ResourceParameterType
from tests.conftest import JSONResourceFixtureDate
from tests.utils import TestPluginContext, get_autocomplete_values, needs_cmem


@needs_cmem
def test_resource_parameter_type_completion(json_resource) -> None:
def test_resource_parameter_type_completion(json_resource: JSONResourceFixtureDate) -> None:
"""Test resource parameter type completion"""
project_name = json_resource.project_name
resource_name = json_resource.resource_name
Expand Down
1 change: 1 addition & 0 deletions tests/test_output_only_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""test file."""

from collections.abc import Sequence

from cmem_plugin_base.dataintegration.context import ExecutionContext
Expand Down
5 changes: 3 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def __init__(
self.user = user


def get_autocomplete_values(parameter: ParameterType, query_terms: list[str],
context: PluginContext) -> list[str]:
def get_autocomplete_values(
parameter: ParameterType, query_terms: list[str], context: PluginContext
) -> list[str]:
"""Get autocomplete values"""
return [
x.value
Expand Down

0 comments on commit 316cd23

Please sign in to comment.