Compare commits

..

27 Commits

Author SHA1 Message Date
Gergő Jedlicska f6917b0761 Merge pull request #318 from specklesystems/gergo/markLogs
feat: reduce log message context for object results
2023-11-13 11:39:49 +01:00
Gergő Jedlicska 04764b17eb feat: reduce log message context for object results 2023-11-13 09:14:06 +01:00
Gergő Jedlicska dbe3d759f6 Merge pull request #317 from specklesystems/KatKatKateryna-patch-1
handle "append" with incoming type "list"
2023-11-13 09:09:23 +01:00
KatKatKateryna f6ff484e66 handle "append" with incoming type "list" 2023-11-13 04:53:03 +08:00
Gergő Jedlicska bd000395af Merge pull request #316 from specklesystems/gergo/contextViewFix
fix: report relative url for context view
2023-11-11 08:32:40 +01:00
Gergő Jedlicska 10f49579fd fix: report relative url for context view 2023-11-11 08:29:16 +01:00
Gergő Jedlicska 1693465dfc Merge pull request #314 from specklesystems/kate/stream_wrapper_fe2
update stream wrapper; add tests
2023-11-10 15:15:12 +01:00
Gergő Jedlicska c3a7ead8f5 Merge branch 'main' into kate/stream_wrapper_fe2 2023-11-10 15:11:28 +01:00
Gergő Jedlicska d151a8d0ae Merge pull request #315 from specklesystems/jrm/minio/fix
Pinned MinIO version for integration test docker compose
2023-11-10 15:06:14 +01:00
Gergő Jedlicska c0dd88cbdb fix: pin minio release to fix tests 2023-11-10 15:04:30 +01:00
Jedd Morgan 71d3589e72 pinned MinIO version for integration test docker compose 2023-11-10 13:54:02 +00:00
KatKatKateryna 5bde1bc2d6 remove library 2023-11-09 17:36:06 +00:00
KatKatKateryna 75e6f0229a update stream wrapper; add tests 2023-11-09 17:34:57 +00:00
Gergő Jedlicska 5d7e71f357 Merge pull request #313 from specklesystems/oguzhan/text-object
Chore (Objects): Add text object definition
2023-10-30 12:37:02 +01:00
oguzhankoral 6c223b6fb3 Exclude displayStyle from Text object
It shouldn't be have displayStyle for general purpose Text object, because displayStyle more Rhino and AutoCAD specific
2023-10-30 14:07:36 +03:00
oguzhankoral e6131a7956 Fix typo on type of displayValue 2023-10-30 11:51:15 +03:00
oguzhankoral 45b50e4f26 Add optional props of Objects.Other.Text 2023-10-30 11:42:30 +03:00
oguzhankoral d9b92490ec Add text object definition 2023-10-27 16:33:02 +03:00
Gergő Jedlicska 37c09fa56c Merge pull request #311 from specklesystems/gergo/contextView
fix: automate sdk context view is a realative url
2023-10-26 15:38:50 +02:00
Gergő Jedlicska cbae4d300d Merge branch 'main' into gergo/contextView 2023-10-26 15:36:30 +02:00
Gergő Jedlicska 2742c12e31 fix: automate sdk context view is a realative url 2023-10-26 15:35:39 +02:00
Gergő Jedlicska 6dd0813089 Merge pull request #310 from specklesystems/gergo/contextView
Gergo/context view
2023-10-26 15:02:37 +02:00
Gergő Jedlicska a1831b57db feat: automation context result view reporting and creating 2023-10-26 15:00:03 +02:00
Gergő Jedlicska 1ff3245531 feat: automate sdk report context view 2023-10-26 13:32:48 +02:00
Gergő Jedlicska 3b4723a186 Merge pull request #309 from specklesystems/gergo/automateReportFunctionName
feat: migrate to new automate api
2023-10-25 18:06:44 +02:00
Gergő Jedlicska efe9551c5e fix: legacy typing and tests 2023-10-25 17:53:23 +02:00
Gergő Jedlicska 23a5087fbc feat: migrate to new automate api 2023-10-25 17:46:00 +02:00
9 changed files with 189 additions and 61 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ services:
retries: 30
minio:
image: "minio/minio"
image: "minio/minio:RELEASE.2023-10-25T06-33-25Z"
command: server /data --console-address ":9001"
restart: always
volumes:
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "specklepy"
version = "2.17.5"
version = "2.17.8"
description = "The Python SDK for Speckle 2.0"
readme = "README.md"
authors = ["Speckle Systems <devops@speckle.systems>"]
+61 -47
View File
@@ -2,7 +2,7 @@
from dataclasses import dataclass, field
from pathlib import Path
import time
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Tuple, Union
import httpx
from gql import gql
@@ -91,7 +91,7 @@ class AutomationContext:
def elapsed(self) -> float:
"""Return the elapsed time in seconds since the initialization time."""
return (time.perf_counter() - self._init_time) / 1000
return time.perf_counter() - self._init_time
def receive_version(self) -> Base:
"""Receive the Speckle project version that triggered this automation run."""
@@ -110,8 +110,8 @@ class AutomationContext:
return base
def create_new_version_in_project(
self, root_object: Base, model_id: str, version_message: str = ""
) -> str:
self, root_object: Base, model_name: str, version_message: str = ""
) -> Tuple[str, str]:
"""Save a base model to a new version on the project.
Args:
@@ -120,15 +120,28 @@ class AutomationContext:
version_message (str): The message for the new version.
"""
if model_id == self.automation_run_data.model_id:
if model_name == self.automation_run_data.branch_name:
raise ValueError(
f"The target model id: {model_id} cannot match the model id"
f" that triggered this automation: {self.automation_run_data.model_id}"
f"The target model: {model_name} cannot match the model"
f" that triggered this automation:"
f" {self.automation_run_data.model_id} /"
f" {self.automation_run_data.branch_name}"
)
branch = self._get_model(model_id)
if not branch.name:
raise ValueError(f"The model {model_id} has no name.")
branch = self.speckle_client.branch.get(
self.automation_run_data.project_id, model_name, 1
)
# we just check if it exists
if (not branch) or isinstance(branch, SpeckleException):
branch_create = self.speckle_client.branch.create(
self.automation_run_data.project_id,
model_name,
)
if isinstance(branch_create, Exception):
raise branch_create
model_id = branch_create
else:
model_id = branch.id
root_object_id = operations.send(
root_object,
@@ -139,7 +152,7 @@ class AutomationContext:
version_id = self.speckle_client.commit.create(
stream_id=self.automation_run_data.project_id,
object_id=root_object_id,
branch_name=branch.name,
branch_name=model_name,
message=version_message,
source_application="SpeckleAutomate",
)
@@ -148,43 +161,35 @@ class AutomationContext:
raise version_id
self._automation_result.result_versions.append(version_id)
return version_id
return model_id, 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"])
@property
def context_view(self) -> Optional[str]:
return self._automation_result.result_view
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
}
}
}
"""
def set_context_view(
self,
# f"{model_id}@{version_id} or {model_id} "
resource_ids: Optional[List[str]] = None,
include_source_model_version: bool = True,
) -> None:
link_resources = (
[
f"{self.automation_run_data.model_id}@{self.automation_run_data.version_id}"
]
if include_source_model_version
else []
)
if resource_ids:
link_resources.extend(resource_ids)
if not link_resources:
raise Exception(
"We do not have enough resource ids to compose a context view"
)
self._automation_result.result_view = (
f"/projects/{self.automation_run_data.project_id}"
f"/models/{','.join(link_resources)}"
)
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."""
@@ -196,8 +201,11 @@ class AutomationContext:
$automationRunId: String!,
$versionId: String!,
$functionId: String!,
$functionName: String!,
$functionLogo: String,
$runStatus: AutomationRunStatus!
$elapsed: Float!
$contextView: String
$resultVersionIds: [String!]!
$statusMessage: String
$objectResults: JSONObject
@@ -211,7 +219,10 @@ class AutomationContext:
functionRuns: [
{
functionId: $functionId
functionName: $functionName
functionLogo: $functionLogo
status: $runStatus,
contextView: $contextView,
elapsed: $elapsed,
resultVersionIds: $resultVersionIds,
statusMessage: $statusMessage
@@ -241,8 +252,11 @@ class AutomationContext:
"automationRunId": self.automation_run_data.automation_run_id,
"versionId": self.automation_run_data.version_id,
"functionId": self.automation_run_data.function_id,
"functionName": self.automation_run_data.function_name,
"functionLogo": self.automation_run_data.function_logo,
"runStatus": self.run_status.value,
"statusMessage": self._automation_result.status_message,
"contextView": self._automation_result.result_view,
"elapsed": self.elapsed(),
"resultVersionIds": self._automation_result.result_versions,
"objectResults": object_results,
@@ -391,8 +405,8 @@ class AutomationContext:
else:
id_list = [object_ids]
print(
f"Object {', '.join(id_list)} was marked with {level.value.upper()}",
f"/{category} cause: {message}",
f"Created new {level.value.upper()}"
f" category: {category} caused by: {message}"
)
self._automation_result.object_results.append(
ResultCase(
+2
View File
@@ -146,5 +146,7 @@ def run_function(
"Function error. Check the automation run logs for details."
)
finally:
if not automation_context.context_view:
automation_context.set_context_view()
automation_context.report_run_status()
return automation_context
+1 -1
View File
@@ -26,8 +26,8 @@ class AutomationRunData(BaseModel):
automation_run_id: str
function_id: str
function_release: str
function_name: str
function_logo: Optional[str]
model_config = ConfigDict(
alias_generator=camelcase, populate_by_name=True, protected_namespaces=()
+47 -2
View File
@@ -1,5 +1,6 @@
from urllib.parse import unquote, urlparse
from warnings import warn
from gql import gql
from specklepy.core.api.client import SpeckleClient
from specklepy.core.api.credentials import (
@@ -81,13 +82,25 @@ class StreamWrapper:
" provided."
)
# check for fe2 URL
if "/projects/" in parsed.path:
use_fe2 = True
else:
use_fe2 = False
while segments:
segment = segments.pop(0)
if segments and segment.lower() == "streams":
if segments and (
(use_fe2 is False and segment.lower() == "streams")
or (use_fe2 is True and segment.lower() == "projects")
):
self.stream_id = segments.pop(0)
elif segments and segment.lower() == "commits":
self.commit_id = segments.pop(0)
elif segments and segment.lower() == "branches":
elif segments and (
(use_fe2 is False and segment.lower() == "branches")
or (use_fe2 is True and segment.lower() == "models")
):
self.branch_name = unquote(segments.pop(0))
elif segments and segment.lower() == "objects":
self.object_id = segments.pop(0)
@@ -101,6 +114,38 @@ class StreamWrapper:
" provided."
)
if use_fe2 is True and self.branch_name is not None:
if "," in self.branch_name:
raise SpeckleException("Multi-model urls are not supported yet")
if "@" in self.branch_name:
model_id = self.branch_name.split("@")[0]
self.commit_id = self.branch_name.split("@")[1]
else:
model_id = self.branch_name
# get branch name
query = gql(
"""
query Project($project_id: String!, $model_id: String!) {
project(id: $project_id) {
id
model(id: $model_id) {
name
}
}
}
"""
)
self._client = self.get_client()
params = {"project_id": self.stream_id, "model_id": model_id}
project = self._client.httpclient.execute(query, params)
try:
self.branch_name = project["project"]["model"]["name"]
except KeyError as ke:
raise SpeckleException("Project model name is not found", ke)
if not self.stream_id:
raise SpeckleException(
f"Cannot parse {url} into a stream wrapper class - no stream id found."
+13 -1
View File
@@ -1,7 +1,7 @@
from typing import Any, List, Optional
from deprecated import deprecated
from specklepy.objects.geometry import Point, Vector
from specklepy.objects.geometry import Point, Vector, Plane, Polyline
from .base import Base
@@ -71,6 +71,18 @@ class DisplayStyle(Base, speckle_type=OTHER + "DisplayStyle"):
lineweight: float = 0
class Text(Base, speckle_type=OTHER + "Text"):
"""
Text object to render it on viewer.
"""
plane: Plane
value: str
height: float
rotation: float
displayValue: Optional[List[Polyline]] = None
richText: Optional[str] = None
class Transform(
Base,
speckle_type=OTHER + "Transform",
@@ -79,7 +79,7 @@ def automation_run_data(
automation_run_id = crypto_random_string(10)
function_id = crypto_random_string(10)
function_release = crypto_random_string(10)
function_name = f"automate test {crypto_random_string(3)}"
return AutomationRunData(
project_id=project_id,
model_id=model_id,
@@ -90,8 +90,8 @@ def automation_run_data(
automation_revision_id=automation_revision_id,
automation_run_id=automation_run_id,
function_id=function_id,
function_release=function_release,
function_name="foobar",
function_name=function_name,
function_logo=None,
)
@@ -235,17 +235,51 @@ def test_create_version_in_project_raises_error_for_same_model(
) -> None:
with pytest.raises(ValueError):
automation_context.create_new_version_in_project(
Base(), automation_context.automation_run_data.model_id
Base(), automation_context.automation_run_data.branch_name
)
def test_create_version_in_project(
automation_context: AutomationContext,
) -> None:
model_id = automation_context.speckle_client.branch.create(
automation_context.automation_run_data.project_id, "foobar"
)
root_object = Base()
root_object.foo = "bar"
version_id = automation_context.create_new_version_in_project(root_object, model_id)
model_id, version_id = automation_context.create_new_version_in_project(
root_object, "foobar"
)
assert model_id is not None
assert version_id is not None
def test_set_context_view(automation_context: AutomationContext) -> None:
automation_context.set_context_view()
assert automation_context.context_view is not None
assert automation_context.context_view.endswith(
f"models/{automation_context.automation_run_data.model_id}@{automation_context.automation_run_data.version_id}"
)
automation_context.report_run_status()
automation_context._automation_result.result_view = None
dummy_context = "foo@bar"
automation_context.set_context_view([dummy_context])
assert automation_context.context_view is not None
assert automation_context.context_view.endswith(
f"models/{automation_context.automation_run_data.model_id}@{automation_context.automation_run_data.version_id},{dummy_context}"
)
automation_context.report_run_status()
automation_context._automation_result.result_view = None
dummy_context = "foo@baz"
automation_context.set_context_view(
[dummy_context], include_source_model_version=False
)
assert automation_context.context_view is not None
assert automation_context.context_view.endswith(f"models/{dummy_context}")
automation_context.report_run_status()
+21
View File
@@ -126,3 +126,24 @@ def test_wrapper_url_match(user_path) -> None:
account = wrap.get_account()
assert account.userInfo.email is None
def test_parse_project():
wrap = StreamWrapper("https://latest.speckle.systems/projects/843d07eb10")
assert wrap.type == "stream"
def test_parse_model():
wrap = StreamWrapper(
"https://latest.speckle.systems/projects/843d07eb10/models/d9eb4918c8"
)
assert wrap.branch_name == "building wrapper"
assert wrap.type == "branch"
def test_parse_version():
wrap = StreamWrapper(
"https://latest.speckle.systems/projects/843d07eb10/models/4e7345c838@c42d5cbac1"
)
assert wrap.type == "commit"