From a82e08f79140e493799f2b5d11c826efbbce8ac7 Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Tue, 26 Sep 2023 10:09:51 +0200 Subject: [PATCH] Fixed fstrings in exceptions --- packages/python/proto2python.sh | 1 + packages/python/pyproject.toml | 2 +- packages/python/src/armonik/client/tasks.py | 8 ++++-- packages/python/src/armonik/common/filter.py | 28 ++++++++++++-------- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/packages/python/proto2python.sh b/packages/python/proto2python.sh index f483b0541..c2fe45244 100644 --- a/packages/python/proto2python.sh +++ b/packages/python/proto2python.sh @@ -32,6 +32,7 @@ mkdir -p $ARMONIK_WORKER $ARMONIK_CLIENT $ARMONIK_COMMON $PACKAGE_PATH python -m pip install --upgrade pip python -m venv $PYTHON_VENV source $PYTHON_VENV/bin/activate +# We need to fix grpc to 1.56 until this bug is solved : https://github.com/grpc/grpc/issues/34305 python -m pip install build grpcio==1.56.2 grpcio-tools==1.56.2 click pytest setuptools_scm[toml] unset proto_files diff --git a/packages/python/pyproject.toml b/packages/python/pyproject.toml index af91ab0d2..0b66674bc 100644 --- a/packages/python/pyproject.toml +++ b/packages/python/pyproject.toml @@ -18,7 +18,7 @@ dependencies = [ "grpcio==1.56.2", "grpcio-tools==1.56.2" ] - +# We need to set grpc to 1.56 until this bug is resolved : https://github.com/grpc/grpc/issues/34305 [project.urls] "Homepage" = "https://github.com/aneoconsulting/ArmoniK.Api" "Bug Tracker" = "https://github.com/aneoconsulting/ArmoniK/issues" diff --git a/packages/python/src/armonik/client/tasks.py b/packages/python/src/armonik/client/tasks.py index 2a543a458..d6fb6876a 100644 --- a/packages/python/src/armonik/client/tasks.py +++ b/packages/python/src/armonik/client/tasks.py @@ -1,6 +1,6 @@ from __future__ import annotations from grpc import Channel -from typing import Type, Union, cast, Tuple, List +from typing import cast, Tuple, List from ..common import Task, Direction from ..common.filter import StringFilter, StatusFilter, DateFilter, NumberFilter, Filter @@ -92,6 +92,10 @@ def list_tasks(self, task_filter: Filter, with_errors: bool = False, page: int = - The total number of tasks for the given filter - The obtained list of tasks """ - request = ListTasksRequest(page=page, page_size=page_size, filters=cast(rawFilters, task_filter.to_disjunction().to_message()), sort=ListTasksRequest.Sort(field=cast(TaskField, sort_field.field), direction=sort_direction), with_errors=with_errors) + request = ListTasksRequest(page=page, + page_size=page_size, + filters=cast(rawFilters, task_filter.to_disjunction().to_message()), + sort=ListTasksRequest.Sort(field=cast(TaskField, sort_field.field), direction=sort_direction), + with_errors=with_errors) list_response: ListTasksDetailedResponse = self._client.ListTasksDetailed(request) return list_response.total, [Task.from_message(t) for t in list_response.tasks] diff --git a/packages/python/src/armonik/common/filter.py b/packages/python/src/armonik/common/filter.py index 330329e2e..d80ccd312 100644 --- a/packages/python/src/armonik/common/filter.py +++ b/packages/python/src/armonik/common/filter.py @@ -76,11 +76,12 @@ def to_disjunction(self) -> Filter: def __and__(self, other: "Filter") -> "Filter": if not isinstance(other, Filter): - raise Exception(f"Cannot create a conjunction between Filter and {other.__class__.__name__}") + msg = f"Cannot create a conjunction between Filter and {other.__class__.__name__}" + raise Exception(msg) if self.is_true_disjunction() or other.is_true_disjunction(): - raise Exception(f"Cannot make a conjunction of disjunctions") + raise Exception("Cannot make a conjunction of disjunctions") if self.conjunction_type != other.conjunction_type: - raise Exception(f"Conjunction types are different") + raise Exception("Conjunction types are different") return Filter(None, self.disjunction_type, self.conjunction_type, self.conjunction_type, None, [self.to_disjunction()._filters[0] + other.to_disjunction()._filters[0]]) def __mul__(self, other: Filter) -> "Filter": @@ -88,9 +89,10 @@ def __mul__(self, other: Filter) -> "Filter": def __or__(self, other: "Filter") -> "Filter": if not isinstance(other, Filter): - raise Exception(f"Cannot create a conjunction between Filter and {other.__class__.__name__}") + msg = f"Cannot create a conjunction between Filter and {other.__class__.__name__}" + raise Exception(msg) if self.disjunction_type != other.disjunction_type: - raise Exception(f"Disjunction types are different") + raise Exception("Disjunction types are different") return Filter(None, self.disjunction_type, self.conjunction_type, self.disjunction_type, None, self.to_disjunction()._filters + other.to_disjunction()._filters) def __add__(self, other: "Filter") -> "Filter": @@ -126,8 +128,9 @@ def __invert__(self) -> Filter: """ if self.operator is None: if self.is_true_conjunction() or self.is_true_disjunction(): - raise Exception(f"Cannot invert conjunctions or disjunctions") - raise Exception(f"Cannot invert None operator in class {self.__class__.__name__} for field {str(self.field)}") + raise Exception("Cannot invert conjunctions or disjunctions") + msg = f"Cannot invert None operator in class {self.__class__.__name__} for field {str(self.field)}" + raise Exception(msg) if self.operator == self.__class__.eq_: return self.__ne__(self.value) if self.operator == self.__class__.ne_: @@ -144,7 +147,8 @@ def __invert__(self) -> Filter: return self._check(self.value, self.__class__.notcontains_, "not_contains") if self.operator == self.__class__.notcontains_: return self.contains(self.value) - raise Exception(f"{self.__class__.__name__} operator {str(self.operator)} for field {str(self.field)} has no inverted equivalent") + msg = f"{self.__class__.__name__} operator {str(self.operator)} for field {str(self.field)} has no inverted equivalent" + raise Exception(msg) def __neg__(self) -> "Filter": return ~self @@ -176,7 +180,8 @@ def _verify_value(self, value): """ if self.__class__.value_type_ is None or isinstance(value, self.__class__.value_type_): return - raise Exception(f"Expected value type {str(self.__class__.value_type_)} for field {str(self.field)}, got {str(type(value))} instead") + msg = f"Expected value type {str(self.__class__.value_type_)} for field {str(self.field)}, got {str(type(value))} instead" + raise Exception(msg) def _check(self, value: Any, operator: Any, operator_str: str = "") -> "Filter": """ @@ -193,10 +198,11 @@ def _check(self, value: Any, operator: Any, operator_str: str = "") -> "Filter": NotImplementedError if the given operator is not available for the given class """ if self.is_true_conjunction() or self.is_true_disjunction(): - raise Exception(f"Cannot apply operator to a disjunction or a conjunction") + raise Exception("Cannot apply operator to a disjunction or a conjunction") self._verify_value(value) if operator is None: - raise NotImplementedError(f"Operator {operator_str} is not available for {self.__class__.__name__}") + msg = f"Operator {operator_str} is not available for {self.__class__.__name__}" + raise NotImplementedError(msg) return self.__class__(self.field, self.disjunction_type, self.conjunction_type, self.message_type, self.inner_message_type, self._filters, value, operator) @abstractmethod