Compare commits

...

5 Commits

Author SHA1 Message Date
Gergő Jedlicska 62912d4428 Merge pull request #306 from specklesystems/gergo/automateRaise
fix(automate_sdk): make sure we throw for failed version create
2023-10-03 16:08:00 +02:00
Gergő Jedlicska 67cf41d721 fix(automate_sdk): get model name from id 2023-10-03 16:04:22 +02:00
Gergő Jedlicska 4ad3761478 fix(automate_sdk): make sure we throw for failed version create 2023-10-03 15:28:50 +02:00
Gergő Jedlicska 6e8e08ae94 fix(automate): support py >= 3.10 typing 2023-10-03 08:13:40 +02:00
Gergő Jedlicska 6e7c36223f fix(automate_sdk): functions have releases 2023-10-02 14:03:07 +02:00
5 changed files with 46 additions and 14 deletions
@@ -8,9 +8,11 @@ import httpx
from gql import gql
from specklepy.api import operations
from specklepy.api.client import SpeckleClient
from specklepy.core.api.models import Branch
from specklepy.objects import Base
from specklepy.transports.memory import MemoryTransport
from specklepy.transports.server import ServerTransport
from specklepy.logging.exceptions import SpeckleException
from speckle_automate.schema import (
AutomateBase,
@@ -118,6 +120,10 @@ class AutomationContext:
f" that triggered this automation: {self.automation_run_data.model_id}"
)
branch = self._get_model(model_id)
if not branch.name:
raise ValueError(f"The model {model_id} has no name.")
root_object_id = operations.send(
root_object,
[self._server_transport, self._memory_transport],
@@ -131,8 +137,30 @@ class AutomationContext:
message=version_message,
source_application="SpeckleAutomate",
)
if isinstance(version_id, SpeckleException):
raise version_id
self._automation_result.result_versions.append(version_id)
def _get_model(self, model_id: str) -> Branch:
query = gql(
"""
query ProjectModel($projectId: String!, $modelId: String!){
project(id: $projectId) {
model(id: $modelId) {
name
id
description
}
}
}
"""
)
params = {"projectId": self.automation_run_data.project_id, "modelId": model_id}
response = self.speckle_client.httpclient.execute(query, params)
return Branch.model_validate(response["project"]["model"])
def report_run_status(self) -> None:
"""Report the current run status to the project of this automation."""
query = gql(
+5 -5
View File
@@ -1,7 +1,7 @@
""""""
from collections import defaultdict
from enum import Enum
from typing import Optional
from typing import Optional, List, Dict
from pydantic import BaseModel, ConfigDict, Field
from stringcase import camelcase
@@ -27,7 +27,7 @@ class AutomationRunData(BaseModel):
automation_run_id: str
function_id: str
function_revision: str
function_release: str
model_config = ConfigDict(
alias_generator=camelcase, populate_by_name=True, protected_namespaces=()
@@ -63,11 +63,11 @@ class AutomationResult(AutomateBase):
elapsed: float = 0
result_view: Optional[str] = None
result_versions: list[str] = Field(default_factory=list)
blobs: list[str] = Field(default_factory=list)
result_versions: List[str] = Field(default_factory=list)
blobs: List[str] = Field(default_factory=list)
run_status: AutomationStatus = AutomationStatus.RUNNING
status_message: Optional[str] = None
object_results: dict[str, list[ObjectResult]] = Field(
object_results: Dict[str, List[ObjectResult]] = Field(
default_factory=lambda: defaultdict(list) # typing: ignore
)
+7 -4
View File
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import List, Optional, Union
from gql import gql
@@ -7,6 +7,7 @@ from specklepy.api.resource import ResourceBase
from specklepy.logging import metrics
from specklepy.core.api.resources.commit import Resource as CoreResource
from specklepy.logging.exceptions import SpeckleException
class Resource(CoreResource):
@@ -55,8 +56,8 @@ class Resource(CoreResource):
branch_name: str = "main",
message: str = "",
source_application: str = "python",
parents: List[str] = None,
) -> str:
parents: Optional[List[str]] = None,
) -> Union[str, SpeckleException]:
"""
Creates a commit on a branch
@@ -76,7 +77,9 @@ class Resource(CoreResource):
str -- the id of the created commit
"""
metrics.track(metrics.SDK, self.account, {"name": "Commit Create"})
return super().create(stream_id, object_id, branch_name, message, source_application, parents)
return super().create(
stream_id, object_id, branch_name, message, source_application, parents
)
def update(self, stream_id: str, commit_id: str, message: str) -> bool:
"""
+4 -3
View File
@@ -1,9 +1,10 @@
from typing import List, Optional
from typing import List, Optional, Union
from gql import gql
from specklepy.core.api.models import Commit
from specklepy.core.api.resource import ResourceBase
from specklepy.logging.exceptions import SpeckleException
NAME = "commit"
@@ -106,8 +107,8 @@ class Resource(ResourceBase):
branch_name: str = "main",
message: str = "",
source_application: str = "python",
parents: List[str] = None,
) -> str:
parents: Optional[List[str]] = None,
) -> Union[str, SpeckleException]:
"""
Creates a commit on a branch
@@ -128,7 +128,7 @@ def automation_run_data(
automation_run_id = crypto_random_string(10)
function_id = crypto_random_string(10)
function_revision = crypto_random_string(10)
function_release = crypto_random_string(10)
return AutomationRunData(
project_id=project_id,
model_id=model_id,
@@ -139,7 +139,7 @@ def automation_run_data(
automation_revision_id=automation_revision_id,
automation_run_id=automation_run_id,
function_id=function_id,
function_revision=function_revision,
function_release=function_release,
)