Compare commits

...

18 Commits

Author SHA1 Message Date
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
6 changed files with 155 additions and 9 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:
+33 -4
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
@@ -111,7 +111,7 @@ class AutomationContext:
def create_new_version_in_project(
self, root_object: Base, model_name: str, version_message: str = ""
) -> str:
) -> Tuple[str, str]:
"""Save a base model to a new version on the project.
Args:
@@ -137,9 +137,11 @@ class AutomationContext:
self.automation_run_data.project_id,
model_name,
)
print(branch_create)
if isinstance(branch_create, Exception):
raise branch_create
model_id = branch_create
else:
model_id = branch.id
root_object_id = operations.send(
root_object,
@@ -159,7 +161,31 @@ class AutomationContext:
raise version_id
self._automation_result.result_versions.append(version_id)
return version_id
return model_id, version_id
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.append(*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)}"
)
def report_run_status(self) -> None:
"""Report the current run status to the project of this automation."""
@@ -175,6 +201,7 @@ class AutomationContext:
$functionLogo: String,
$runStatus: AutomationRunStatus!
$elapsed: Float!
$contextView: String
$resultVersionIds: [String!]!
$statusMessage: String
$objectResults: JSONObject
@@ -191,6 +218,7 @@ class AutomationContext:
functionName: $functionName
functionLogo: $functionLogo
status: $runStatus,
contextView: $contextView,
elapsed: $elapsed,
resultVersionIds: $resultVersionIds,
statusMessage: $statusMessage
@@ -224,6 +252,7 @@ class AutomationContext:
"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,
+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",
@@ -244,5 +244,44 @@ def test_create_version_in_project(
) -> None:
root_object = Base()
root_object.foo = "bar"
version_id = automation_context.create_new_version_in_project(root_object, "foobar")
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._automation_result.result_view is not None
assert automation_context._automation_result.result_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._automation_result.result_view is not None
assert automation_context._automation_result.result_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._automation_result.result_view is not None
assert automation_context._automation_result.result_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"