From c00b56959d43489bd2382977fa92b35624f25dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinhagen?= Date: Wed, 12 Feb 2025 23:10:42 +0100 Subject: [PATCH] style: checking for next-gen more stable --- main.py | 16 +++++++++++++--- .../revit/revit_source_validator.py | 10 ++++++++-- src/core/base/source_validator.py | 17 ++++++++--------- tests/manual_test.py | 10 ++++++++-- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 4c458c1..2a36d0e 100644 --- a/main.py +++ b/main.py @@ -39,12 +39,23 @@ def automate_function( commit_root = automate_context.speckle_client.commit.get( automate_context.automation_run_data.project_id, version_id ) + model_root = automate_context.receive_version() # Validate source application source_validator = RevitSourceValidator() # Built for revit, therefore check - if not source_validator.validate(commit_root.sourceApplication): + if not source_validator.validate_source_application( + commit_root.sourceApplication + ): automate_context.mark_run_failed( - f"Automation requires Revit v3 commits. Received: {commit_root.sourceApplication}" + f"Automation requires models from Revit. Received: {commit_root.sourceApplication}" + ) + return + if not source_validator.validate_connector_version( + int(getattr(model_root, "version", 2)) + ): + automate_context.mark_run_failed( + "Automation required Revit models using the v3 " + "connector. Received: v2." ) return @@ -52,7 +63,6 @@ def automate_function( processor = configure_components() # Process model - model_root = automate_context.receive_version() # TODO: Line 35 and 36!? processor.process_elements(model_root) # Logger information - successes diff --git a/src/applications/revit/revit_source_validator.py b/src/applications/revit/revit_source_validator.py index 6fbbf74..77e867a 100644 --- a/src/applications/revit/revit_source_validator.py +++ b/src/applications/revit/revit_source_validator.py @@ -8,5 +8,11 @@ class RevitSourceValidator(SourceApplicationValidator): # ℹ️ sourceApplication value for v3: slug => revit # ⚠️ We're just working with v3 data - adapt commit_processor for v2 data structure if you want # ⚠️ Alternatively, write a model factory that injects the correct CommitProcessor() - def validate(self, source_app: str) -> bool: - return source_app == "revit" + def validate_source_application(self, source_app: str) -> bool: + return source_app.lower().startswith("revit") + + def validate_connector_version(self, connector_version: int) -> bool: + if connector_version == 2: + return False # TODO: If you want to support v2, implement a factory method + elif connector_version == 3: + return True diff --git a/src/core/base/source_validator.py b/src/core/base/source_validator.py index 5812d5f..00e6ec7 100644 --- a/src/core/base/source_validator.py +++ b/src/core/base/source_validator.py @@ -5,14 +5,13 @@ class SourceApplicationValidator(ABC): """Interface for source application validator. Host app should be supported by the automation. """ + @abstractmethod - def validate(self, source_app: str) -> bool: - """Assert that the source application is supported. - - Args: - source_app (str): sourceApplication from the commit root - - Returns: - bool: True if supported, False if not - """ + def validate_source_application(self, source_app: str) -> bool: + """Assert that the source application is supported.""" + pass + + @abstractmethod + def validate_connector_version(self, connector_version: str) -> bool: + """Assert that the connector version is supported.""" pass diff --git a/tests/manual_test.py b/tests/manual_test.py index 365cd3c..70fa66c 100644 --- a/tests/manual_test.py +++ b/tests/manual_test.py @@ -59,19 +59,25 @@ def create_processor_chain() -> tuple[RevitModel, RevitLogger]: try: # Get version data commit_root = branch.commits.items[0] + model_root = model_data # Validate source application source_validator = RevitSourceValidator() - if not source_validator.validate(commit_root.sourceApplication): + if not source_validator.validate_source_application(commit_root.sourceApplication): print( f"Automation requires Revit v3 commits. Received: {commit_root.sourceApplication}" ) + if not source_validator.validate_connector_version( + int(getattr(model_root, "version", 2)) + ): + print( + "Automation required Revit models using the v3 " "connector. Received: v2." + ) # Create processor chain and get logger for results processor, logger = create_processor_chain() # Process model - model_root = model_data processor.process_elements(model_root) # Report compliance issues