@@ -379,7 +379,9 @@ def python_name(self) -> str:
379
379
380
380
def _set_python_name (self ):
381
381
this_command = self ._command ()
382
- self ._python_name = camel_to_snake_case (this_command .get_attr ("helpString" ))
382
+ self ._python_name = camel_to_snake_case (
383
+ this_command .get_attr ("APIName" ) or this_command .get_attr ("helpString" )
384
+ )
383
385
self ._cache_data (this_command )
384
386
385
387
def _cache_data (self , command ):
@@ -429,7 +431,10 @@ def __getattr__(self, attr):
429
431
return ArgumentWrapper (self , attr )
430
432
except Exception as ex :
431
433
logger .debug (str (ex ))
432
- return self ._task_objects .get (attr , None )
434
+ result = self ._task_objects .get (attr , None )
435
+ if result :
436
+ return result
437
+ return super ().__getattribute__ (attr )
433
438
434
439
def __setattr__ (self , attr , value ):
435
440
logger .debug (f"BaseTask.__setattr__({ attr } , { value } )" )
@@ -490,18 +495,15 @@ def update_child_tasks(self, setup_type_changed: bool):
490
495
"""Update child tasks."""
491
496
self ._task .UpdateChildTasks (SetupTypeChanged = setup_type_changed )
492
497
493
- def insert_compound_child_task (self ):
494
- """Insert a compound child task."""
495
- return self ._task .InsertCompoundChildTask ()
496
-
497
498
def _get_next_python_task_names (self ) -> list [str ]:
498
499
self ._python_task_names_map = {}
499
500
for command_name in self ._task .GetNextPossibleTasks ():
501
+ comm_obj = getattr (
502
+ self ._command_source ._command_source , command_name
503
+ ).create_instance ()
500
504
self ._python_task_names_map [
501
505
camel_to_snake_case (
502
- getattr (self ._command_source ._command_source , command_name )
503
- .create_instance ()
504
- .get_attr ("helpString" )
506
+ comm_obj .get_attr ("APIName" ) or comm_obj .get_attr ("helpString" )
505
507
)
506
508
] = command_name
507
509
return list (self ._python_task_names_map .keys ())
@@ -1163,6 +1165,10 @@ def _add_child(self, state: Optional[dict] = None) -> None:
1163
1165
state .update ({"add_child" : "yes" })
1164
1166
self .arguments .update_dict (state )
1165
1167
1168
+ def insert_compound_child_task (self ):
1169
+ """Insert a compound child task."""
1170
+ return self .add_child_and_update ()
1171
+
1166
1172
def add_child_and_update (self , state = None , defer_update = None ):
1167
1173
"""Add a child to this CompoundTask and update.
1168
1174
@@ -1183,18 +1189,20 @@ def add_child_and_update(self, state=None, defer_update=None):
1183
1189
)
1184
1190
self ._command_source ._compound_child = True
1185
1191
self ._command_source ._parent_of_compound_child = py_name
1186
- if self ._fluent_version >= FluentVersion .v241 :
1187
- if defer_update is None :
1188
- defer_update = False
1189
- self ._task .AddChildAndUpdate (DeferUpdate = defer_update )
1190
- else :
1191
- if defer_update is not None :
1192
- warnings .warn (
1193
- " The 'defer_update()' method is supported in Fluent 2024 R1 and later." ,
1194
- PyFluentUserWarning ,
1195
- )
1196
- self ._task .AddChildAndUpdate ()
1197
- self ._command_source ._compound_child = False
1192
+ try :
1193
+ if self ._fluent_version >= FluentVersion .v241 :
1194
+ if defer_update is None :
1195
+ defer_update = False
1196
+ self ._task .AddChildAndUpdate (DeferUpdate = defer_update )
1197
+ else :
1198
+ if defer_update is not None :
1199
+ warnings .warn (
1200
+ "The 'defer_update()' method is supported in Fluent 2024 R1 and later." ,
1201
+ PyFluentUserWarning ,
1202
+ )
1203
+ self ._task .AddChildAndUpdate ()
1204
+ finally :
1205
+ self ._command_source ._compound_child = False
1198
1206
return self .last_child ()
1199
1207
1200
1208
def last_child (self ) -> BaseTask :
@@ -1324,6 +1332,29 @@ def task(self, name: str) -> BaseTask:
1324
1332
1325
1333
The wrapper adds extra functionality.
1326
1334
1335
+ Parameters
1336
+ ----------
1337
+ name : str
1338
+ Task name - the display name, not the internal ID.
1339
+ Returns
1340
+ -------
1341
+ BaseTask
1342
+ wrapped task object.
1343
+ """
1344
+ py_name = self .tasks ()[
1345
+ [repr (task ) for task in self .tasks ()].index (repr (self ._task (name )))
1346
+ ].python_name ()
1347
+ warnings .warn (
1348
+ f"'task' is deprecated -> Use '{ py_name } ' instead." ,
1349
+ PyFluentDeprecationWarning ,
1350
+ )
1351
+ return self ._task (name )
1352
+
1353
+ def _task (self , name : str ) -> BaseTask :
1354
+ """Get a TaskObject by name, in a ``BaseTask`` wrapper.
1355
+
1356
+ The wrapper adds extra functionality.
1357
+
1327
1358
Parameters
1328
1359
----------
1329
1360
name : str
@@ -1393,7 +1424,7 @@ def inactive_tasks() -> list:
1393
1424
def __getattr__ (self , attr ):
1394
1425
"""Delegate attribute lookup to the wrapped workflow object."""
1395
1426
if attr in self ._repeated_task_python_name_display_text_map :
1396
- return self .task (self ._repeated_task_python_name_display_text_map [attr ])
1427
+ return self ._task (self ._repeated_task_python_name_display_text_map [attr ])
1397
1428
_task_object = self ._task_objects .get (attr )
1398
1429
if _task_object :
1399
1430
return _task_object
@@ -1453,7 +1484,7 @@ def _workflow_and_task_list_state(self) -> Tuple[dict, dict]:
1453
1484
def _task_by_id_impl (self , task_id , workflow_state ):
1454
1485
task_key = "TaskObject:" + task_id
1455
1486
task_state = workflow_state [task_key ]
1456
- return self .task (task_state ["_name_" ])
1487
+ return self ._task (task_state ["_name_" ])
1457
1488
1458
1489
def _task_by_id (self , task_id ):
1459
1490
workflow_state = self ._workflow_state ()
@@ -1536,7 +1567,9 @@ def _populate_first_tasks_python_name_command_id_map(self):
1536
1567
if isinstance (command_obj , PyCommand ):
1537
1568
command_obj_instance = command_obj .create_instance ()
1538
1569
if not command_obj_instance .get_attr ("requiredInputs" ):
1539
- help_str = command_obj_instance .get_attr ("helpString" )
1570
+ help_str = command_obj_instance .get_attr (
1571
+ "APIName"
1572
+ ) or command_obj_instance .get_attr ("helpString" )
1540
1573
if help_str :
1541
1574
self ._initial_task_python_names_map [help_str ] = command
1542
1575
del command_obj_instance
0 commit comments