Compare commits

..

12 Commits

Author SHA1 Message Date
izzy lyseggen 29c97cde45 chore: bump version to 2.2.4 2021-07-29 16:14:25 +01:00
izzy lyseggen 02f4f4fe41 Merge pull request #109 from specklesystems/izzy/sql-transport
feat(sqlite): remove unusued queue
2021-07-29 16:12:37 +01:00
izzy lyseggen b2dd5bfedd feat(sqlite): remove unusued queue 2021-07-29 16:11:04 +01:00
izzy lyseggen 09b3edcc23 Merge pull request #106 from specklesystems/izzy/smol-sparkles
fix(base): get parent props on child serialisation
2021-07-28 18:08:00 +01:00
izzy lyseggen a44036863d fix(base): get units prop on children 2021-07-28 18:01:51 +01:00
izzy lyseggen 5806c032dd feat(units): add km 2021-07-28 18:01:25 +01:00
izzy lyseggen cff20aec54 Merge pull request #105 from specklesystems/izzy/client-docstrings
docs(client): add dosctring to the `SpeckleClient`
2021-07-22 09:28:04 +01:00
izzy lyseggen 144d51b147 docs(client): add dosctring to the SpeckleClient
as alan noted, the default one is garbo lol
hopefully this will make it clearer for users
2021-07-22 09:27:32 +01:00
izzy lyseggen 09f61a6efd Update README.md 2021-07-22 09:15:26 +01:00
Matteo Cominetti e61bf0f78f Update README.md 2021-07-22 09:14:41 +01:00
izzy lyseggen 6ac72ce8ee Merge pull request #104 from specklesystems/izzy/readme
docs(readme): use xyz as example host
2021-07-22 09:12:34 +01:00
izzy lyseggen 0b9ef942f5 docs(readme): use xyz as example host 2021-07-22 09:12:20 +01:00
7 changed files with 56 additions and 39 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ from specklepy.api.credentials import get_default_account, get_local_accounts
all_accounts = get_local_accounts() # get back a list
account = get_default_account()
client = SpeckleClient(host="localhost:3000", use_ssl=False)
client = SpeckleClient(host="speckle.xyz")
# client = SpeckleClient(host="yourserver.com") or whatever your host is
client.authenticate(account.token)
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "specklepy"
version = "2.2.3"
version = "2.2.4"
description = "The Python SDK for Speckle 2.0"
readme = "README.md"
authors = ["Speckle Systems <devops@speckle.systems>"]
+27
View File
@@ -21,6 +21,33 @@ from gql.transport.websockets import WebsocketsTransport
class SpeckleClient:
"""
The `SpeckleClient` is your entry point for interacting with your Speckle Server's GraphQL API.
You'll need to have access to a server to use it, or you can use our public server `speckle.xyz`.
To authenticate the client, you'll need to have downloaded the [Speckle Manager](https://speckle.guide/#speckle-manager)
and added your account.
```py
from specklepy.api.client import SpeckleClient
from specklepy.api.credentials import get_default_account
# initialise the client
client = SpeckleClient(host="speckle.xyz") # or whatever your host is
# client = SpeckleClient(host="localhost:3000", use_ssl=False) or use local server
# authenticate the client with a token (account has been added in Speckle Manager)
account = get_default_account()
client.authenticate(token=account.token)
# create a new stream. this returns the stream id
new_stream_id = client.stream.create(name="a shiny new stream")
# use that stream id to get the stream from the server
new_stream = client.stream.get(id=new_stream_id)
```
"""
DEFAULT_HOST = "speckle.xyz"
USE_SSL = True
+7 -11
View File
@@ -98,7 +98,7 @@ class Base(_RegisteringBase):
@classmethod
def validate_prop_name(cls, name: str) -> None:
"""Validator for dynamic attribute names."""
if name in ("", "@"):
if name in {"", "@"}:
raise ValueError("Invalid Name: Base member names cannot be empty strings")
if name.startswith("@@"):
raise ValueError(
@@ -172,7 +172,7 @@ class Base(_RegisteringBase):
if not name.startswith("_")
and name
!= "fields" # soon to be removed as this pydantic prop is depreciated
and isinstance(getattr(self, name, None), property)
and isinstance(getattr(type(self), name, None), property)
]
return attrs + properties
@@ -215,15 +215,11 @@ class Base(_RegisteringBase):
return 0
parsed.append(base)
count = 0
for name, value in base.__dict__.items():
if name.startswith("@"):
continue
else:
count += self._handle_object_count(value, parsed)
return count
return sum(
self._handle_object_count(value, parsed)
for name, value in base.__dict__.items()
if not name.startswith("@")
)
def _handle_object_count(self, obj: Any, parsed: List) -> int:
count = 0
-4
View File
@@ -24,10 +24,6 @@ class Point(Base, speckle_type=GEOMETRY + "Point"):
def __repr__(self) -> str:
return f"{self.__class__.__name__}(x: {self.x}, y: {self.y}, z: {self.z}, id: {self.id}, speckle_type: {self.speckle_type})"
@property
def value(self) -> List[float]:
return [self.x, self.y, self.z]
class Vector(Point, speckle_type=GEOMETRY + "Vector"):
pass
+1
View File
@@ -6,6 +6,7 @@ UNITS_STRINGS = {
"mm": ["mm", "mil", "millimeters", "millimetres"],
"cm": ["cm", "centimetre", "centimeter", "centimetres", "centimeters"],
"m": ["m", "meter", "meters", "metre", "metres"],
"km": ["km", "kilometer", "kilometre", "kilometers", "kilometres"],
"in": ["in", "inch", "inches"],
"ft": ["ft", "foot", "feet"],
"yd": ["yd", "yard", "yards"],
+19 -22
View File
@@ -6,7 +6,6 @@ import sqlite3
from typing import Any, List, Dict
from appdirs import user_data_dir
from contextlib import closing
from multiprocessing import Process, Queue
from specklepy.transports.abstract_transport import AbstractTransport
from specklepy.logging.exceptions import SpeckleException
@@ -19,7 +18,6 @@ class SQLiteTransport(AbstractTransport):
_scheduler = sched.scheduler(time.time, time.sleep)
_polling_interval = 0.5 # seconds
__connection: sqlite3.Connection = None
__queue: Queue = Queue()
app_name: str = ""
scope: str = ""
saved_obj_count: int = 0
@@ -63,26 +61,26 @@ class SQLiteTransport(AbstractTransport):
if os_name.startswith("Mac"):
system = "darwin"
if system == "darwin":
path = os.path.expanduser("~/.config/")
return os.path.join(path, self.app_name)
else:
if system != "darwin":
return user_data_dir(appname=self.app_name, appauthor=False, roaming=True)
def __consume_queue(self):
if self._is_writing or self.__queue.empty():
return
print("CONSUME QUEUE")
self._is_writing = True
while not self.__queue.empty():
data = self.__queue.get()
self.save_object(data[0], data[1])
self._is_writing = False
path = os.path.expanduser("~/.config/")
return os.path.join(path, self.app_name)
self._scheduler.enter(
delay=self._polling_interval, priority=1, action=self.__consume_queue
)
self._scheduler.run(blocking=True)
# def __consume_queue(self):
# if self._is_writing or self.__queue.empty():
# return
# print("CONSUME QUEUE")
# self._is_writing = True
# while not self.__queue.empty():
# data = self.__queue.get()
# self.save_object(data[0], data[1])
# self._is_writing = False
# self._scheduler.enter(
# delay=self._polling_interval, priority=1, action=self.__consume_queue
# )
# self._scheduler.run(blocking=True)
# def save_object(self, id: str, serialized_object: str) -> None:
# """Adds an object to the queue and schedules it to be saved.
@@ -102,15 +100,14 @@ class SQLiteTransport(AbstractTransport):
def save_object_from_transport(
self, id: str, source_transport: AbstractTransport
) -> None:
"""Adds an object from the given transport to the queue and schedules it to be saved.
"""Adds an object from the given transport to the the local db
Arguments:
id {str} -- the object id
source_transport {AbstractTransport) -- the transport through which the object can be found
"""
serialized_object = source_transport.get_object(id)
self.__queue.put((id, serialized_object))
raise NotImplementedError
self.save_object(id, serialized_object)
def save_object(self, id: str, serialized_object: str) -> None:
"""Directly saves an object into the database.