Skip to content

Commit 24c3bf7

Browse files
dawoodhqbenflexcompute
authored andcommitted
feat: Add folder parameter to project creation (#1325)
1 parent f4faab2 commit 24c3bf7

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

flow360/component/geometry.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import threading
99
from enum import Enum
10-
from typing import Any, List, Literal, Union
10+
from typing import Any, List, Literal, Optional, Union
1111

1212
import pydantic as pd
1313

@@ -25,6 +25,7 @@
2525
ResourceDraft,
2626
)
2727
from flow360.component.simulation.entity_info import GeometryEntityInfo
28+
from flow360.component.simulation.folder import Folder
2829
from flow360.component.simulation.primitives import Edge, GeometryBodyGroup, Surface
2930
from flow360.component.simulation.unit_system import LengthType
3031
from flow360.component.simulation.utils import model_attribute_unlock
@@ -91,12 +92,14 @@ def __init__(
9192
solver_version: str = None,
9293
length_unit: LengthUnitType = "m",
9394
tags: List[str] = None,
95+
folder: Optional[Folder] = None,
9496
):
9597
self._file_names = file_names
9698
self.project_name = project_name
9799
self.tags = tags if tags is not None else []
98100
self.length_unit = length_unit
99101
self.solver_version = solver_version
102+
self.folder = folder
100103
self._validate()
101104
ResourceDraft.__init__(self)
102105

@@ -186,9 +189,7 @@ def submit(self, description="", progress_callback=None, run_async=False) -> Geo
186189
)
187190
for file_path in self.file_names + mapbc_files
188191
],
189-
# pylint: disable=fixme
190-
# TODO: remove hardcoding
191-
parent_folder_id="ROOT.FLOW360",
192+
parent_folder_id=self.folder.id if self.folder else "ROOT.FLOW360",
192193
length_unit=self.length_unit,
193194
description=description,
194195
)
@@ -296,9 +297,12 @@ def from_file(
296297
solver_version: str = None,
297298
length_unit: LengthUnitType = "m",
298299
tags: List[str] = None,
300+
folder: Optional[Folder] = None,
299301
) -> GeometryDraft:
300302
# For type hint only but proper fix is to fully abstract the Draft class too.
301-
return super().from_file(file_names, project_name, solver_version, length_unit, tags)
303+
return super().from_file(
304+
file_names, project_name, solver_version, length_unit, tags, folder=folder
305+
)
302306

303307
def show_available_groupings(self, verbose_mode: bool = False):
304308
"""Display all the possible groupings for faces and edges"""

