Skip to content

Commit 1e6321c

Browse files
authored
Merge pull request #296 from specklesystems/gergo/abstract_transport_no_pydantic
fix(AbstractTransport-and-subclasses): abstract transport and its subclasses should not be pydantic models
2 parents 65048cd + b5fb684 commit 1e6321c

File tree

4 files changed

+30
-55
lines changed

4 files changed

+30
-55
lines changed

src/specklepy/transports/abstract_transport.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
from abc import ABC, abstractmethod
22
from typing import Dict, List, Optional
33

4-
from pydantic import BaseModel
5-
from pydantic.config import Extra
6-
7-
8-
class AbstractTransport(ABC, BaseModel):
9-
_name: str = "Abstract"
10-
model_config = {'extra': 'allow', 'arbitrary_types_allowed': True}
114

5+
class AbstractTransport(ABC):
126
@property
7+
@abstractmethod
138
def name(self):
14-
return type(self)._name
9+
pass
1510

1611
@abstractmethod
1712
def begin_write(self) -> None:

src/specklepy/transports/memory.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55

66
class MemoryTransport(AbstractTransport):
7-
_name: str = "Memory"
8-
objects: dict = {}
9-
saved_object_count: int = 0
10-
11-
def __init__(self, name=None, **data: Any) -> None:
12-
super().__init__(**data)
13-
if name:
14-
self._name = name
7+
def __init__(self, name="Memory") -> None:
8+
super().__init__()
9+
self._name = name
10+
self.objects = {}
11+
self.saved_object_count = 0
12+
13+
@property
14+
def name(self) -> str:
15+
return self._name
1516

1617
def __repr__(self) -> str:
1718
return f"MemoryTransport(objects: {len(self.objects)})"

src/specklepy/transports/server/server.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,25 @@ class ServerTransport(AbstractTransport):
4545
```
4646
"""
4747

48-
_name = "RemoteTransport"
49-
url: Optional[str] = None
50-
stream_id: Optional[str] = None
51-
account: Optional[Account] = None
52-
saved_obj_count: int = 0
53-
session: Optional[requests.Session] = None
54-
5548
def __init__(
5649
self,
5750
stream_id: str,
5851
client: Optional[SpeckleClient] = None,
5952
account: Optional[Account] = None,
6053
token: Optional[str] = None,
6154
url: Optional[str] = None,
62-
**data: Any,
55+
name: str = "RemoteTransport",
6356
) -> None:
64-
super().__init__(**data)
57+
super().__init__()
6558
if client is None and account is None and token is None and url is None:
6659
raise SpeckleException(
6760
"You must provide either a client or a token and url to construct a"
6861
" ServerTransport."
6962
)
7063

64+
self._name = name
65+
self.account = None
66+
self.saved_obj_count = 0
7167
if account:
7268
self.account = account
7369
url = account.serverInfo.url
@@ -97,6 +93,10 @@ def __init__(
9793
{"Authorization": f"Bearer {self.account.token}", "Accept": "text/plain"}
9894
)
9995

96+
@property
97+
def name(self) -> str:
98+
return self._name
99+
100100
def begin_write(self) -> None:
101101
self.saved_obj_count = 0
102102

src/specklepy/transports/sqlite.py

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,22 @@
99

1010

1111
class SQLiteTransport(AbstractTransport):
12-
_name = "SQLite"
13-
_base_path: Optional[str] = None
14-
_root_path: Optional[str] = None
15-
__connection: Optional[sqlite3.Connection] = None
16-
app_name: str = ""
17-
scope: str = ""
18-
saved_obj_count: int = 0
19-
max_size: Optional[int] = None
20-
_current_batch: Optional[List[Tuple[str, str]]] = None
21-
_current_batch_size: Optional[int] = None
22-
2312
def __init__(
2413
self,
2514
base_path: Optional[str] = None,
2615
app_name: Optional[str] = None,
2716
scope: Optional[str] = None,
2817
max_batch_size_mb: float = 10.0,
29-
**data: Any,
18+
name: str = "SQLite",
3019
) -> None:
31-
super().__init__(**data)
20+
super().__init__()
21+
self._name = name
3222
self.app_name = app_name or "Speckle"
3323
self.scope = scope or "Objects"
3424
self._base_path = base_path or self.get_base_path(self.app_name)
3525
self.max_size = int(max_batch_size_mb * 1000 * 1000)
36-
self._current_batch = []
26+
self.saved_obj_count = 0
27+
self._current_batch: List[Tuple[str, str]] = []
3728
self._current_batch_size = 0
3829

3930
try:
@@ -54,24 +45,12 @@ def __init__(
5445
def __repr__(self) -> str:
5546
return f"SQLiteTransport(app: '{self.app_name}', scope: '{self.scope}')"
5647

48+
@property
49+
def name(self) -> str:
50+
return self._name
51+
5752
@staticmethod
5853
def get_base_path(app_name):
59-
# # from appdirs https://github.com/ActiveState/appdirs/blob/master/appdirs.py
60-
# # default mac path is not the one we use (we use unix path), so using special case for this
61-
# system = sys.platform
62-
# if system.startswith("java"):
63-
# import platform
64-
65-
# os_name = platform.java_ver()[3][0]
66-
# if os_name.startswith("Mac"):
67-
# system = "darwin"
68-
69-
# if system != "darwin":
70-
# return user_data_dir(appname=app_name, appauthor=False, roaming=True)
71-
72-
# path = os.path.expanduser("~/.config/")
73-
# return os.path.join(path, app_name)
74-
7554
return str(
7655
speckle_path_provider.user_application_data_path().joinpath(app_name)
7756
)

0 commit comments

Comments
 (0)