1
- # ignoring "line too long" check from linter
2
- # ruff: noqa: E501
3
1
"""This module provides an abstraction layer above the Speckle Automate runtime."""
4
2
5
3
import time
@@ -75,7 +73,7 @@ def initialize(
75
73
speckle_client .authenticate_with_token (speckle_token )
76
74
if not speckle_client .account :
77
75
msg = (
78
- f"Could not autenticate to { automation_run_data .speckle_server_url } " ,
76
+ f"Could not authenticate to { automation_run_data .speckle_server_url } " ,
79
77
"with the provided token" ,
80
78
)
81
79
raise ValueError (msg )
@@ -109,18 +107,24 @@ def receive_version(self) -> Base:
109
107
)
110
108
except SpeckleException as err :
111
109
raise ValueError (
112
- f"""\
113
- Could not receive specified version.
114
- Is your environment configured correctly?
115
- project_id: { self .automation_run_data .project_id }
116
- model_id: { self .automation_run_data .triggers [0 ].payload .model_id }
117
- version_id: { self .automation_run_data .triggers [0 ].payload .version_id }
118
- """
110
+ f"""Could not receive specified version.
111
+ Is your environment configured correctly?
112
+ project_id: { self .automation_run_data .project_id }
113
+ model_id: { self .automation_run_data .triggers [0 ].payload .model_id }
114
+ version_id: { self .automation_run_data .triggers [0 ].payload .version_id }
115
+ """
119
116
) from err
120
117
118
+ if not version .referenced_object :
119
+ raise Exception (
120
+ "This version is past the version history limit," ,
121
+ " cannot execute an automation on it" ,
122
+ )
123
+
121
124
base = operations .receive (
122
125
version .referenced_object , self ._server_transport , self ._memory_transport
123
126
)
127
+ # self._closure_tree = base["__closure"]
124
128
print (
125
129
f"It took { self .elapsed ():.2f} seconds to receive" ,
126
130
f" the speckle version { version_id } " ,
@@ -242,7 +246,7 @@ def report_run_status(self) -> None:
242
246
)
243
247
if self .run_status in [AutomationStatus .SUCCEEDED , AutomationStatus .FAILED ]:
244
248
object_results = {
245
- "version" : 1 ,
249
+ "version" : 2 ,
246
250
"values" : {
247
251
"objectResults" : self ._automation_result .model_dump (by_alias = True )[
248
252
"objectResults"
@@ -332,26 +336,24 @@ def _mark_run(
332
336
def attach_error_to_objects (
333
337
self ,
334
338
category : str ,
335
- object_ids : Union [str , List [str ]],
339
+ affected_objects : Union [Base , List [Base ]],
336
340
message : Optional [str ] = None ,
337
341
metadata : Optional [Dict [str , Any ]] = None ,
338
342
visual_overrides : Optional [Dict [str , Any ]] = None ,
339
343
) -> None :
340
344
"""Add a new error case to the run results.
341
-
342
- If the error cause has already created an error case,
343
- the error will be extended with a new case refering to the causing objects.
344
345
Args:
345
- error_tag (str): A short tag for the error type.
346
- causing_object_ids (str[]): A list of object_id-s that are causing the error
347
- error_messagge (Optional[str]): Optional error message.
346
+ category (str): A short tag for the event type.
347
+ affected_objects (Union[Base, List[Base]]): A single object or a list of
348
+ objects that are causing the error case.
349
+ message (Optional[str]): Optional message.
348
350
metadata: User provided metadata key value pairs
349
351
visual_overrides: Case specific 3D visual overrides.
350
352
"""
351
353
self .attach_result_to_objects (
352
354
ObjectResultLevel .ERROR ,
353
355
category ,
354
- object_ids ,
356
+ affected_objects ,
355
357
message ,
356
358
metadata ,
357
359
visual_overrides ,
@@ -360,16 +362,25 @@ def attach_error_to_objects(
360
362
def attach_warning_to_objects (
361
363
self ,
362
364
category : str ,
363
- object_ids : Union [str , List [str ]],
365
+ affected_objects : Union [Base , List [Base ]],
364
366
message : Optional [str ] = None ,
365
367
metadata : Optional [Dict [str , Any ]] = None ,
366
368
visual_overrides : Optional [Dict [str , Any ]] = None ,
367
369
) -> None :
368
- """Add a new warning case to the run results."""
370
+ """Add a new warning case to the run results.
371
+
372
+ Args:
373
+ category (str): A short tag for the event type.
374
+ affected_objects (Union[Base, List[Base]]): A single object or a list of
375
+ objects that are causing the warning case.
376
+ message (Optional[str]): Optional message.
377
+ metadata: User provided metadata key value pairs
378
+ visual_overrides: Case specific 3D visual overrides.
379
+ """
369
380
self .attach_result_to_objects (
370
381
ObjectResultLevel .WARNING ,
371
382
category ,
372
- object_ids ,
383
+ affected_objects ,
373
384
message ,
374
385
metadata ,
375
386
visual_overrides ,
@@ -378,16 +389,25 @@ def attach_warning_to_objects(
378
389
def attach_success_to_objects (
379
390
self ,
380
391
category : str ,
381
- object_ids : Union [str , List [str ]],
392
+ affected_objects : Union [Base , List [Base ]],
382
393
message : Optional [str ] = None ,
383
394
metadata : Optional [Dict [str , Any ]] = None ,
384
395
visual_overrides : Optional [Dict [str , Any ]] = None ,
385
396
) -> None :
386
- """Add a new success case to the run results."""
397
+ """Add a new success case to the run results.
398
+
399
+ Args:
400
+ category (str): A short tag for the event type.
401
+ affected_objects (Union[Base, List[Base]]): A single object or a list of
402
+ objects that are causing the success case.
403
+ message (Optional[str]): Optional message.
404
+ metadata: User provided metadata key value pairs
405
+ visual_overrides: Case specific 3D visual overrides.
406
+ """
387
407
self .attach_result_to_objects (
388
408
ObjectResultLevel .SUCCESS ,
389
409
category ,
390
- object_ids ,
410
+ affected_objects ,
391
411
message ,
392
412
metadata ,
393
413
visual_overrides ,
@@ -396,16 +416,25 @@ def attach_success_to_objects(
396
416
def attach_info_to_objects (
397
417
self ,
398
418
category : str ,
399
- object_ids : Union [str , List [str ]],
419
+ affected_objects : Union [Base , List [Base ]],
400
420
message : Optional [str ] = None ,
401
421
metadata : Optional [Dict [str , Any ]] = None ,
402
422
visual_overrides : Optional [Dict [str , Any ]] = None ,
403
423
) -> None :
404
- """Add a new info case to the run results."""
424
+ """Add a new info case to the run results.
425
+
426
+ Args:
427
+ category (str): A short tag for the event type.
428
+ affected_objects (Union[Base, List[Base]]): A single object or a list of
429
+ objects that are causing the info case.
430
+ message (Optional[str]): Optional message.
431
+ metadata: User provided metadata key value pairs
432
+ visual_overrides: Case specific 3D visual overrides.
433
+ """
405
434
self .attach_result_to_objects (
406
435
ObjectResultLevel .INFO ,
407
436
category ,
408
- object_ids ,
437
+ affected_objects ,
409
438
message ,
410
439
metadata ,
411
440
visual_overrides ,
@@ -415,19 +444,39 @@ def attach_result_to_objects(
415
444
self ,
416
445
level : ObjectResultLevel ,
417
446
category : str ,
418
- object_ids : Union [str , List [str ]],
447
+ affected_objects : Union [Base , List [Base ]],
419
448
message : Optional [str ] = None ,
420
449
metadata : Optional [Dict [str , Any ]] = None ,
421
450
visual_overrides : Optional [Dict [str , Any ]] = None ,
422
451
) -> None :
423
- if isinstance (object_ids , list ):
424
- if len (object_ids ) < 1 :
452
+ """Add a new result case to the run results.
453
+
454
+ Args:
455
+ level: Result level.
456
+ category (str): A short tag for the event type.
457
+ affected_objects (Union[Base, List[Base]]): A single object or a list of
458
+ objects that are causing the info case.
459
+ message (Optional[str]): Optional message.
460
+ metadata: User provided metadata key value pairs
461
+ visual_overrides: Case specific 3D visual overrides.
462
+ """
463
+ if isinstance (affected_objects , list ):
464
+ if len (affected_objects ) < 1 :
425
465
raise ValueError (
426
- f"Need atleast one object_id to report a(n) { level .value .upper ()} "
466
+ f"Need atleast one object to report a(n) { level .value .upper ()} "
427
467
)
428
- id_list = object_ids
468
+ object_list = affected_objects
429
469
else :
430
- id_list = [object_ids ]
470
+ object_list = [affected_objects ]
471
+
472
+ ids : Dict [str , Optional [str ]] = {}
473
+ for o in object_list :
474
+ # validate that the Base.id is not None. If its a None, throw an Exception
475
+ if not o .id :
476
+ raise Exception (
477
+ f"You can only attach { level } results to objects with an id."
478
+ )
479
+ ids [o .id ] = o .applicationId
431
480
print (
432
481
f"Created new { level .value .upper ()} "
433
482
f" category: { category } caused by: { message } "
@@ -436,7 +485,7 @@ def attach_result_to_objects(
436
485
ResultCase (
437
486
category = category ,
438
487
level = level ,
439
- object_ids = id_list ,
488
+ object_app_ids = ids ,
440
489
message = message ,
441
490
metadata = metadata ,
442
491
visual_overrides = visual_overrides ,
0 commit comments