Skip to content

Commit

Permalink
Merge branch 'master' into update/dataset_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
GhislainJ committed Mar 26, 2024
2 parents 6103cf7 + fe0642f commit d44c368
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fix

- Export: Add block_index if export blocks
- PhysicalObject : Remove to_stl encoding element
- Schema : Take `None` default value into account
- WorkflowRun : Compute memory usage, subtract before_memory


### Build

- Numpy : Restrict version to lower 2.0.0



## 0.16.1

### Fix
Expand Down
9 changes: 2 additions & 7 deletions dessia_common/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,7 @@ def to_docx(self, filepath: str):
self.to_docx_stream(filepath)

def zip_settings(self):
"""
Returns a list of streams containing different representations of the object.
Excel file stream generated by calling 'to_xlsx_stream' method.
JSON file stream generated by calling 'save_to_stream' method.
"""
""" Returns a list of streams that contain different exports of the objects. """
streams = []
for export_format in self._export_formats():
if export_format.extension != "zip":
Expand Down Expand Up @@ -708,7 +703,7 @@ def to_stl(self, filepath: str):
if not filepath.endswith('.stl'):
filepath += '.stl'

with open(filepath, 'wb', encoding='utf-8') as file:
with open(filepath, 'wb') as file:
self.to_stl_stream(stream=file)

def babylonjs(self, use_cdn=True, debug=False, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion dessia_common/schemas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ def object_default(default_value: CoreDessiaObject = UNDEFINED, class_schema: Cl
Return serialized user default if definition, else None.
"""
if default_value is not UNDEFINED:
if default_value is not UNDEFINED and default_value is not None:
return default_value.to_dict(use_pointers=False)
if class_schema is not None:
# TODO Should we implement this ? Right now, tests state that the result is None
Expand Down
13 changes: 13 additions & 0 deletions dessia_common/workflow/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,19 @@ def to_markdown(self, **kwargs) -> str:
return template.substitute(name=self.name, workflow_name=self.workflow.name,
output_table=output_table, execution_info=execution_info)

def zip_settings(self):
""" Returns a list of streams that contain different exports of the objects. """
streams = []
for export_format in self.workflow.blocks_export_formats:
if export_format.extension != "zip":
method_name = export_format.method_name
stream_class = StringFile if export_format.text else BinaryFile
stream = stream_class(filename=export_format.export_name)
block_index = export_format.args.get('block_index')
getattr(self, method_name)(stream, block_index)
streams.append(stream)
return streams


def initialize_workflow(dict_, global_dict, pointers_memo) -> Workflow:
""" Generate blocks, pipes, detached_variables and output from a serialized state. """
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_branch():
"humanize",
"matplotlib",
"networkx",
"numpy",
"numpy<2.0.0",
"openpyxl",
"orjson>=3.8.0",
"pandas",
Expand Down
18 changes: 17 additions & 1 deletion tests/test_schemas/test_computation_structures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dessia_common.schemas.core import ClassProperty, MethodTypeProperty, AttributeTypeProperty, SchemaAttribute
from dessia_common.core import DessiaObject
from dessia_common.schemas.core import ClassProperty, MethodTypeProperty, AttributeTypeProperty, SchemaAttribute, \
CustomClass
from dessia_common.forms import StandaloneObject
from dessia_common.typings import MethodType, ClassMethodType, AttributeType, ClassAttributeType
from typing import Type
Expand All @@ -8,6 +10,7 @@


CUSTOM_CLASS = SchemaAttribute(name="custom_class")
CUSTOM_CLASS_DEFAULT = SchemaAttribute(name="custom_class", editable=True, title="CustomClass", default_value=None)
ATTRIBUTE = SchemaAttribute(name="attribute")
METHOD = SchemaAttribute(name="method")

Expand Down Expand Up @@ -58,6 +61,19 @@ def test_attributes(self, schema, expected_type, expected_typing, expected_class
self.assertEqual(computed_schema["properties"]["class_"]["type"], "object")
self.assertEqual(computed_schema["properties"]["class_"]["python_typing"], expected_class)

@parameterized.expand([
(CustomClass(annotation=DessiaObject, attribute=CUSTOM_CLASS_DEFAULT),
"object", "dessia_common.core.DessiaObject"),
(CustomClass(annotation=DessiaObject, attribute=CUSTOM_CLASS),
"object", "dessia_common.core.DessiaObject")
])
def test_custom_classes(self, schema, expected_type, expected_python_typing):
computed_schema = schema.to_dict()
self.assertEqual(computed_schema["type"], expected_type)
self.assertEqual(computed_schema["python_typing"], expected_python_typing)
self.assertEqual(computed_schema["title"], schema.attribute.title)
self.assertEqual(computed_schema["editable"], schema.attribute.editable)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit d44c368

Please sign in to comment.