Compare commits

...

5 Commits

Author SHA1 Message Date
izzy lyseggen 9a1f28516d chore: bump version to 2.2.5 2021-07-30 11:35:43 +01:00
izzy lyseggen 92892b83d8 Merge pull request #110 from specklesystems/izzy/sql-fix
fix(sqlite): delay and try except transport init
2021-07-30 11:31:55 +01:00
izzy lyseggen 8904e9eeb4 docs(ops): note that sqlite is default for receive 2021-07-30 11:31:18 +01:00
izzy lyseggen 68dc1794ee fix(sqlite): try catch initialisation of transport 2021-07-30 11:25:35 +01:00
izzy lyseggen 7e7940f25b refactor(ops): delay init of SQLiteTransport 2021-07-30 11:25:02 +01:00
3 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "specklepy"
version = "2.2.4"
version = "2.2.5"
description = "The Python SDK for Speckle 2.0"
readme = "README.md"
authors = ["Speckle Systems <devops@speckle.systems>"]
+6 -4
View File
@@ -52,7 +52,8 @@ def receive(
Arguments:
obj_id {str} -- the id of the object to receive
remote_transport {Transport} -- the transport to receive from
local_transport {Transport} -- the transport to send from
local_transport {Transport} -- the local cache to check for existing objects
(defaults to `SQLiteTransport`)
Returns:
Base -- the base object
@@ -97,9 +98,7 @@ def serialize(base: Base, write_transports: List[AbstractTransport] = []) -> str
return serializer.write_json(base)[1]
def deserialize(
obj_string: str, read_transport: AbstractTransport = SQLiteTransport()
) -> Base:
def deserialize(obj_string: str, read_transport: AbstractTransport = None) -> Base:
"""
Deserialize a string object into a Base object. If the object contains referenced child objects that are not stored in the local db, a read transport needs to be provided in order to recompose the base with the children objects.
@@ -111,6 +110,9 @@ def deserialize(
Returns:
Base -- the deserialized object
"""
if not read_transport:
read_transport = SQLiteTransport()
serializer = BaseObjectSerializer(read_transport=read_transport)
return serializer.read_json(obj_string=obj_string)
+11 -5
View File
@@ -34,12 +34,18 @@ class SQLiteTransport(AbstractTransport):
self.scope = scope or "Objects"
self._base_path = base_path or self.__get_base_path()
os.makedirs(self._base_path, exist_ok=True)
try:
os.makedirs(self._base_path, exist_ok=True)
self._root_path = os.path.join(
os.path.join(self._base_path, f"{self.scope}.db")
)
self.__initialise()
self._root_path = os.path.join(
os.path.join(self._base_path, f"{self.scope}.db")
)
self.__initialise()
except Exception as ex:
raise SpeckleException(
f"SQLiteTransport could not initialise {self.scope}.db at {self._base_path}. Either provide a different `base_path` or use an alternative transport.",
ex,
)
def __repr__(self) -> str:
return f"SQLiteTransport(app: '{self.app_name}', scope: '{self.scope}')"