Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ae6fc85ab4 | |||
| 7ad0785c62 | |||
| 76e4ec1535 | |||
| 4e96aade51 | |||
| 7ca00b7b77 | |||
| bddf9c0c1c | |||
| bf3ab7da4c | |||
| 4dc148181e | |||
| 357859288d | |||
| 1ce61bdda8 | |||
| 42737c4ed2 | |||
| 62ee1a4b0a | |||
| d21373873c | |||
| e3716f6206 | |||
| f6917b0761 | |||
| 04764b17eb | |||
| dbe3d759f6 | |||
| f6ff484e66 | |||
| bd000395af | |||
| 10f49579fd | |||
| 1693465dfc | |||
| c3a7ead8f5 | |||
| d151a8d0ae | |||
| c0dd88cbdb | |||
| 71d3589e72 | |||
| 5bde1bc2d6 | |||
| 75e6f0229a | |||
| 5d7e71f357 | |||
| 6c223b6fb3 | |||
| e6131a7956 | |||
| 45b50e4f26 | |||
| d9b92490ec | |||
| 37c09fa56c | |||
| cbae4d300d | |||
| 2742c12e31 | |||
| 6dd0813089 | |||
| a1831b57db | |||
| 1ff3245531 | |||
| 3b4723a186 | |||
| efe9551c5e | |||
| 23a5087fbc |
+40
-2
@@ -1,10 +1,43 @@
|
||||
version: 2.1
|
||||
|
||||
orbs:
|
||||
python: circleci/python@2.0.3
|
||||
codecov: codecov/codecov@3.2.2
|
||||
codecov: codecov/codecov@3.3.0
|
||||
|
||||
jobs:
|
||||
pre-commit:
|
||||
parameters:
|
||||
config_file:
|
||||
default: ./.pre-commit-config.yaml
|
||||
description: Optional, path to pre-commit config file.
|
||||
type: string
|
||||
cache_prefix:
|
||||
default: ''
|
||||
description: |
|
||||
Optional cache prefix to be used on CircleCI. Can be used for cache busting or to ensure multiple jobs use different caches.
|
||||
type: string
|
||||
docker:
|
||||
- image: speckle/pre-commit-runner:latest
|
||||
resource_class: medium
|
||||
steps:
|
||||
- checkout
|
||||
- restore_cache:
|
||||
keys:
|
||||
- cache-pre-commit-<<parameters.cache_prefix>>-{{ checksum "<<parameters.config_file>>" }}
|
||||
- run:
|
||||
name: Install pre-commit hooks
|
||||
command: pre-commit install-hooks --config <<parameters.config_file>>
|
||||
- save_cache:
|
||||
key: cache-pre-commit-<<parameters.cache_prefix>>-{{ checksum "<<parameters.config_file>>" }}
|
||||
paths:
|
||||
- ~/.cache/pre-commit
|
||||
- run:
|
||||
name: Run pre-commit
|
||||
command: pre-commit run --all-files
|
||||
- run:
|
||||
command: git --no-pager diff
|
||||
name: git diff
|
||||
when: on_fail
|
||||
|
||||
test:
|
||||
machine:
|
||||
image: ubuntu-2204:2023.02.1
|
||||
@@ -52,6 +85,10 @@ jobs:
|
||||
workflows:
|
||||
main:
|
||||
jobs:
|
||||
- pre-commit:
|
||||
filters:
|
||||
tags:
|
||||
only: /.*/
|
||||
- test:
|
||||
matrix:
|
||||
parameters:
|
||||
@@ -62,6 +99,7 @@ workflows:
|
||||
- deploy:
|
||||
context: pypi
|
||||
requires:
|
||||
- pre-commit
|
||||
- test
|
||||
filters:
|
||||
tags:
|
||||
|
||||
@@ -2,7 +2,7 @@ repos:
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
hooks:
|
||||
- id: ruff
|
||||
rev: v0.0.186
|
||||
rev: v0.1.6
|
||||
|
||||
- repo: https://github.com/commitizen-tools/commitizen
|
||||
hooks:
|
||||
@@ -10,15 +10,15 @@ repos:
|
||||
- id: commitizen-branch
|
||||
stages:
|
||||
- push
|
||||
rev: v2.38.0
|
||||
rev: 3.12.0
|
||||
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: v5.11.3
|
||||
rev: 5.12.0
|
||||
hooks:
|
||||
- id: isort
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.12.0
|
||||
rev: 23.11.0
|
||||
hooks:
|
||||
- id: black
|
||||
# It is recommended to specify the latest version of Python
|
||||
@@ -27,7 +27,7 @@ repos:
|
||||
# https://pre-commit.com/#top_level-default_language_version
|
||||
# language_version: python3.11
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
rev: v4.5.0
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
|
||||
+1
-1
@@ -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
@@ -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>"]
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
"""This module provides an abstraction layer above the Speckle Automate runtime."""
|
||||
import time
|
||||
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
|
||||
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,
|
||||
@@ -22,6 +15,12 @@ from speckle_automate.schema import (
|
||||
ObjectResultLevel,
|
||||
ResultCase,
|
||||
)
|
||||
from specklepy.api import operations
|
||||
from specklepy.api.client import SpeckleClient
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.objects import Base
|
||||
from specklepy.transports.memory import MemoryTransport
|
||||
from specklepy.transports.server import ServerTransport
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -91,7 +90,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 +109,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 +119,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 +151,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,56 +160,51 @@ 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."""
|
||||
query = gql(
|
||||
"""
|
||||
mutation ReportFunctionRunStatus(
|
||||
$automationId: String!,
|
||||
$automationRevisionId: String!,
|
||||
$automationId: String!,
|
||||
$automationRevisionId: String!,
|
||||
$automationRunId: String!,
|
||||
$versionId: String!,
|
||||
$functionId: String!,
|
||||
$functionName: String!,
|
||||
$functionLogo: String,
|
||||
$runStatus: AutomationRunStatus!
|
||||
$elapsed: Float!
|
||||
$contextView: String
|
||||
$resultVersionIds: [String!]!
|
||||
$statusMessage: String
|
||||
$objectResults: JSONObject
|
||||
@@ -211,7 +218,10 @@ class AutomationContext:
|
||||
functionRuns: [
|
||||
{
|
||||
functionId: $functionId
|
||||
functionName: $functionName
|
||||
functionLogo: $functionLogo
|
||||
status: $runStatus,
|
||||
contextView: $contextView,
|
||||
elapsed: $elapsed,
|
||||
resultVersionIds: $resultVersionIds,
|
||||
statusMessage: $statusMessage
|
||||
@@ -241,12 +251,16 @@ 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,
|
||||
}
|
||||
print(f"Reporting run status with content: {params}")
|
||||
self.speckle_client.httpclient.execute(query, params)
|
||||
|
||||
def store_file_result(self, file_path: Union[Path, str]) -> None:
|
||||
@@ -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,9 +2,10 @@
|
||||
import secrets
|
||||
import string
|
||||
|
||||
from specklepy.api.client import SpeckleClient
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.client import SpeckleClient
|
||||
|
||||
|
||||
def register_new_automation(
|
||||
speckle_client: SpeckleClient,
|
||||
@@ -18,10 +19,10 @@ def register_new_automation(
|
||||
query = gql(
|
||||
"""
|
||||
mutation CreateAutomation(
|
||||
$projectId: String!
|
||||
$modelId: String!
|
||||
$projectId: String!
|
||||
$modelId: String!
|
||||
$automationName: String!
|
||||
$automationId: String!
|
||||
$automationId: String!
|
||||
$automationRevisionId: String!
|
||||
) {
|
||||
automationMutations {
|
||||
@@ -29,7 +30,7 @@ def register_new_automation(
|
||||
input: {
|
||||
projectId: $projectId
|
||||
modelId: $modelId
|
||||
automationName: $automationName
|
||||
automationName: $automationName
|
||||
automationId: $automationId
|
||||
automationRevisionId: $automationRevisionId
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ from pathlib import Path
|
||||
from typing import Callable, Optional, TypeVar, Union, overload
|
||||
|
||||
from speckle_automate.automation_context import AutomationContext
|
||||
from speckle_automate.schema import AutomateBase, AutomationRunData, AutomationStatus
|
||||
from speckle_automate.schema import AutomateBase, AutomationStatus
|
||||
|
||||
T = TypeVar("T", bound=AutomateBase)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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=()
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
from deprecated import deprecated
|
||||
from gql.transport.exceptions import TransportServerError
|
||||
from gql.transport.requests import RequestsHTTPTransport
|
||||
from gql.transport.websockets import WebsocketsTransport
|
||||
|
||||
from specklepy.api.credentials import Account, get_account_from_token
|
||||
from specklepy.api.credentials import Account
|
||||
from specklepy.api.resources import (
|
||||
user,
|
||||
active_user,
|
||||
branch,
|
||||
commit,
|
||||
@@ -14,11 +10,10 @@ from specklepy.api.resources import (
|
||||
server,
|
||||
stream,
|
||||
subscriptions,
|
||||
user,
|
||||
)
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException, SpeckleWarning
|
||||
|
||||
from specklepy.core.api.client import SpeckleClient as CoreSpeckleClient
|
||||
from specklepy.logging import metrics
|
||||
|
||||
|
||||
class SpeckleClient(CoreSpeckleClient):
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
import os
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field # pylint: disable=no-name-in-module
|
||||
|
||||
from specklepy.api.models import ServerInfo
|
||||
from specklepy.core.helpers import speckle_path_provider
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.transports.sqlite import SQLiteTransport
|
||||
|
||||
# following imports seem to be unnecessary, but they need to stay
|
||||
# to not break the scripts using these functions as non-core
|
||||
from specklepy.core.api.credentials import StreamWrapper # noqa: F401
|
||||
from specklepy.core.api.credentials import Account, UserInfo # noqa: F401
|
||||
from specklepy.core.api.credentials import (
|
||||
Account,
|
||||
UserInfo,
|
||||
StreamWrapper, # deprecated
|
||||
get_local_accounts as core_get_local_accounts,
|
||||
get_account_from_token as core_get_account_from_token,
|
||||
)
|
||||
from specklepy.core.api.credentials import get_local_accounts as core_get_local_accounts
|
||||
from specklepy.logging import metrics
|
||||
|
||||
|
||||
def get_local_accounts(base_path: Optional[str] = None) -> List[Account]:
|
||||
|
||||
@@ -1,18 +1,74 @@
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from unicodedata import name
|
||||
from specklepy.core.api.host_applications import (
|
||||
ARCGIS,
|
||||
ARCHICAD,
|
||||
AUTOCAD,
|
||||
BLENDER,
|
||||
CIVIL,
|
||||
CSIBRIDGE,
|
||||
DXF,
|
||||
DYNAMO,
|
||||
ETABS,
|
||||
EXCEL,
|
||||
GRASSHOPPER,
|
||||
GSA,
|
||||
MICROSTATION,
|
||||
NET,
|
||||
OPENBUILDINGS,
|
||||
OPENRAIL,
|
||||
OPENROADS,
|
||||
OTHER,
|
||||
POWERBI,
|
||||
PYTHON,
|
||||
QGIS,
|
||||
REVIT,
|
||||
RHINO,
|
||||
SAFE,
|
||||
SAP2000,
|
||||
SKETCHUP,
|
||||
TEKLASTRUCTURES,
|
||||
TOPSOLID,
|
||||
UNITY,
|
||||
UNREAL,
|
||||
HostApplication,
|
||||
HostAppVersion,
|
||||
_app_name_host_app_mapping,
|
||||
get_host_app_from_string,
|
||||
)
|
||||
|
||||
# following imports seem to be unnecessary, but they need to stay
|
||||
# to not break the scripts using these functions as non-core
|
||||
from specklepy.core.api.host_applications import (HostApplication, HostAppVersion,
|
||||
get_host_app_from_string,
|
||||
_app_name_host_app_mapping,
|
||||
RHINO,GRASSHOPPER,REVIT,DYNAMO,UNITY,GSA,
|
||||
CIVIL,AUTOCAD,MICROSTATION,OPENROADS,
|
||||
OPENRAIL,OPENBUILDINGS,ETABS,SAP2000,CSIBRIDGE,
|
||||
SAFE,TEKLASTRUCTURES,DXF,EXCEL,UNREAL,POWERBI,
|
||||
BLENDER,QGIS,ARCGIS,SKETCHUP,ARCHICAD,TOPSOLID,
|
||||
PYTHON,NET,OTHER)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(HostAppVersion.v)
|
||||
# re-exporting stuff from the moved api module
|
||||
__all__ = [
|
||||
"ARCGIS",
|
||||
"ARCHICAD",
|
||||
"AUTOCAD",
|
||||
"BLENDER",
|
||||
"CIVIL",
|
||||
"CSIBRIDGE",
|
||||
"DXF",
|
||||
"DYNAMO",
|
||||
"ETABS",
|
||||
"EXCEL",
|
||||
"GRASSHOPPER",
|
||||
"GSA",
|
||||
"MICROSTATION",
|
||||
"NET",
|
||||
"OPENBUILDINGS",
|
||||
"OPENRAIL",
|
||||
"OPENROADS",
|
||||
"OTHER",
|
||||
"POWERBI",
|
||||
"PYTHON",
|
||||
"QGIS",
|
||||
"REVIT",
|
||||
"RHINO",
|
||||
"SAFE",
|
||||
"SAP2000",
|
||||
"SKETCHUP",
|
||||
"TEKLASTRUCTURES",
|
||||
"TOPSOLID",
|
||||
"UNITY",
|
||||
"UNREAL",
|
||||
"HostApplication",
|
||||
"HostAppVersion",
|
||||
"_app_name_host_app_mapping",
|
||||
"get_host_app_from_string",
|
||||
]
|
||||
|
||||
+34
-11
@@ -1,12 +1,35 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
# following imports seem to be unnecessary, but they need to stay
|
||||
# following imports seem to be unnecessary, but they need to stay
|
||||
# to not break the scripts using these functions as non-core
|
||||
from specklepy.core.api.models import (Collaborator, Commit,
|
||||
Commits, Object, Branch, Branches,
|
||||
Stream, Streams, User, LimitedUser,
|
||||
PendingStreamCollaborator, Activity,
|
||||
ActivityCollection, ServerInfo)
|
||||
from specklepy.core.api.models import (
|
||||
Activity,
|
||||
ActivityCollection,
|
||||
Branch,
|
||||
Branches,
|
||||
Collaborator,
|
||||
Commit,
|
||||
Commits,
|
||||
LimitedUser,
|
||||
Object,
|
||||
PendingStreamCollaborator,
|
||||
ServerInfo,
|
||||
Stream,
|
||||
Streams,
|
||||
User,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Activity",
|
||||
"ActivityCollection",
|
||||
"Branch",
|
||||
"Branches",
|
||||
"Collaborator",
|
||||
"Commit",
|
||||
"Commits",
|
||||
"LimitedUser",
|
||||
"Object",
|
||||
"PendingStreamCollaborator",
|
||||
"ServerInfo",
|
||||
"Stream",
|
||||
"Streams",
|
||||
"User",
|
||||
]
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from specklepy.core.api.operations import deserialize as core_deserialize
|
||||
from specklepy.core.api.operations import receive as _untracked_receive
|
||||
from specklepy.core.api.operations import send as core_send
|
||||
from specklepy.core.api.operations import serialize as core_serialize
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
|
||||
from specklepy.transports.abstract_transport import AbstractTransport
|
||||
from specklepy.transports.sqlite import SQLiteTransport
|
||||
|
||||
from specklepy.core.api.operations import (send as core_send,
|
||||
receive as _untracked_receive,
|
||||
serialize as core_serialize,
|
||||
deserialize as core_deserialize)
|
||||
|
||||
|
||||
def send(
|
||||
@@ -74,6 +70,7 @@ def serialize(base: Base, write_transports: List[AbstractTransport] = []) -> str
|
||||
metrics.track(metrics.SDK, custom_props={"name": "Serialize"})
|
||||
return core_serialize(base, write_transports)
|
||||
|
||||
|
||||
def deserialize(
|
||||
obj_string: str, read_transport: Optional[AbstractTransport] = None
|
||||
) -> Base:
|
||||
|
||||
@@ -1,21 +1,8 @@
|
||||
from threading import Lock
|
||||
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||
from typing import Any, Optional, Tuple
|
||||
|
||||
from gql.client import Client
|
||||
from gql.transport.exceptions import TransportQueryError
|
||||
from graphql import DocumentNode
|
||||
|
||||
from specklepy.api.credentials import Account
|
||||
from specklepy.logging.exceptions import (
|
||||
GraphQLException,
|
||||
SpeckleException,
|
||||
UnsupportedException,
|
||||
)
|
||||
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
|
||||
from specklepy.transports.sqlite import SQLiteTransport
|
||||
|
||||
# following imports seem to be unnecessary, but they need to stay
|
||||
# to not break the scripts using these functions as non-core
|
||||
from specklepy.core.api.resource import ResourceBase as CoreResourceBase
|
||||
|
||||
|
||||
@@ -29,10 +16,9 @@ class ResourceBase(CoreResourceBase):
|
||||
server_version: Optional[Tuple[Any, ...]] = None,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
account = account,
|
||||
basepath = basepath,
|
||||
client = client,
|
||||
name = name,
|
||||
server_version = server_version
|
||||
account=account,
|
||||
basepath=basepath,
|
||||
client=client,
|
||||
name=name,
|
||||
server_version=server_version,
|
||||
)
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.models import ActivityCollection, PendingStreamCollaborator, User
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
from specklepy.api.models import PendingStreamCollaborator, User
|
||||
from specklepy.core.api.resources.active_user import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
|
||||
|
||||
class Resource(CoreResource):
|
||||
@@ -97,7 +92,9 @@ class Resource(CoreResource):
|
||||
List[PendingStreamCollaborator]
|
||||
-- a list of pending invites for the current user
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "User Active Invites All Get"})
|
||||
metrics.track(
|
||||
metrics.SDK, self.account, {"name": "User Active Invites All Get"}
|
||||
)
|
||||
return super().get_all_pending_invites()
|
||||
|
||||
def get_pending_invite(
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
from typing import Optional
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.models import Branch
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.logging import metrics
|
||||
|
||||
from specklepy.core.api.resources.branch import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
|
||||
|
||||
class Resource(CoreResource):
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.models import Commit
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.logging import metrics
|
||||
|
||||
from specklepy.core.api.resources.commit import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
from typing import Dict, List
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.objects.base import Base
|
||||
|
||||
from specklepy.logging import metrics
|
||||
|
||||
from specklepy.core.api.resources.object import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.objects.base import Base
|
||||
|
||||
|
||||
class Resource(CoreResource):
|
||||
@@ -58,4 +53,3 @@ class Resource(CoreResource):
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Object Create"})
|
||||
return super().create(stream_id, objects)
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.models import ActivityCollection, LimitedUser
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.core.api.resources.other_user import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
from specklepy.core.api.resources.other_user import Resource as CoreResource
|
||||
|
||||
|
||||
class Resource(CoreResource):
|
||||
"""API Access class for other users, that are not the currently active user."""
|
||||
@@ -54,7 +50,7 @@ class Resource(CoreResource):
|
||||
)
|
||||
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Other User Search"})
|
||||
return super().search(search_query, limit)
|
||||
return super().search(search_query, limit)
|
||||
|
||||
def activity(
|
||||
self,
|
||||
@@ -83,5 +79,4 @@ class Resource(CoreResource):
|
||||
cursor {datetime} -- timestamp cursor for pagination
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Other User Activity"})
|
||||
return super().activity(user_id, limit, action_type, before, after, cursor)
|
||||
|
||||
return super().activity(user_id, limit, action_type, before, after, cursor)
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import re
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.models import ServerInfo
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import GraphQLException
|
||||
|
||||
from specklepy.core.api.resources.server import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
|
||||
|
||||
class Resource(CoreResource):
|
||||
@@ -73,4 +67,4 @@ class Resource(CoreResource):
|
||||
bool -- True if the token was successfully deleted
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Server Revoke Token"})
|
||||
return super().revoke_token(token)
|
||||
return super().revoke_token(token)
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from deprecated import deprecated
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.models import ActivityCollection, PendingStreamCollaborator, Stream
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException, UnsupportedException
|
||||
|
||||
from specklepy.api.models import PendingStreamCollaborator, Stream
|
||||
from specklepy.core.api.resources.stream import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
|
||||
|
||||
class Resource(CoreResource):
|
||||
@@ -256,7 +250,11 @@ class Resource(CoreResource):
|
||||
Returns:
|
||||
bool -- True if the operation was successful
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Stream Permission Update", "role": role})
|
||||
metrics.track(
|
||||
metrics.SDK,
|
||||
self.account,
|
||||
{"name": "Stream Permission Update", "role": role},
|
||||
)
|
||||
return super().update_permission(stream_id, user_id, role)
|
||||
|
||||
def revoke_permission(self, stream_id: str, user_id: str):
|
||||
@@ -301,4 +299,3 @@ class Resource(CoreResource):
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Stream Activity"})
|
||||
return super().activity(stream_id, action_type, limit, before, after, cursor)
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
from functools import wraps
|
||||
from typing import Callable, Dict, List, Optional, Union
|
||||
|
||||
from gql import gql
|
||||
from graphql import DocumentNode
|
||||
|
||||
from specklepy.api.resource import ResourceBase
|
||||
from specklepy.api.resources.stream import Stream
|
||||
from specklepy.core.api.resources.subscriptions import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.core.api.resources.subscriptions import Resource as CoreResource
|
||||
|
||||
def check_wsclient(function):
|
||||
@wraps(function)
|
||||
@@ -64,7 +61,9 @@ class Resource(CoreResource):
|
||||
Returns:
|
||||
Stream -- the update stream
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Subscription Stream Updated"})
|
||||
metrics.track(
|
||||
metrics.SDK, self.account, {"name": "Subscription Stream Updated"}
|
||||
)
|
||||
return super().stream_updated(id, callback)
|
||||
|
||||
@check_wsclient
|
||||
@@ -83,7 +82,9 @@ class Resource(CoreResource):
|
||||
Returns:
|
||||
dict -- dict containing 'id' of stream removed and optionally 'revokedBy'
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "Subscription Stream Removed"})
|
||||
metrics.track(
|
||||
metrics.SDK, self.account, {"name": "Subscription Stream Removed"}
|
||||
)
|
||||
return super().stream_removed(callback)
|
||||
|
||||
@check_wsclient
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from deprecated import deprecated
|
||||
from gql import gql
|
||||
|
||||
from specklepy.api.models import ActivityCollection, PendingStreamCollaborator, User
|
||||
from specklepy.api.resource import ResourceBase
|
||||
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.api.models import PendingStreamCollaborator, User
|
||||
from specklepy.core.api.resources.user import Resource as CoreResource
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
DEPRECATION_VERSION = "2.9.0"
|
||||
DEPRECATION_TEXT = (
|
||||
@@ -46,7 +42,7 @@ class Resource(CoreResource):
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "User Get_deprecated"})
|
||||
return super().get(id)
|
||||
|
||||
|
||||
@deprecated(version=DEPRECATION_VERSION, reason=DEPRECATION_TEXT)
|
||||
def search(
|
||||
self, search_query: str, limit: int = 25
|
||||
@@ -83,7 +79,7 @@ class Resource(CoreResource):
|
||||
Returns:
|
||||
bool -- True if your profile was updated successfully
|
||||
"""
|
||||
#metrics.track(metrics.USER, self.account, {"name": "update"})
|
||||
# metrics.track(metrics.USER, self.account, {"name": "update"})
|
||||
metrics.track(metrics.SDK, self.account, {"name": "User Update_deprecated"})
|
||||
return super().update(name, company, bio, avatar)
|
||||
|
||||
@@ -118,7 +114,6 @@ class Resource(CoreResource):
|
||||
"""
|
||||
metrics.track(metrics.SDK, self.account, {"name": "User Activity_deprecated"})
|
||||
return super().activity(user_id, limit, action_type, before, after, cursor)
|
||||
|
||||
|
||||
@deprecated(version=DEPRECATION_VERSION, reason=DEPRECATION_TEXT)
|
||||
def get_all_pending_invites(self) -> List[PendingStreamCollaborator]:
|
||||
@@ -130,10 +125,11 @@ class Resource(CoreResource):
|
||||
List[PendingStreamCollaborator]
|
||||
-- a list of pending invites for the current user
|
||||
"""
|
||||
#metrics.track(metrics.INVITE, self.account, {"name": "get"})
|
||||
metrics.track(metrics.SDK, self.account, {"name": "User GetAllInvites_deprecated"})
|
||||
# metrics.track(metrics.INVITE, self.account, {"name": "get"})
|
||||
metrics.track(
|
||||
metrics.SDK, self.account, {"name": "User GetAllInvites_deprecated"}
|
||||
)
|
||||
return super().get_all_pending_invites()
|
||||
|
||||
|
||||
@deprecated(version=DEPRECATION_VERSION, reason=DEPRECATION_TEXT)
|
||||
def get_pending_invite(
|
||||
@@ -152,7 +148,6 @@ class Resource(CoreResource):
|
||||
PendingStreamCollaborator
|
||||
-- the invite for the given stream (or None if it isn't found)
|
||||
"""
|
||||
#metrics.track(metrics.INVITE, self.account, {"name": "get"})
|
||||
# metrics.track(metrics.INVITE, self.account, {"name": "get"})
|
||||
metrics.track(metrics.SDK, self.account, {"name": "User GetInvite_deprecated"})
|
||||
return super().get_pending_invite(stream_id, token)
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
from urllib.parse import unquote, urlparse
|
||||
from warnings import warn
|
||||
|
||||
from specklepy.api.client import SpeckleClient
|
||||
from specklepy.api.credentials import (
|
||||
Account,
|
||||
get_account_from_token,
|
||||
get_local_accounts,
|
||||
)
|
||||
from specklepy.logging.exceptions import SpeckleException, SpeckleWarning
|
||||
from specklepy.api.credentials import Account
|
||||
from specklepy.core.api.wrapper import StreamWrapper as CoreStreamWrapper
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.transports.server.server import ServerTransport
|
||||
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.core.api.wrapper import StreamWrapper as CoreStreamWrapper
|
||||
|
||||
class StreamWrapper(CoreStreamWrapper):
|
||||
"""
|
||||
@@ -51,7 +43,7 @@ class StreamWrapper(CoreStreamWrapper):
|
||||
_account: Account = None
|
||||
|
||||
def __init__(self, url: str) -> None:
|
||||
super().__init__(url = url)
|
||||
super().__init__(url=url)
|
||||
|
||||
def get_account(self, token: str = None) -> Account:
|
||||
"""
|
||||
@@ -90,5 +82,7 @@ class StreamWrapper(CoreStreamWrapper):
|
||||
ServerTransport -- constructed for this stream
|
||||
with a pre-authenticated client
|
||||
"""
|
||||
metrics.track(metrics.SDK, custom_props={"name": "Stream Wrapper Get Transport"})
|
||||
metrics.track(
|
||||
metrics.SDK, custom_props={"name": "Stream Wrapper Get Transport"}
|
||||
)
|
||||
return super().get_transport(token)
|
||||
|
||||
@@ -11,7 +11,6 @@ from gql.transport.websockets import WebsocketsTransport
|
||||
from specklepy.core.api import resources
|
||||
from specklepy.core.api.credentials import Account, get_account_from_token
|
||||
from specklepy.core.api.resources import (
|
||||
user,
|
||||
active_user,
|
||||
branch,
|
||||
commit,
|
||||
@@ -20,6 +19,7 @@ from specklepy.core.api.resources import (
|
||||
server,
|
||||
stream,
|
||||
subscriptions,
|
||||
user,
|
||||
)
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException, SpeckleWarning
|
||||
@@ -58,8 +58,14 @@ class SpeckleClient:
|
||||
|
||||
DEFAULT_HOST = "speckle.xyz"
|
||||
USE_SSL = True
|
||||
VERIFY_CERTIFICATE = True
|
||||
|
||||
def __init__(self, host: str = DEFAULT_HOST, use_ssl: bool = USE_SSL) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
host: str = DEFAULT_HOST,
|
||||
use_ssl: bool = USE_SSL,
|
||||
verify_certificate: bool = VERIFY_CERTIFICATE,
|
||||
) -> None:
|
||||
ws_protocol = "ws"
|
||||
http_protocol = "http"
|
||||
|
||||
@@ -74,9 +80,12 @@ class SpeckleClient:
|
||||
self.graphql = f"{self.url}/graphql"
|
||||
self.ws_url = f"{ws_protocol}://{host}/graphql"
|
||||
self.account = Account()
|
||||
self.verify_certificate = verify_certificate
|
||||
|
||||
self.httpclient = Client(
|
||||
transport=RequestsHTTPTransport(url=self.graphql, verify=True, retries=3)
|
||||
transport=RequestsHTTPTransport(
|
||||
url=self.graphql, verify=self.verify_certificate, retries=3
|
||||
)
|
||||
)
|
||||
self.wsclient = None
|
||||
|
||||
@@ -150,7 +159,7 @@ class SpeckleClient:
|
||||
"apollographql-client-version": metrics.HOST_APP_VERSION,
|
||||
}
|
||||
httptransport = RequestsHTTPTransport(
|
||||
url=self.graphql, headers=headers, verify=True, retries=3
|
||||
url=self.graphql, headers=headers, verify=self.verify_certificate, retries=3
|
||||
)
|
||||
wstransport = WebsocketsTransport(
|
||||
url=self.ws_url,
|
||||
|
||||
@@ -6,7 +6,6 @@ from pydantic import BaseModel, Field # pylint: disable=no-name-in-module
|
||||
|
||||
from specklepy.core.api.models import ServerInfo
|
||||
from specklepy.core.helpers import speckle_path_provider
|
||||
from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.transports.sqlite import SQLiteTransport
|
||||
|
||||
@@ -110,7 +109,7 @@ def get_default_account(base_path: Optional[str] = None) -> Optional[Account]:
|
||||
if not default:
|
||||
default = accounts[0]
|
||||
default.isDefault = True
|
||||
#metrics.initialise_tracker(default)
|
||||
# metrics.initialise_tracker(default)
|
||||
|
||||
return default
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import List, Optional
|
||||
|
||||
#from specklepy.logging import metrics
|
||||
# from specklepy.logging import metrics
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
|
||||
|
||||
@@ -3,7 +3,11 @@ from typing import List, Optional
|
||||
|
||||
from gql import gql
|
||||
|
||||
from specklepy.core.api.models import ActivityCollection, PendingStreamCollaborator, User
|
||||
from specklepy.core.api.models import (
|
||||
ActivityCollection,
|
||||
PendingStreamCollaborator,
|
||||
User,
|
||||
)
|
||||
from specklepy.core.api.resource import ResourceBase
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import List, Optional
|
||||
|
||||
from deprecated import deprecated
|
||||
from gql import gql
|
||||
|
||||
from specklepy.core.api.models import ActivityCollection, PendingStreamCollaborator, Stream
|
||||
from specklepy.core.api.models import (
|
||||
ActivityCollection,
|
||||
PendingStreamCollaborator,
|
||||
Stream,
|
||||
)
|
||||
from specklepy.core.api.resource import ResourceBase
|
||||
from specklepy.logging.exceptions import SpeckleException, UnsupportedException
|
||||
|
||||
@@ -504,11 +507,10 @@ class Resource(ResourceBase):
|
||||
|
||||
user_invites = [
|
||||
{"streamId": stream_id, "message": message, "userId": user_id}
|
||||
for user_id in (user_ids if user_ids is not None else [])
|
||||
for user_id in (user_ids if user_ids is not None else [])
|
||||
if user_id is not None
|
||||
]
|
||||
|
||||
|
||||
params = {"input": [*email_invites, *user_invites]}
|
||||
|
||||
return self.make_request(
|
||||
|
||||
@@ -4,9 +4,12 @@ from typing import List, Optional, Union
|
||||
from deprecated import deprecated
|
||||
from gql import gql
|
||||
|
||||
from specklepy.core.api.models import ActivityCollection, PendingStreamCollaborator, User
|
||||
from specklepy.core.api.models import (
|
||||
ActivityCollection,
|
||||
PendingStreamCollaborator,
|
||||
User,
|
||||
)
|
||||
from specklepy.core.api.resource import ResourceBase
|
||||
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
NAME = "user"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
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 (
|
||||
Account,
|
||||
@@ -81,13 +83,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 +115,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."
|
||||
|
||||
@@ -28,7 +28,7 @@ CONNECTOR = "Connector Action"
|
||||
RECEIVE = "Receive"
|
||||
SEND = "Send"
|
||||
|
||||
# not in use since 2.15
|
||||
# not in use since 2.15
|
||||
ACCOUNTS = "Get Local Accounts"
|
||||
BRANCH = "Branch Action"
|
||||
CLIENT = "Speckle Client"
|
||||
@@ -142,7 +142,7 @@ class MetricsTracker(metaclass=Singleton):
|
||||
|
||||
def hash(self, value: str):
|
||||
inputList = value.lower().split("://")
|
||||
input = inputList[len(inputList)-1].split("/")[0].split('?')[0]
|
||||
input = inputList[len(inputList) - 1].split("/")[0].split("?")[0]
|
||||
return hashlib.md5(input.encode("utf-8")).hexdigest().upper()
|
||||
|
||||
def _send_tracking_requests(self):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from specklepy.objects import Base
|
||||
|
||||
|
||||
@@ -8,9 +9,7 @@ class CRS(Base, speckle_type="Objects.GIS.CRS"):
|
||||
name: Optional[str] = None
|
||||
authority_id: Optional[str] = None
|
||||
wkt: Optional[str] = None
|
||||
units_native: Optional[str] = None
|
||||
units_native: Optional[str] = None
|
||||
offset_x: Optional[float] = None
|
||||
offset_y: Optional[float] = None
|
||||
rotation: Optional[float] = None
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
"""Builtin Speckle object kit."""
|
||||
|
||||
from specklepy.objects.GIS.layers import (
|
||||
VectorLayer,
|
||||
RasterLayer,
|
||||
)
|
||||
|
||||
from specklepy.objects.GIS.CRS import CRS
|
||||
from specklepy.objects.GIS.geometry import (
|
||||
GisPolygonGeometry,
|
||||
GisPolygonElement,
|
||||
GisLineElement,
|
||||
GisPointElement,
|
||||
GisPolygonElement,
|
||||
GisPolygonGeometry,
|
||||
GisRasterElement,
|
||||
)
|
||||
from specklepy.objects.GIS.layers import RasterLayer, VectorLayer
|
||||
|
||||
from specklepy.objects.GIS.CRS import (
|
||||
CRS,
|
||||
)
|
||||
|
||||
__all__ = ["VectorLayer", "RasterLayer",
|
||||
"GisPolygonGeometry", "GisPolygonElement", "GisLineElement", "GisPointElement", "GisRasterElement",
|
||||
"CRS"]
|
||||
__all__ = [
|
||||
"VectorLayer",
|
||||
"RasterLayer",
|
||||
"GisPolygonGeometry",
|
||||
"GisPolygonElement",
|
||||
"GisLineElement",
|
||||
"GisPointElement",
|
||||
"GisRasterElement",
|
||||
"CRS",
|
||||
]
|
||||
|
||||
@@ -1,35 +1,51 @@
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from typing import Optional, Union, List
|
||||
from specklepy.objects.geometry import Point, Line, Polyline, Circle, Arc, Polycurve, Mesh
|
||||
from specklepy.objects import Base
|
||||
from deprecated import deprecated
|
||||
from specklepy.objects.geometry import (
|
||||
Arc,
|
||||
Circle,
|
||||
Line,
|
||||
Mesh,
|
||||
Point,
|
||||
Polycurve,
|
||||
Polyline,
|
||||
)
|
||||
|
||||
class GisPolygonGeometry(Base, speckle_type="Objects.GIS.PolygonGeometry", detachable={"displayValue"}):
|
||||
|
||||
class GisPolygonGeometry(
|
||||
Base, speckle_type="Objects.GIS.PolygonGeometry", detachable={"displayValue"}
|
||||
):
|
||||
"""GIS Polygon Geometry"""
|
||||
|
||||
boundary: Optional[Union[Polyline, Arc, Line, Circle, Polycurve]] = None
|
||||
voids: Optional[List[Union[Polyline, Arc, Line, Circle, Polycurve]] ] = None
|
||||
voids: Optional[List[Union[Polyline, Arc, Line, Circle, Polycurve]]] = None
|
||||
displayValue: Optional[List[Mesh]] = None
|
||||
|
||||
|
||||
class GisPolygonElement(Base, speckle_type="Objects.GIS.PolygonElement"):
|
||||
"""GIS Polygon element"""
|
||||
|
||||
geometry: Optional[List[GisPolygonGeometry]] = None
|
||||
attributes: Optional[Base] = None
|
||||
|
||||
|
||||
class GisLineElement(Base, speckle_type="Objects.GIS.LineElement"):
|
||||
"""GIS Polyline element"""
|
||||
|
||||
geometry: Optional[List[Union[Polyline, Arc, Line, Circle, Polycurve]]] = None,
|
||||
attributes: Optional[Base] = None,
|
||||
geometry: Optional[List[Union[Polyline, Arc, Line, Circle, Polycurve]]] = None
|
||||
attributes: Optional[Base] = None
|
||||
|
||||
|
||||
class GisPointElement(Base, speckle_type="Objects.GIS.PointElement"):
|
||||
"""GIS Point element"""
|
||||
|
||||
geometry: Optional[List[Point]] = None,
|
||||
attributes: Optional[Base] = None,
|
||||
geometry: Optional[List[Point]] = None
|
||||
attributes: Optional[Base] = None
|
||||
|
||||
class GisRasterElement(Base, speckle_type="Objects.GIS.RasterElement", detachable={"displayValue"}):
|
||||
|
||||
class GisRasterElement(
|
||||
Base, speckle_type="Objects.GIS.RasterElement", detachable={"displayValue"}
|
||||
):
|
||||
"""GIS Raster element"""
|
||||
|
||||
band_count: Optional[int] = None
|
||||
@@ -43,11 +59,16 @@ class GisRasterElement(Base, speckle_type="Objects.GIS.RasterElement", detachabl
|
||||
noDataValue: Optional[List[float]] = None
|
||||
displayValue: Optional[List[Mesh]] = None
|
||||
|
||||
class GisTopography(GisRasterElement, speckle_type="Objects.GIS.GisTopography", detachable={"displayValue"}):
|
||||
|
||||
class GisTopography(
|
||||
GisRasterElement,
|
||||
speckle_type="Objects.GIS.GisTopography",
|
||||
detachable={"displayValue"},
|
||||
):
|
||||
"""GIS Raster element with 3d Topography representation"""
|
||||
|
||||
|
||||
class GisNonGeometryElement(Base, speckle_type="Objects.GIS.NonGeometryElement"):
|
||||
"""GIS Table feature"""
|
||||
|
||||
attributes: Optional[Base] = None
|
||||
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
from typing import Any, Dict, List, Union, Optional
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.objects.GIS.CRS import CRS
|
||||
from specklepy.objects.other import Collection
|
||||
|
||||
from specklepy.objects.GIS.CRS import CRS
|
||||
from deprecated import deprecated
|
||||
|
||||
@deprecated(version="2.15", reason="Use VectorLayer or RasterLayer instead")
|
||||
class Layer(Base, detachable={"features"}):
|
||||
"""A GIS Layer"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name:str=None,
|
||||
crs:CRS=None,
|
||||
name: str = None,
|
||||
crs: CRS = None,
|
||||
units: str = "m",
|
||||
features: Optional[List[Base]] = None,
|
||||
layerType: str = "None",
|
||||
geomType: str = "None",
|
||||
renderer: Optional[dict[str, Any]] = None,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.name = name
|
||||
@@ -26,25 +29,28 @@ class Layer(Base, detachable={"features"}):
|
||||
self.type = layerType
|
||||
self.features = features or []
|
||||
self.geomType = geomType
|
||||
self.renderer = renderer or {}
|
||||
self.renderer = renderer or {}
|
||||
|
||||
|
||||
@deprecated(version="2.16", reason="Use VectorLayer or RasterLayer instead")
|
||||
class VectorLayer(
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="VectorLayer",
|
||||
serialize_ignore={"features"}):
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="VectorLayer",
|
||||
serialize_ignore={"features"},
|
||||
):
|
||||
|
||||
"""GIS Vector Layer"""
|
||||
name: Optional[str]=None
|
||||
crs: Optional[Union[CRS, Base]]=None
|
||||
|
||||
name: Optional[str] = None
|
||||
crs: Optional[Union[CRS, Base]] = None
|
||||
units: Optional[str] = None
|
||||
elements: Optional[List[Base]] = None
|
||||
attributes: Optional[Base] = None
|
||||
geomType: Optional[str] = "None"
|
||||
renderer: Optional[Dict[str, Any]] = None
|
||||
collectionType = "VectorLayer"
|
||||
|
||||
|
||||
@property
|
||||
@deprecated(version="2.14", reason="Use elements")
|
||||
def features(self) -> Optional[List[Base]]:
|
||||
@@ -54,25 +60,26 @@ class VectorLayer(
|
||||
def features(self, value: Optional[List[Base]]) -> None:
|
||||
self.elements = value
|
||||
|
||||
|
||||
@deprecated(version="2.16", reason="Use VectorLayer or RasterLayer instead")
|
||||
class RasterLayer(
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="RasterLayer",
|
||||
serialize_ignore={"features"}):
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="RasterLayer",
|
||||
serialize_ignore={"features"},
|
||||
):
|
||||
|
||||
"""GIS Raster Layer"""
|
||||
|
||||
name: Optional[str] = None
|
||||
crs: Optional[Union[CRS, Base]]=None
|
||||
crs: Optional[Union[CRS, Base]] = None
|
||||
units: Optional[str] = None
|
||||
rasterCrs: Optional[Union[CRS, Base]]=None
|
||||
rasterCrs: Optional[Union[CRS, Base]] = None
|
||||
elements: Optional[List[Base]] = None
|
||||
geomType: Optional[str] = "None"
|
||||
renderer: Optional[Dict[str, Any]] = None
|
||||
collectionType = "RasterLayer"
|
||||
|
||||
|
||||
@property
|
||||
@deprecated(version="2.14", reason="Use elements")
|
||||
def features(self) -> Optional[List[Base]]:
|
||||
@@ -83,23 +90,24 @@ class RasterLayer(
|
||||
self.elements = value
|
||||
|
||||
|
||||
class VectorLayer(
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="Objects.GIS.VectorLayer",
|
||||
serialize_ignore={"features"}):
|
||||
class VectorLayer( # noqa: F811
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="Objects.GIS.VectorLayer",
|
||||
serialize_ignore={"features"},
|
||||
):
|
||||
|
||||
"""GIS Vector Layer"""
|
||||
|
||||
name: Optional[str]=None
|
||||
crs: Optional[Union[CRS, Base]]=None
|
||||
name: Optional[str] = None
|
||||
crs: Optional[Union[CRS, Base]] = None
|
||||
units: Optional[str] = None
|
||||
elements: Optional[List[Base]] = None
|
||||
attributes: Optional[Base] = None
|
||||
geomType: Optional[str] = "None"
|
||||
renderer: Optional[Dict[str, Any]] = None
|
||||
collectionType = "VectorLayer"
|
||||
|
||||
|
||||
@property
|
||||
@deprecated(version="2.14", reason="Use elements")
|
||||
def features(self) -> Optional[List[Base]]:
|
||||
@@ -109,24 +117,25 @@ class VectorLayer(
|
||||
def features(self, value: Optional[List[Base]]) -> None:
|
||||
self.elements = value
|
||||
|
||||
class RasterLayer(
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="Objects.GIS.RasterLayer",
|
||||
serialize_ignore={"features"}):
|
||||
|
||||
class RasterLayer( # noqa: F811
|
||||
Collection,
|
||||
detachable={"elements"},
|
||||
speckle_type="Objects.GIS.RasterLayer",
|
||||
serialize_ignore={"features"},
|
||||
):
|
||||
|
||||
"""GIS Raster Layer"""
|
||||
|
||||
name: Optional[str] = None
|
||||
crs: Optional[Union[CRS, Base]]=None
|
||||
crs: Optional[Union[CRS, Base]] = None
|
||||
units: Optional[str] = None
|
||||
rasterCrs: Optional[Union[CRS, Base]]=None
|
||||
rasterCrs: Optional[Union[CRS, Base]] = None
|
||||
elements: Optional[List[Base]] = None
|
||||
geomType: Optional[str] = "None"
|
||||
renderer: Optional[Dict[str, Any]] = None
|
||||
collectionType = "RasterLayer"
|
||||
|
||||
|
||||
@property
|
||||
@deprecated(version="2.14", reason="Use elements")
|
||||
def features(self) -> Optional[List[Base]]:
|
||||
@@ -135,4 +144,3 @@ class RasterLayer(
|
||||
@features.setter
|
||||
def features(self, value: Optional[List[Base]]) -> None:
|
||||
self.elements = value
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ from warnings import warn
|
||||
from stringcase import pascalcase
|
||||
|
||||
from specklepy.logging.exceptions import SpeckleException, SpeckleInvalidUnitException
|
||||
from specklepy.objects.units import Units, get_units_from_string
|
||||
from specklepy.objects.units import Units
|
||||
from specklepy.transports.memory import MemoryTransport
|
||||
|
||||
PRIMITIVES = (int, float, str, bool)
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Collection, Dict, Generic, Iterable, List, Optional, Tuple, TypeVar
|
||||
from typing import Any, Collection, Dict, Generic, Iterable, Optional, Tuple, TypeVar
|
||||
|
||||
from attrs import define
|
||||
|
||||
from specklepy.objects.base import Base
|
||||
|
||||
ROOT: str = "__Root"
|
||||
|
||||
T = TypeVar('T')
|
||||
T = TypeVar("T")
|
||||
PARENT_INFO = Tuple[Optional[str], str]
|
||||
|
||||
|
||||
@define(slots=True)
|
||||
class CommitObjectBuilder(ABC, Generic[T]):
|
||||
|
||||
converted: Dict[str, Base]
|
||||
_parent_infos: Dict[str, Collection[PARENT_INFO]]
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.converted = {}
|
||||
self._parent_infos = {}
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def include_object(self, conversion_result: Base, native_object: T) -> None:
|
||||
pass
|
||||
@@ -26,14 +27,17 @@ class CommitObjectBuilder(ABC, Generic[T]):
|
||||
def build_commit_object(self, root_commit_object: Base) -> None:
|
||||
self.apply_relationships(self.converted.values(), root_commit_object)
|
||||
|
||||
def set_relationship(self, app_id: Optional[str], *parent_info : PARENT_INFO) -> None:
|
||||
|
||||
def set_relationship(
|
||||
self, app_id: Optional[str], *parent_info: PARENT_INFO
|
||||
) -> None:
|
||||
if not app_id:
|
||||
return
|
||||
|
||||
|
||||
self._parent_infos[app_id] = parent_info
|
||||
|
||||
def apply_relationships(self, to_add: Iterable[Base], root_commit_object: Base) -> None:
|
||||
def apply_relationships(
|
||||
self, to_add: Iterable[Base], root_commit_object: Base
|
||||
) -> None:
|
||||
for c in to_add:
|
||||
try:
|
||||
self.apply_relationship(c, root_commit_object)
|
||||
@@ -41,20 +45,25 @@ class CommitObjectBuilder(ABC, Generic[T]):
|
||||
print(f"Failed to add object {type(c)} to commit object: {ex}")
|
||||
|
||||
def apply_relationship(self, current: Base, root_commit_object: Base):
|
||||
if not current.applicationId: raise Exception(f"Expected applicationId to have been set")
|
||||
|
||||
if not current.applicationId:
|
||||
raise Exception("Expected applicationId to have been set")
|
||||
|
||||
parents = self._parent_infos[current.applicationId]
|
||||
|
||||
for (parent_id, prop_name) in parents:
|
||||
if not parent_id: continue
|
||||
|
||||
for parent_id, prop_name in parents:
|
||||
if not parent_id:
|
||||
continue
|
||||
|
||||
parent: Optional[Base]
|
||||
if parent_id == ROOT:
|
||||
parent = root_commit_object
|
||||
else:
|
||||
parent = self.converted[parent_id] if parent_id in self.converted else None
|
||||
|
||||
if not parent: continue
|
||||
parent = (
|
||||
self.converted[parent_id] if parent_id in self.converted else None
|
||||
)
|
||||
|
||||
if not parent:
|
||||
continue
|
||||
|
||||
try:
|
||||
elements = get_detached_prop(parent, prop_name)
|
||||
@@ -66,18 +75,26 @@ class CommitObjectBuilder(ABC, Generic[T]):
|
||||
return
|
||||
except Exception as ex:
|
||||
# A parent was found, but it was invalid (Likely because of a type mismatch on a `elements` property)
|
||||
print(f"Failed to add object {type(current)} to a converted parent; {ex}")
|
||||
|
||||
raise Exception(f"Could not find a valid parent for object of type {type(current)}. Checked {len(parents)} potential parent, and non were converted!")
|
||||
print(
|
||||
f"Failed to add object {type(current)} to a converted parent; {ex}"
|
||||
)
|
||||
|
||||
raise Exception(
|
||||
f"Could not find a valid parent for object of type {type(current)}. Checked {len(parents)} potential parent, and non were converted!"
|
||||
)
|
||||
|
||||
|
||||
def get_detached_prop(speckle_object: Base, prop_name: str) -> Optional[Any]:
|
||||
detached_prop_name = get_detached_prop_name(speckle_object, prop_name)
|
||||
return getattr(speckle_object, detached_prop_name, None)
|
||||
|
||||
def set_detached_prop(speckle_object: Base, prop_name: str, value: Optional[Any]) -> None:
|
||||
|
||||
def set_detached_prop(
|
||||
speckle_object: Base, prop_name: str, value: Optional[Any]
|
||||
) -> None:
|
||||
detached_prop_name = get_detached_prop_name(speckle_object, prop_name)
|
||||
setattr(speckle_object, detached_prop_name, value)
|
||||
|
||||
|
||||
def get_detached_prop_name(speckle_object: Base, prop_name: str) -> str:
|
||||
return prop_name if hasattr(speckle_object, prop_name) else f"@{prop_name}"
|
||||
return prop_name if hasattr(speckle_object, prop_name) else f"@{prop_name}"
|
||||
|
||||
@@ -41,7 +41,6 @@ class TraversalContext:
|
||||
@final
|
||||
@define(slots=True, frozen=True)
|
||||
class GraphTraversal:
|
||||
|
||||
_rules: List[ITraversalRule]
|
||||
|
||||
def traverse(self, root: Base) -> Iterator[TraversalContext]:
|
||||
@@ -58,15 +57,15 @@ class GraphTraversal:
|
||||
members_to_traverse = active_rule.get_members_to_traverse(current)
|
||||
for child_prop in members_to_traverse:
|
||||
try:
|
||||
if child_prop in {"speckle_type", "units", "applicationId"}: continue #debug: to avoid noisy exceptions, explicitly avoid checking ones we know will fail, this is not exhaustive
|
||||
if child_prop in {"speckle_type", "units", "applicationId"}:
|
||||
continue # debug: to avoid noisy exceptions, explicitly avoid checking ones we know will fail, this is not exhaustive
|
||||
if getattr(current, child_prop, None):
|
||||
value = current[child_prop]
|
||||
self._traverse_member_to_stack(
|
||||
stack, value, child_prop, head
|
||||
)
|
||||
except KeyError as ex:
|
||||
self._traverse_member_to_stack(stack, value, child_prop, head)
|
||||
except KeyError:
|
||||
# Unset application ids, and class variables like SpeckleType will throw when __getitem__ is called
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _traverse_member_to_stack(
|
||||
stack: List[TraversalContext],
|
||||
@@ -78,10 +77,14 @@ class GraphTraversal:
|
||||
stack.append(TraversalContext(value, member_name, parent))
|
||||
elif isinstance(value, list):
|
||||
for obj in value:
|
||||
GraphTraversal._traverse_member_to_stack(stack, obj, member_name, parent)
|
||||
GraphTraversal._traverse_member_to_stack(
|
||||
stack, obj, member_name, parent
|
||||
)
|
||||
elif isinstance(value, dict):
|
||||
for obj in value.values():
|
||||
GraphTraversal._traverse_member_to_stack(stack, obj, member_name, parent)
|
||||
GraphTraversal._traverse_member_to_stack(
|
||||
stack, obj, member_name, parent
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def traverse_member(value: Optional[Any]) -> Iterator[Base]:
|
||||
@@ -96,7 +99,6 @@ class GraphTraversal:
|
||||
for o in GraphTraversal.traverse_member(obj):
|
||||
yield o
|
||||
|
||||
|
||||
def _get_active_rule_or_default_rule(self, o: Base) -> ITraversalRule:
|
||||
return self._get_active_rule(o) or _default_rule
|
||||
|
||||
@@ -120,4 +122,4 @@ class TraversalRule:
|
||||
for condition in self._conditions:
|
||||
if condition(o):
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from typing import Any, List, Optional
|
||||
|
||||
from deprecated import deprecated
|
||||
|
||||
from specklepy.objects.geometry import Point, Vector
|
||||
from specklepy.objects.geometry import Plane, Point, Polyline, Vector
|
||||
|
||||
from .base import Base
|
||||
|
||||
@@ -71,6 +72,19 @@ 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",
|
||||
@@ -247,9 +261,7 @@ class BlockDefinition(
|
||||
geometry: Optional[List[Base]] = None
|
||||
|
||||
|
||||
class Instance(
|
||||
Base, speckle_type=OTHER + "Instance", detachable={"definition"}
|
||||
):
|
||||
class Instance(Base, speckle_type=OTHER + "Instance", detachable={"definition"}):
|
||||
transform: Optional[Transform] = None
|
||||
definition: Optional[Base] = None
|
||||
|
||||
@@ -268,17 +280,17 @@ class BlockInstance(
|
||||
def blockDefinition(self, value: Optional[BlockDefinition]) -> None:
|
||||
self.definition = value
|
||||
|
||||
|
||||
class RevitInstance(Instance, speckle_type=OTHER_REVIT + "RevitInstance"):
|
||||
level: Optional[Base] = None
|
||||
level: Optional[Base] = None
|
||||
facingFlipped: bool
|
||||
handFlipped: bool
|
||||
parameters: Optional[Base] = None
|
||||
parameters: Optional[Base] = None
|
||||
elementId: Optional[str]
|
||||
|
||||
|
||||
# TODO: prob move this into a built elements module, but just trialling this for now
|
||||
class RevitParameter(
|
||||
Base, speckle_type="Objects.BuiltElements.Revit.Parameter"
|
||||
):
|
||||
class RevitParameter(Base, speckle_type="Objects.BuiltElements.Revit.Parameter"):
|
||||
name: Optional[str] = None
|
||||
value: Any = None
|
||||
applicationUnitType: Optional[str] = None # eg UnitType UT_Length
|
||||
@@ -290,9 +302,10 @@ class RevitParameter(
|
||||
isReadOnly: bool = False
|
||||
isTypeParameter: bool = False
|
||||
|
||||
|
||||
class Collection(
|
||||
Base, speckle_type="Speckle.Core.Models.Collection", detachable={"elements"}
|
||||
):
|
||||
name: Optional[str] = None
|
||||
collectionType: Optional[str] = None
|
||||
elements: Optional[List[Base]] = None
|
||||
elements: Optional[List[Base]] = None
|
||||
|
||||
@@ -6,10 +6,7 @@ from specklepy.objects.structural.analysis import (
|
||||
ModelSettings,
|
||||
ModelUnits,
|
||||
)
|
||||
from specklepy.objects.structural.axis import (
|
||||
AxisType,
|
||||
Axis
|
||||
)
|
||||
from specklepy.objects.structural.axis import Axis, AxisType
|
||||
from specklepy.objects.structural.geometry import (
|
||||
Element1D,
|
||||
Element2D,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from typing import Optional
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.objects.geometry import Plane
|
||||
|
||||
@@ -106,7 +106,9 @@ def get_encoding_from_units(unit: Union[Units, str, None]):
|
||||
|
||||
def get_scale_factor_from_string(fromUnits: str, toUnits: str) -> float:
|
||||
"""Returns a scalar to convert distance values from one unit system to another"""
|
||||
return get_scale_factor(get_units_from_string(fromUnits), get_units_from_string(toUnits))
|
||||
return get_scale_factor(
|
||||
get_units_from_string(fromUnits), get_units_from_string(toUnits)
|
||||
)
|
||||
|
||||
|
||||
def get_scale_factor(fromUnits: Units, toUnits: Units) -> float:
|
||||
@@ -119,4 +121,4 @@ def get_scale_factor_to_meters(fromUnits: Units) -> float:
|
||||
if fromUnits not in UNIT_SCALE:
|
||||
raise ValueError(f"Invalid units provided: {fromUnits}")
|
||||
|
||||
return UNIT_SCALE[fromUnits]
|
||||
return UNIT_SCALE[fromUnits]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Dict, List
|
||||
from typing import Dict, List
|
||||
|
||||
from specklepy.transports.abstract_transport import AbstractTransport
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ class BatchSender(object):
|
||||
raise SpeckleException(
|
||||
message=(
|
||||
"Could not save the object to the server - status code"
|
||||
f" {r.status_code} ({r.text[:1000]})"
|
||||
f" {r.status_code} ({r.text[:1000]})"
|
||||
)
|
||||
)
|
||||
except json.JSONDecodeError as error:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Dict, List, Optional
|
||||
from warnings import warn
|
||||
|
||||
import requests
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import sqlite3
|
||||
from contextlib import closing
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from specklepy.core.helpers import speckle_path_provider
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
|
||||
@@ -5,12 +5,6 @@ from typing import Dict
|
||||
|
||||
import pytest
|
||||
from gql import gql
|
||||
from speckle_automate.schema import AutomateBase
|
||||
from speckle_automate.helpers import register_new_automation, crypto_random_string
|
||||
from specklepy.api import operations
|
||||
from specklepy.api.client import SpeckleClient
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.transports.server import ServerTransport
|
||||
|
||||
from speckle_automate import (
|
||||
AutomationContext,
|
||||
@@ -18,6 +12,12 @@ from speckle_automate import (
|
||||
AutomationStatus,
|
||||
run_function,
|
||||
)
|
||||
from speckle_automate.helpers import crypto_random_string, register_new_automation
|
||||
from speckle_automate.schema import AutomateBase
|
||||
from specklepy.api import operations
|
||||
from specklepy.api.client import SpeckleClient
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.transports.server import ServerTransport
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -111,8 +111,8 @@ def get_automation_status(
|
||||
query = gql(
|
||||
"""
|
||||
query AutomationRuns(
|
||||
$projectId: String!
|
||||
$modelId: String!
|
||||
$projectId: String!
|
||||
$modelId: String!
|
||||
)
|
||||
{
|
||||
project(id: $projectId) {
|
||||
@@ -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()
|
||||
|
||||
@@ -8,11 +8,7 @@ from specklepy.api.models import (
|
||||
Stream,
|
||||
User,
|
||||
)
|
||||
from specklepy.logging.exceptions import (
|
||||
GraphQLException,
|
||||
SpeckleException,
|
||||
UnsupportedException,
|
||||
)
|
||||
from specklepy.logging.exceptions import GraphQLException, SpeckleException
|
||||
|
||||
|
||||
@pytest.mark.run(order=3)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -102,4 +102,4 @@ class GraphTraversalTests(TestCase):
|
||||
|
||||
self.assertCountEqual(ret, [test_case, expected_traverse, expected_traverse])
|
||||
self.assertNotIn(expected_ignore, ret)
|
||||
self.assertEqual(len(ret), 3)
|
||||
self.assertEqual(len(ret), 3)
|
||||
|
||||
@@ -107,7 +107,12 @@ fake_bases = [FakeBase("foo"), FakeBase("bar")]
|
||||
fake_bases,
|
||||
),
|
||||
(List["int"], [2, 3, 4], True, [2, 3, 4]),
|
||||
(Union[float, Dict[str, float]], {"foo": 1, "bar": 2}, True, {"foo": 1.0, "bar": 2.0}),
|
||||
(
|
||||
Union[float, Dict[str, float]],
|
||||
{"foo": 1, "bar": 2},
|
||||
True,
|
||||
{"foo": 1.0, "bar": 2.0},
|
||||
),
|
||||
(Union[float, Dict[str, float]], {"foo": "bar"}, False, {"foo": "bar"}),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from specklepy.objects.units import Units, get_scale_factor
|
||||
@@ -8,7 +6,7 @@ from specklepy.objects.units import Units, get_scale_factor
|
||||
@pytest.mark.parametrize(
|
||||
"fromUnits, toUnits, inValue, expectedOutValue",
|
||||
[
|
||||
#To self
|
||||
# To self
|
||||
(Units.km, Units.km, 1.5, 1.5),
|
||||
(Units.km, Units.km, 0, 0),
|
||||
(Units.m, Units.m, 1.5, 1.5),
|
||||
@@ -23,24 +21,20 @@ from specklepy.objects.units import Units, get_scale_factor
|
||||
(Units.yards, Units.yards, 0, 0),
|
||||
(Units.feet, Units.feet, 1.5, 1.5),
|
||||
(Units.feet, Units.feet, 0, 0),
|
||||
|
||||
#To Meters
|
||||
# To Meters
|
||||
(Units.km, Units.m, 987654.321, 987654321),
|
||||
(Units.m, Units.m, 987654.321, 987654.321),
|
||||
(Units.mm, Units.m, 98765432.1, 98765.4321),
|
||||
(Units.cm, Units.m, 9876543.21, 98765.4321),
|
||||
|
||||
#To negative meters
|
||||
# To negative meters
|
||||
(Units.km, Units.m, -987654.321, -987654321),
|
||||
(Units.m, Units.m,- 987654.321, -987654.321),
|
||||
(Units.m, Units.m, -987654.321, -987654.321),
|
||||
(Units.mm, Units.m, -98765432.1, -98765.4321),
|
||||
(Units.cm, Units.m, -9876543.21, -98765.4321),
|
||||
|
||||
(Units.m, Units.km, 987654.321, 987.654321),
|
||||
(Units.m, Units.cm, 987654.321, 98765432.1),
|
||||
(Units.m, Units.mm, 987654.321, 987654321),
|
||||
|
||||
#Imperial
|
||||
# Imperial
|
||||
(Units.miles, Units.m, 123.45, 198673.517),
|
||||
(Units.miles, Units.inches, 123.45, 7821792),
|
||||
(Units.yards, Units.m, 123.45, 112.88268),
|
||||
@@ -50,7 +44,9 @@ from specklepy.objects.units import Units, get_scale_factor
|
||||
(Units.inches, Units.m, 123.45, 3.13563),
|
||||
],
|
||||
)
|
||||
def test_get_scale_factor_between_units(fromUnits: Units, toUnits: Units, inValue: float, expectedOutValue: float):
|
||||
def test_get_scale_factor_between_units(
|
||||
fromUnits: Units, toUnits: Units, inValue: float, expectedOutValue: float
|
||||
):
|
||||
Tolerance = 1e-10
|
||||
actual = inValue * get_scale_factor(fromUnits, toUnits)
|
||||
assert(actual - expectedOutValue < Tolerance)
|
||||
assert actual - expectedOutValue < Tolerance
|
||||
|
||||
+14
-19
@@ -3,9 +3,9 @@ Provides uniform and consistent path helpers for `specklepy`
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
from importlib import import_module, invalidate_caches
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from importlib import import_module, invalidate_caches
|
||||
|
||||
_user_data_env_var = "SPECKLE_USERDATA_PATH"
|
||||
|
||||
@@ -55,9 +55,7 @@ def user_application_data_path() -> Path:
|
||||
if sys.platform.startswith("win"):
|
||||
app_data_path = os.getenv("APPDATA")
|
||||
if not app_data_path:
|
||||
raise Exception(
|
||||
"Cannot get appdata path from environment."
|
||||
)
|
||||
raise Exception("Cannot get appdata path from environment.")
|
||||
return Path(app_data_path)
|
||||
else:
|
||||
# try getting the standard XDG_DATA_HOME value
|
||||
@@ -68,9 +66,7 @@ def user_application_data_path() -> Path:
|
||||
else:
|
||||
return _ensure_folder_exists(Path.home(), ".config")
|
||||
except Exception as ex:
|
||||
raise Exception(
|
||||
"Failed to initialize user application data path.", ex
|
||||
)
|
||||
raise Exception("Failed to initialize user application data path.", ex)
|
||||
|
||||
|
||||
def user_speckle_folder_path() -> Path:
|
||||
@@ -90,19 +86,16 @@ def user_speckle_connector_installation_path(host_application: str) -> Path:
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print("Starting module dependency installation")
|
||||
print(sys.executable)
|
||||
|
||||
PYTHON_PATH = sys.executable
|
||||
|
||||
|
||||
|
||||
def connector_installation_path(host_application: str) -> Path:
|
||||
connector_installation_path = user_speckle_connector_installation_path(host_application)
|
||||
connector_installation_path = user_speckle_connector_installation_path(
|
||||
host_application
|
||||
)
|
||||
connector_installation_path.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
# set user modules path at beginning of paths for earlier hit
|
||||
@@ -113,7 +106,6 @@ def connector_installation_path(host_application: str) -> Path:
|
||||
return connector_installation_path
|
||||
|
||||
|
||||
|
||||
def is_pip_available() -> bool:
|
||||
try:
|
||||
import_module("pip") # noqa F401
|
||||
@@ -132,7 +124,9 @@ def ensure_pip() -> None:
|
||||
if completed_process.returncode == 0:
|
||||
print("Successfully installed pip")
|
||||
else:
|
||||
raise Exception(f"Failed to install pip, got {completed_process.returncode} return code")
|
||||
raise Exception(
|
||||
f"Failed to install pip, got {completed_process.returncode} return code"
|
||||
)
|
||||
|
||||
|
||||
def get_requirements_path() -> Path:
|
||||
@@ -184,7 +178,7 @@ def _import_dependencies() -> None:
|
||||
# the code above doesn't work for now, it fails on importing graphql-core
|
||||
# despite that, the connector seams to be working as expected
|
||||
# But it would be nice to make this solution work
|
||||
# it would ensure that all dependencies are fully loaded
|
||||
# it would ensure that all dependencies are fully loaded
|
||||
# requirements = get_requirements_path().read_text()
|
||||
# reqs = [
|
||||
# req.split(" ; ")[0].split("==")[0].split("[")[0].replace("-", "_")
|
||||
@@ -195,6 +189,7 @@ def _import_dependencies() -> None:
|
||||
# print(req)
|
||||
# import_module("specklepy")
|
||||
|
||||
|
||||
def ensure_dependencies(host_application: str) -> None:
|
||||
try:
|
||||
install_dependencies(host_application)
|
||||
@@ -202,6 +197,6 @@ def ensure_dependencies(host_application: str) -> None:
|
||||
_import_dependencies()
|
||||
print("Successfully found dependencies")
|
||||
except ImportError:
|
||||
raise Exception(f"Cannot automatically ensure Speckle dependencies. Please try restarting the host application {host_application}!")
|
||||
|
||||
|
||||
raise Exception(
|
||||
f"Cannot automatically ensure Speckle dependencies. Please try restarting the host application {host_application}!"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user