Update version handling in automation function
- Added a global VERSION variable for tracking. - Updated comments to reflect changes from 'version' to 'VERSION'. - Adjusted logic to retrieve the version from the root object. - Enhanced success message to include the current version.
This commit is contained in:
+12
-11
@@ -2,21 +2,23 @@
|
||||
# It will receive the inputs from the user, and the context of the run.
|
||||
# It will then apply the rules to the objects in the model, and report back the results.
|
||||
|
||||
|
||||
from pandas import DataFrame
|
||||
from speckle_automate import AutomationContext
|
||||
from specklepy.objects.base import Base
|
||||
|
||||
from src.helpers import flatten_base
|
||||
from src.inputs import FunctionInputs
|
||||
from src.rule_processor import apply_rules_to_objects
|
||||
from src.spreadsheet import read_rules_from_spreadsheet
|
||||
|
||||
VERSION: int = 2
|
||||
|
||||
|
||||
def automate_function(
|
||||
automate_context: AutomationContext,
|
||||
function_inputs: FunctionInputs,
|
||||
) -> None:
|
||||
"""This version of the function will add a check for the new provide inputs.
|
||||
"""This VERSION of the function will add a check for the new provide inputs.
|
||||
|
||||
Args:
|
||||
automate_context: A context helper object, that carries relevant information
|
||||
@@ -25,17 +27,16 @@ def automate_function(
|
||||
It also has convenience methods attach result data to the Speckle model.
|
||||
function_inputs: An instance object matching the defined schema.
|
||||
"""
|
||||
# the context provides a convenient way, to receive the triggering version
|
||||
version_root_object = automate_context.receive_version()
|
||||
# the context provides a convenient way, to receive the triggering VERSION
|
||||
version_root_object: Base = automate_context.receive_version()
|
||||
|
||||
# We can continue to work with a flattened list of objects.
|
||||
flat_list_of_objects = list(flatten_base(version_root_object))
|
||||
|
||||
# If it is a next_gen model, we can get the version from the root object
|
||||
if type(version_root_object) == "Base":
|
||||
version = version_root_object.version
|
||||
else:
|
||||
version = None
|
||||
# If it is a next_gen model, we can get the VERSION from the root object
|
||||
# This function's rules don't make use of this check, but it is here for reference if you want to.
|
||||
global VERSION
|
||||
VERSION = getattr(version_root_object, "version", 2) # noqa: F841SION = getattr(version_root_object,"version", 2) # noqa: F841 # noqa: F841
|
||||
|
||||
# read the rules from the spreadsheet
|
||||
rules: DataFrame = read_rules_from_spreadsheet(function_inputs.spreadsheet_url)
|
||||
@@ -48,10 +49,10 @@ def automate_function(
|
||||
# apply the rules to the objects
|
||||
apply_rules_to_objects(flat_list_of_objects, grouped_rules, automate_context)
|
||||
|
||||
# set the automation context view, to the original model / version view
|
||||
# set the automation context view, to the original model / VERSION view
|
||||
automate_context.set_context_view()
|
||||
|
||||
# report success
|
||||
automate_context.mark_run_success(
|
||||
f"Successfully applied {len(grouped_rules)} rules to {len(flat_list_of_objects)} objects."
|
||||
f"Successfully applied {len(grouped_rules)} rules to {len(flat_list_of_objects)} version {VERSION} objects."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user