Merge pull request #4 from bjoernsteinhagen/bjorn/proper-next-gen-validation

style: checking for next-gen more stable
This commit is contained in:
Björn Steinhagen
2025-02-12 23:11:34 +01:00
committed by GitHub
4 changed files with 37 additions and 16 deletions
+13 -3
View File
@@ -39,12 +39,23 @@ def automate_function(
commit_root = automate_context.speckle_client.commit.get( commit_root = automate_context.speckle_client.commit.get(
automate_context.automation_run_data.project_id, version_id automate_context.automation_run_data.project_id, version_id
) )
model_root = automate_context.receive_version()
# Validate source application # Validate source application
source_validator = RevitSourceValidator() # Built for revit, therefore check 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( 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 return
@@ -52,7 +63,6 @@ def automate_function(
processor = configure_components() processor = configure_components()
# Process model # Process model
model_root = automate_context.receive_version() # TODO: Line 35 and 36!?
processor.process_elements(model_root) processor.process_elements(model_root)
# Logger information - successes # Logger information - successes
@@ -8,5 +8,11 @@ class RevitSourceValidator(SourceApplicationValidator):
# ️ sourceApplication value for v3: slug => revit # ️ sourceApplication value for v3: slug => revit
# ⚠️ We're just working with v3 data - adapt commit_processor for v2 data structure if you want # ⚠️ 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() # ⚠️ Alternatively, write a model factory that injects the correct CommitProcessor()
def validate(self, source_app: str) -> bool: def validate_source_application(self, source_app: str) -> bool:
return source_app == "revit" 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
+8 -9
View File
@@ -5,14 +5,13 @@ class SourceApplicationValidator(ABC):
"""Interface for source application validator. """Interface for source application validator.
Host app should be supported by the automation. Host app should be supported by the automation.
""" """
@abstractmethod @abstractmethod
def validate(self, source_app: str) -> bool: def validate_source_application(self, source_app: str) -> bool:
"""Assert that the source application is supported. """Assert that the source application is supported."""
pass
Args:
source_app (str): sourceApplication from the commit root @abstractmethod
def validate_connector_version(self, connector_version: str) -> bool:
Returns: """Assert that the connector version is supported."""
bool: True if supported, False if not
"""
pass pass
+8 -2
View File
@@ -59,19 +59,25 @@ def create_processor_chain() -> tuple[RevitModel, RevitLogger]:
try: try:
# Get version data # Get version data
commit_root = branch.commits.items[0] commit_root = branch.commits.items[0]
model_root = model_data
# Validate source application # Validate source application
source_validator = RevitSourceValidator() source_validator = RevitSourceValidator()
if not source_validator.validate(commit_root.sourceApplication): if not source_validator.validate_source_application(commit_root.sourceApplication):
print( print(
f"Automation requires Revit v3 commits. Received: {commit_root.sourceApplication}" 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 # Create processor chain and get logger for results
processor, logger = create_processor_chain() processor, logger = create_processor_chain()
# Process model # Process model
model_root = model_data
processor.process_elements(model_root) processor.process_elements(model_root)
# Report compliance issues # Report compliance issues