Skip to content

Commit

Permalink
fix(workflow): optional list of file like object os now ignored by wo…
Browse files Browse the repository at this point in the history
…rkflow state
  • Loading branch information
GhislainJ committed Dec 6, 2023
1 parent 417d03f commit c61388b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
12 changes: 11 additions & 1 deletion dessia_common/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,20 @@ def isinstance_base_types(obj):


def is_dessia_file(obj):
"""Return if the object inherits from dessia files."""
""" Wether object inherits from dessia files. """
return isinstance(obj, (BinaryFile, StringFile))


def is_file_or_file_sequence(object_):
""" Whether object inherits from dessia file or is a container of such objects. """
is_file = is_dessia_file(object_)
if not is_file and is_sequence(object_):
for obj in object_:
if is_file_or_file_sequence(obj):
return True
return is_file


def get_python_class_from_class_name(full_class_name: str):
""" Get python class object corresponging to given classname. """
cached_value = _PYTHON_CLASS_CACHE.get(full_class_name, None)
Expand Down
22 changes: 10 additions & 12 deletions dessia_common/workflow/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import webbrowser
from functools import cached_property
import io
from typing import List, Union, Type, Any, Dict, Tuple, Optional, get_args
from typing import List, Union, Type, Any, Dict, Tuple, Optional, get_args, get_origin
from copy import deepcopy
import warnings
import networkx as nx
Expand All @@ -21,7 +21,7 @@
deserialize_argument, set_default_value, DisplaySetting

from dessia_common.utils.types import (serialize_typing, deserialize_typing, recursive_type,
typematch, is_typing, is_dessia_file)
typematch, is_typing, is_file_or_file_sequence)
from dessia_common.utils.copy import deepcopy_value
from dessia_common.utils.docstrings import FAILED_ATTRIBUTE_PARSING, EMPTY_PARSED_ATTRIBUTE
from dessia_common.utils.diff import choose_hash
Expand Down Expand Up @@ -121,7 +121,13 @@ def is_file_type(self) -> bool:
""" Return whether a variable is of type File given its type_ attribute. """
if is_typing(self.type_):
# Handling List[BinaryFile or StringFile]
return get_args(self.type_)[0] in [BinaryFile, StringFile]
origin = get_origin(self.type_)
args = get_args(self.type_)
relevant_arg = args[0]
if origin is Union and len(args) == 2 and type(None) in args:
# Check for Union false Positive (Default value = None)
relevant_arg = get_args(relevant_arg)[0]
return relevant_arg in [BinaryFile, StringFile]

if not isinstance(self.type_, type):
return False
Expand Down Expand Up @@ -1603,14 +1609,6 @@ def _data_eq(self, other_object: 'WorkflowState'):
if self.activated_items[pipe] != other_object.activated_items[other_pipe]:
# Check pipe progress state
return False

# Not comparing values, to avoid comparing cleaned values
# if self.activated_items[pipe] and pipe in self.values:
# # Not comparing values if ther
# if not is_dessia_file(self.values[pipe]) and not is_dessia_file(other_object.values[other_pipe]):
# if self.values[pipe] != other_object.values[other_pipe]:
# # Check variable values for evaluated ones
# return False
return True

def to_dict(self, use_pointers: bool = True, memo=None, path: str = '#', id_method=True, id_memo=None):
Expand Down Expand Up @@ -1658,7 +1656,7 @@ def to_dict(self, use_pointers: bool = True, memo=None, path: str = '#', id_meth
# Values
values = {}
for pipe, value in self.values.items():
if not is_dessia_file(value) and pipe in self.workflow.memorized_pipes:
if not is_file_or_file_sequence(value) and pipe in self.workflow.memorized_pipes:
pipe_index = self.workflow.pipes.index(pipe)
if use_pointers:
try:
Expand Down

0 comments on commit c61388b

Please sign in to comment.