Skip to content

Commit

Permalink
Fixed lots of Ruff issues (but not all yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertisele committed Sep 24, 2024
1 parent 1e9a6e7 commit da18c98
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 84 deletions.
12 changes: 6 additions & 6 deletions cmem_plugin_base/dataintegration/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from inspect import _empty
from mimetypes import guess_type
from pkgutil import get_data
from typing import Any
from typing import Any, ClassVar

from cmem_plugin_base.dataintegration.plugins import TransformPlugin, WorkflowPlugin
from cmem_plugin_base.dataintegration.types import (
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__( # noqa: PLR0913
label: str = "",
description: str = "",
param_type: ParameterType | None = None,
default_value: Any | None = None,
default_value: Any | None = None, # noqa: ANN401
advanced: bool = False,
visible: bool = True,
) -> None:
Expand All @@ -110,7 +110,7 @@ class PluginDescription:

def __init__( # noqa: PLR0913
self,
plugin_class,
plugin_class: type,
label: str,
plugin_id: str | None = None,
description: str = "",
Expand All @@ -126,7 +126,7 @@ def __init__( # noqa: PLR0913
elif issubclass(plugin_class, TransformPlugin):
self.plugin_type = "TransformPlugin"
else:
raise ValueError(
raise TypeError(
f"Class {plugin_class.__name__} does not implement a supported "
f"plugin base class (e.g., WorkflowPlugin)."
)
Expand Down Expand Up @@ -231,7 +231,7 @@ class Plugin:
:param icon: Optional custom plugin icon.
"""

plugins: list[PluginDescription] = []
plugins: ClassVar[list[PluginDescription]] = []

def __init__( # noqa: PLR0913
self,
Expand All @@ -257,7 +257,7 @@ def __init__( # noqa: PLR0913
else:
self.parameters = parameters

def __call__(self, func):
def __call__(self, func: type):
"""Allow to call the instance"""
plugin_desc = PluginDescription(
plugin_class=func,
Expand Down
4 changes: 2 additions & 2 deletions cmem_plugin_base/dataintegration/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
)


def get_packages():
def get_packages() -> object:
"""Get installed python packages.
Returns a list of dict with the following keys:
- name - package name
- version - package version
"""
return json.loads(
check_output(["pip", "list", "--format", "json"], shell=False) # nosec
check_output(["pip", "list", "--format", "json"], shell=False) # noqa: S603, S607
)


Expand Down
13 changes: 8 additions & 5 deletions cmem_plugin_base/dataintegration/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __repr__(self) -> str:
}
return f"EntityPath({obj})"

def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
"""Compare"""
return (
isinstance(other, EntityPath)
Expand All @@ -43,28 +43,31 @@ class EntitySchema:
:param type_uri: The entity type
:param paths: Ordered list of paths
:param path_to_root: Specifies a path which defines where this schema is located
in the schema tree
in the schema tree. Empty by default.
:param sub_schemata: Nested entity schemata
"""

def __init__(
self,
type_uri: str,
paths: Sequence[EntityPath],
path_to_root: EntityPath = EntityPath(""),
path_to_root: EntityPath | None = None,
sub_schemata: Sequence["EntitySchema"] | None = None,
) -> None:
self.type_uri = type_uri
self.paths = paths
self.path_to_root = path_to_root
if path_to_root is None:
self.path_to_root = EntityPath("")
else:
self.path_to_root = path_to_root
self.sub_schemata = sub_schemata

def __repr__(self) -> str:
"""Get a string representation"""
obj = {"type_uri": self.type_uri, "paths": self.paths, "path_to_root": self.path_to_root}
return f"EntitySchema({obj})"

def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
"""Compare"""
return (
isinstance(other, EntitySchema)
Expand Down
8 changes: 4 additions & 4 deletions cmem_plugin_base/dataintegration/parameter/choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def __init__(self, choice_list: collections.OrderedDict[str, str]):
self.choice_list = choice_list

def label(
self, value: str, depend_on_parameter_values: list[Any], context: PluginContext # noqa: ARG002
self, value: str, depend_on_parameter_values: list[Any], context: PluginContext
) -> str | None:
"""Return the label for the given choice value."""
return self.choice_list[value]

def autocomplete(
self, query_terms: list[str], depend_on_parameter_values: list[Any], context: PluginContext, # noqa: ARG002
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 @@ -37,6 +37,6 @@ def autocomplete(
result.append(Autocompletion(value=identifier, label=label))
for term in query_terms:
if term.lower() in label.lower():
result.append(Autocompletion(value=identifier, label=label))
result.sort(key=lambda x: x.label) # type: ignore
result.append(Autocompletion(value=identifier, label=label)) # noqa: PERF401
result.sort(key=lambda x: x.label)
return list(set(result))
7 changes: 4 additions & 3 deletions cmem_plugin_base/dataintegration/parameter/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, dataset_type: str | None = None):
def label(
self, value: str, depend_on_parameter_values: list[Any], context: PluginContext
) -> str | None:
"""Returns the label for the given dataset."""
"""Return the label for the given dataset."""
setup_cmempy_user_access(context.user)
task_label = str(get_task(project=context.project_id, task=value)["metadata"]["label"])
return f"{task_label}"
Expand All @@ -37,6 +37,7 @@ def autocomplete(
depend_on_parameter_values: list[Any],
context: PluginContext,
) -> list[Autocompletion]:
"""Autocompletion request - Returns all results that match all provided query terms."""
setup_cmempy_user_access(context.user)
datasets = list_items(item_type="dataset", project=context.project_id)["results"]

Expand All @@ -50,9 +51,9 @@ def autocomplete(
continue
for term in query_terms:
if term.lower() in label.lower():
result.append(Autocompletion(value=identifier, label=label))
result.append(Autocompletion(value=identifier, label=label)) # noqa: PERF401
if len(query_terms) == 0:
# add any dataset to list if no search terms are given
result.append(Autocompletion(value=identifier, label=label))
result.sort(key=lambda x: x.label) # type: ignore
result.sort(key=lambda x: x.label)
return list(set(result))
2 changes: 1 addition & 1 deletion cmem_plugin_base/dataintegration/parameter/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ def autocomplete(
if term.lower() in label.lower():
result.append(Autocompletion(value=iri, label=label))
continue
result.sort(key=lambda x: x.label) # type: ignore
result.sort(key=lambda x: x.label)
return list(set(result))
8 changes: 5 additions & 3 deletions cmem_plugin_base/dataintegration/parameter/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, encrypted_value: str, system: SystemContext):
self.system = system

def decrypt(self) -> str:
"""Returns the decrypted value"""
"""Return the decrypted value"""
return self.system.decrypt(self.encrypted_value)


Expand All @@ -26,7 +26,8 @@ class PasswordParameterType(ParameterType[Password]):
"""Prefix to identify already encrypted values."""

def from_string(self, value: str, context: PluginContext) -> Password:
"""Parses strings into parameter values.
"""Parse strings into parameter values.
Decrypts the password if the encryption preamble is present
"""
if value is None or value == "":
Expand All @@ -38,7 +39,8 @@ def from_string(self, value: str, context: PluginContext) -> Password:
return Password(encrypted_value, context.system)

def to_string(self, value: Password) -> str:
"""Converts parameter values into their string representation.
"""Convert parameter values into their string representation.
Encrypts the password so that it won't be stored verbatim.
"""
if value.encrypted_value == "":
Expand Down
1 change: 1 addition & 0 deletions cmem_plugin_base/dataintegration/parameter/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def autocomplete(
depend_on_parameter_values: list[Any],
context: PluginContext,
) -> list[Autocompletion]:
"""Autocompletion request - Returns all results that match ALL provided query terms."""
setup_cmempy_user_access(context.user)
resources = get_resources(context.project_id)
result = [
Expand Down
Loading

0 comments on commit da18c98

Please sign in to comment.