flow360/component/project.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
validate_params_with_context,
3131
)
3232
from flow360.component.resource_base import Flow360Resource
33+
from flow360.component.simulation.folder import Folder
3334
from flow360.component.simulation.simulation_params import SimulationParams
3435
from flow360.component.simulation.unit_system import LengthType
3536
from flow360.component.simulation.web.asset_base import AssetBase
@@ -635,6 +636,7 @@ def _create_project_from_files(
635636
length_unit: LengthUnitType = "m",
636637
tags: List[str] = None,
637638
run_async: bool = False,
639+
folder: Optional[Folder] = None,
638640
):
639641
"""
640642
Initializes a project from a file.
@@ -653,6 +655,8 @@ def _create_project_from_files(
653655
Tags to assign to the project (default is None).
654656
run_async : bool, optional
655657
Whether to create the project asynchronously (default is False).
658+
folder : Optional[Folder], optional
659+
Parent folder for the project. If None, creates in root.
656660
657661
Returns
658662
-------
@@ -670,14 +674,16 @@ def _create_project_from_files(
670674
files._check_files_existence()
671675

672676
if isinstance(files, GeometryFiles):
673-
draft = Geometry.from_file(files.file_names, name, solver_version, length_unit, tags)
677+
draft = Geometry.from_file(
678+
files.file_names, name, solver_version, length_unit, tags, folder=folder
679+
)
674680
elif isinstance(files, SurfaceMeshFile):
675681
draft = SurfaceMeshV2.from_file(
676-
files.file_names, name, solver_version, length_unit, tags
682+
files.file_names, name, solver_version, length_unit, tags, folder=folder
677683
)
678684
elif isinstance(files, VolumeMeshFile):
679685
draft = VolumeMeshV2.from_file(
680-
files.file_names, name, solver_version, length_unit, tags
686+
files.file_names, name, solver_version, length_unit, tags, folder=folder
681687
)
682688
else:
683689
raise Flow360FileError(
@@ -718,7 +724,11 @@ def _create_project_from_files(
718724
return project
719725

720726
@classmethod
721-
@pd.validate_call
727+
@pd.validate_call(
728+
config={
729+
"arbitrary_types_allowed": True
730+
} # Folder (v2: component/simulation/folder.py) does not have validate() defined
731+
)
722732
def from_geometry(
723733
cls,
724734
files: Union[str, list[str]],
@@ -728,6 +738,7 @@ def from_geometry(
728738
length_unit: LengthUnitType = "m",
729739
tags: List[str] = None,
730740
run_async: bool = False,
741+
folder: Optional[Folder] = None,
731742
):
732743
"""
733744
Initializes a project from local geometry files.
@@ -746,6 +757,8 @@ def from_geometry(
746757
Tags to assign to the project (default is None).
747758
run_async : bool, optional
748759
Whether to create project asynchronously (default is False).
760+
folder : Optional[Folder], optional
761+
Parent folder for the project. If None, creates in root.
749762
750763
Returns
751764
-------
@@ -781,10 +794,11 @@ def from_geometry(
781794
length_unit=length_unit,
782795
tags=tags,
783796
run_async=run_async,
797+
folder=folder,
784798
)
785799

786800
@classmethod
787-
@pd.validate_call
801+
@pd.validate_call(config={"arbitrary_types_allowed": True})
788802
def from_surface_mesh(
789803
cls,
790804
file: str,
@@ -794,6 +808,7 @@ def from_surface_mesh(
794808
length_unit: LengthUnitType = "m",
795809
tags: List[str] = None,
796810
run_async: bool = False,
811+
folder: Optional[Folder] = None,
797812
):
798813
"""
799814
Initializes a project from a local surface mesh file.
@@ -813,6 +828,8 @@ def from_surface_mesh(
813828
Tags to assign to the project (default is None).
814829
run_async : bool, optional
815830
Whether to create project asynchronously (default is False).
831+
folder : Optional[Folder], optional
832+
Parent folder for the project. If None, creates in root.
816833
817834
Returns
818835
-------
@@ -849,10 +866,11 @@ def from_surface_mesh(
849866
length_unit=length_unit,
850867
tags=tags,
851868
run_async=run_async,
869+
folder=folder,
852870
)
853871

854872
@classmethod
855-
@pd.validate_call
873+
@pd.validate_call(config={"arbitrary_types_allowed": True})
856874
def from_volume_mesh(
857875
cls,
858876
file: str,
@@ -862,6 +880,7 @@ def from_volume_mesh(
862880
length_unit: LengthUnitType = "m",
863881
tags: List[str] = None,
864882
run_async: bool = False,
883+
folder: Optional[Folder] = None,
865884
):
866885
"""
867886
Initializes a project from a local volume mesh file.
@@ -881,6 +900,8 @@ def from_volume_mesh(
881900
Tags to assign to the project (default is None).
882901
run_async : bool, optional
883902
Whether to create project asynchronously (default is False).
903+
folder : Optional[Folder], optional
904+
Parent folder for the project. If None, creates in root.
884905
885906
Returns
886907
-------
@@ -917,6 +938,7 @@ def from_volume_mesh(
917938
length_unit=length_unit,
918939
tags=tags,
919940
run_async=run_async,
941+
folder=folder,
920942
)
921943

922944
@classmethod

flow360/component/simulation/web/asset_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
EntityInfoModel,
2525
parse_entity_info_model,
2626
)
27+
from flow360.component.simulation.folder import Folder
2728
from flow360.component.simulation.framework.updater_utils import Flow360Version
2829
from flow360.component.simulation.simulation_params import SimulationParams
2930
from flow360.component.utils import (
@@ -255,12 +256,14 @@ def from_file(
255256
solver_version: str = None,
256257
length_unit: LengthUnitType = "m",
257258
tags: List[str] = None,
259+
folder: Optional[Folder] = None,
258260
):
259261
"""
260262
Create asset draft from files
261263
:param file_names:
262264
:param project_name:
263265
:param tags:
266+
:param folder: Folder object where the asset will be created (optional; defaults to root if unspecified)
264267
:return:
265268
"""
266269
# pylint: disable=not-callable
@@ -270,6 +273,7 @@ def from_file(
270273
solver_version=solver_version,
271274
tags=tags,
272275
length_unit=length_unit,
276+
folder=folder,
273277
)
274278

275279
@classmethod

flow360/component/surface_mesh_v2.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ResourceDraft,
2222
)
2323
from flow360.component.simulation.entity_info import SurfaceMeshEntityInfo
24+
from flow360.component.simulation.folder import Folder
2425
from flow360.component.simulation.web.asset_base import AssetBase
2526
from flow360.component.utils import (
2627
MeshNameParser,
@@ -90,12 +91,14 @@ def __init__(
9091
solver_version: str = None,
9192
length_unit: LengthUnitType = "m",
9293
tags: List[str] = None,
94+
folder: Optional[Folder] = None,
9395
):
9496
self._file_name = file_names
9597
self.project_name = project_name
9698
self.tags = tags if tags is not None else []
9799
self.length_unit = length_unit
98100
self.solver_version = solver_version
101+
self.folder = folder
99102
self._validate()
100103
ResourceDraft.__init__(self)
101104

@@ -157,9 +160,7 @@ def submit(self, description="", progress_callback=None, run_async=False) -> Sur
157160
solver_version=self.solver_version,
158161
tags=self.tags,
159162
file_name=self._file_name,
160-
# pylint: disable=fixme
161-
# TODO: remove hardcoding
162-
parent_folder_id="ROOT.FLOW360",
163+
parent_folder_id=self.folder.id if self.folder else "ROOT.FLOW360",
163164
length_unit=self.length_unit,
164165
description=description,
165166
)
@@ -277,6 +278,7 @@ def from_file(
277278
solver_version: str = None,
278279
length_unit: LengthUnitType = "m",
279280
tags: List[str] = None,
281+
folder: Optional[Folder] = None,
280282
) -> SurfaceMeshDraftV2:
281283
"""
282284
Parameters
@@ -291,6 +293,8 @@ def from_file(
291293
Length unit to use for the project ("m", "mm", "cm", "inch", "ft")
292294
tags: List[str]
293295
List of string tags to be added to the project upon creation
296+
folder : Optional[Folder], optional
297+
Parent folder for the project. If None, creates in root.
294298
295299
Returns
296300
-------
@@ -304,6 +308,7 @@ def from_file(
304308
solver_version=solver_version,
305309
length_unit=length_unit,
306310
tags=tags,
311+
folder=folder,
307312
)
308313

309314
# pylint: disable=useless-parent-delegation

flow360/component/volume_mesh.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929
from flow360.cloud.heartbeat import post_upload_heartbeat
3030
from flow360.cloud.rest_api import RestApi
31+
from flow360.component.simulation.folder import Folder
3132
from flow360.component.utils import VolumeMeshFile
3233
from flow360.component.v1.cloud.flow360_requests import NewVolumeMeshRequest
3334
from flow360.component.v1.meshing.params import VolumeMeshingParams
@@ -926,12 +927,14 @@ def __init__(
926927
solver_version: str = None,
927928
length_unit: LengthUnitType = "m",
928929
tags: List[str] = None,
930+
folder: Optional[Folder] = None,
929931
):
930932
self.file_name = file_names
931933
self.project_name = project_name
932934
self.tags = tags if tags is not None else []
933935
self.length_unit = length_unit
934936
self.solver_version = solver_version
937+
self.folder = folder
935938
self._validate()
936939
ResourceDraft.__init__(self)
937940

@@ -1011,6 +1014,7 @@ def submit(
10111014
solver_version=self.solver_version,
10121015
tags=self.tags,
10131016
file_name=original_file_with_compression,
1017+
parent_folder_id=self.folder.id if self.folder else "ROOT.FLOW360",
10141018
length_unit=self.length_unit,
10151019
format=mesh_format.value,
10161020
description=description,
@@ -1137,6 +1141,7 @@ def from_file(
11371141
solver_version: str = None,
11381142
length_unit: LengthUnitType = "m",
11391143
tags: List[str] = None,
1144+
folder: Optional[Folder] = None,
11401145
) -> VolumeMeshDraftV2:
11411146
"""
11421147
Parameters
@@ -1151,6 +1156,8 @@ def from_file(
11511156
Length unit to use for the project ("m", "mm", "cm", "inch", "ft")
11521157
tags: List[str]
11531158
List of string tags to be added to the project upon creation
1159+
folder : Optional[Folder], optional
1160+
Parent folder for the project. If None, creates in root.
11541161
11551162
Returns
11561163
-------
@@ -1164,6 +1171,7 @@ def from_file(
11641171
solver_version=solver_version,
11651172
length_unit=length_unit,
11661173
tags=tags,
1174+
folder=folder,
11671175
)
11681176

11691177
# pylint: disable=useless-parent-delegation

0 commit comments

Comments
 (0)