Skip to content

Commit

Permalink
Fixed fstrings in exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrasseur-aneo committed Sep 26, 2023
1 parent 7776a3f commit a82e08f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/python/proto2python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions packages/python/src/armonik/client/tasks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
28 changes: 17 additions & 11 deletions packages/python/src/armonik/common/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,23 @@ 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":
return self & other

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":
Expand Down Expand Up @@ -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_:
Expand All @@ -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
Expand Down Expand Up @@ -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":
"""
Expand All @@ -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
Expand Down

0 comments on commit a82e08f

Please sign in to comment.