feat: rename `speckle` to `specklepy`

This commit is contained in:
izzy lyseggen 2021-04-09 12:25:32 +01:00
Родитель 066bc44457
Коммит 434ada8bc1
43 изменённых файлов: 96 добавлений и 89 удалений

Просмотреть файл

@ -29,8 +29,8 @@ To execute any python script run `$ poetry run python my_script.py`
The `SpeckleClient` is the entry point for interacting with the GraphQL API. You'll need to have a running server to use this.
```py
from speckle.api.client import SpeckleClient
from speckle.api.credentials import get_default_account, get_local_accounts
from specklepy.api.client import SpeckleClient
from specklepy.api.credentials import get_default_account, get_local_accounts
all_accounts = get_local_accounts() # get back a list
account = get_default_account()
@ -76,8 +76,8 @@ deleted = client.commit.delete("stream id", "commit id")
The `BaseObjectSerializer` is used for decomposing and serializing `Base` objects so they can be sent / received to the server. You can use it directly to get the id (hash) and a serializable object representation of the decomposed `Base`. You can learn more about the Speckle `Base` object [here](https://discourse.speckle.works/t/core-2-0-the-base-object/782) and the decomposition API [here](https://discourse.speckle.works/t/core-2-0-decomposition-api/911).
```py
from speckle.objects.base import Base
from speckle.serialization.base_object_serializer import BaseObjectSerializer
from specklepy.objects.base import Base
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
detached_base = Base()
detached_base.name = "this will get detached"
@ -93,8 +93,8 @@ hash, obj_dict = serializer.traverse_base(base_obj)
If you use the `operations`, you will not need to interact with the serializer directly as this will be taken care of for you. You will just need to provide a transport to indicate where the objects should be sent / received from. At the moment, just the `MemoryTransport` and the `ServerTransport` are fully functional at the moment. If you'd like to learn more about Transports in Speckle 2.0, have a look [here](https://discourse.speckle.works/t/core-2-0-transports/919).
```py
from speckle.transports.memory import MemoryTransport
from speckle.api import operations
from specklepy.transports.memory import MemoryTransport
from specklepy.api import operations
transport = MemoryTransport()

Просмотреть файл

@ -1,8 +1,8 @@
"""This is an example showcasing the usage of speckle `Base` class."""
# the speckle.objects module exposes all speckle provided classes
from speckle.objects import Base
from speckle.api import operations
from specklepy.objects import Base
from specklepy.api import operations
from devtools import debug

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -1,10 +1,10 @@
import re
from gql.client import SyncClientSession
from speckle.logging.exceptions import SpeckleException
from specklepy.logging.exceptions import SpeckleException
from typing import Dict
from speckle.api import resources
from speckle.api.resources import (
from specklepy.api import resources
from specklepy.api.resources import (
branch,
commit,
stream,
@ -20,7 +20,7 @@ from gql.transport.websockets import WebsocketsTransport
class SpeckleClient:
DEFAULT_HOST = "staging.speckle.dev"
DEFAULT_HOST = "speckle.xyz"
USE_SSL = True
def __init__(self, host: str = DEFAULT_HOST, use_ssl: bool = USE_SSL) -> None:

Просмотреть файл

@ -1,7 +1,7 @@
from typing import List, Optional
from pydantic import BaseModel
from speckle.api.models import ServerInfo
from speckle.transports.sqlite import SQLiteTransport
from specklepy.api.models import ServerInfo
from specklepy.transports.sqlite import SQLiteTransport
account_storage = SQLiteTransport(scope="Accounts")

Просмотреть файл

Просмотреть файл

@ -1,11 +1,11 @@
import json
from typing import List
from speckle.objects.base import Base
from speckle.transports.sqlite import SQLiteTransport
from speckle.transports.server import ServerTransport
from speckle.logging.exceptions import SpeckleException
from speckle.transports.abstract_transport import AbstractTransport
from speckle.serialization.base_object_serializer import BaseObjectSerializer
from specklepy.objects.base import Base
from specklepy.transports.sqlite import SQLiteTransport
from specklepy.transports.server import ServerTransport
from specklepy.logging.exceptions import SpeckleException
from specklepy.transports.abstract_transport import AbstractTransport
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
def send(

Просмотреть файл

@ -1,5 +1,5 @@
from logging import error
from speckle.logging.exceptions import GraphQLException, SpeckleException
from specklepy.logging.exceptions import GraphQLException, SpeckleException
from typing import Dict, List
from gql.client import Client
from gql.gql import gql

Просмотреть файл

Просмотреть файл

@ -1,9 +1,9 @@
from speckle.api.resources import stream
from specklepy.api.resources import stream
from typing import List, Optional
from gql import gql
from pydantic.main import BaseModel
from speckle.api.resource import ResourceBase
from speckle.api.models import Branch
from specklepy.api.resource import ResourceBase
from specklepy.api.models import Branch
NAME = "branch"
METHODS = ["create"]

Просмотреть файл

@ -1,8 +1,8 @@
from typing import Optional, List
from gql import gql
from pydantic.main import BaseModel
from speckle.api.resource import ResourceBase
from speckle.api.models import Commit
from specklepy.api.resource import ResourceBase
from specklepy.api.models import Commit
NAME = "commit"

Просмотреть файл

@ -1,8 +1,8 @@
from typing import Dict, List
from gql import gql
from graphql.language import parser
from speckle.api.resource import ResourceBase
from speckle.objects.base import Base
from specklepy.api.resource import ResourceBase
from specklepy.objects.base import Base
NAME = "object"
METHODS = []

Просмотреть файл

@ -1,8 +1,8 @@
from typing import Dict, List
from gql import gql
from gql.client import Client
from speckle.api.models import ServerInfo
from speckle.api.resource import ResourceBase
from specklepy.api.models import ServerInfo
from specklepy.api.resource import ResourceBase
NAME = "server"

Просмотреть файл

@ -1,7 +1,7 @@
from typing import Dict, List, Optional
from gql import gql
from speckle.api.resource import ResourceBase
from speckle.api.models import Stream
from specklepy.api.resource import ResourceBase
from specklepy.api.models import Stream
NAME = "stream"
METHODS = [

Просмотреть файл

@ -1,9 +1,9 @@
from typing import Callable, Dict, List, Optional, Any
from functools import wraps
from gql import gql
from speckle.api.resource import ResourceBase
from speckle.api.resources.stream import Stream
from speckle.logging.exceptions import GraphQLException, SpeckleException
from specklepy.api.resource import ResourceBase
from specklepy.api.resources.stream import Stream
from specklepy.logging.exceptions import GraphQLException, SpeckleException
NAME = "subscribe"
METHODS = [

Просмотреть файл

@ -1,9 +1,9 @@
from speckle.logging.exceptions import SpeckleException
from specklepy.logging.exceptions import SpeckleException
from typing import List, Optional
from gql import gql
from pydantic.main import BaseModel
from speckle.api.resource import ResourceBase
from speckle.api.models import User
from specklepy.api.resource import ResourceBase
from specklepy.api.models import User
NAME = "user"
METHODS = ["get"]

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -1,5 +1,5 @@
"""Builtin Speckle object kit."""
from speckle.objects.base import Base
from specklepy.objects.base import Base
__all__ = ["Base"]

Просмотреть файл

@ -2,9 +2,9 @@ from inspect import getattr_static
from pydantic import BaseModel, validator
from pydantic.main import Extra
from typing import ClassVar, Dict, List, Optional, Any, Set, Type
from speckle.transports.memory import MemoryTransport
from speckle.logging.exceptions import SpeckleException
from speckle.objects.units import get_units_from_string
from specklepy.transports.memory import MemoryTransport
from specklepy.logging.exceptions import SpeckleException
from specklepy.objects.units import get_units_from_string
PRIMITIVES = (int, float, str, bool)
@ -201,7 +201,7 @@ class Base(_RegisteringBase):
Returns:
str -- the hash (id) of the fully serialized object
"""
from speckle.serialization.base_object_serializer import (
from specklepy.serialization.base_object_serializer import (
BaseObjectSerializer,
)

Просмотреть файл

@ -1,4 +1,4 @@
from speckle.objects.geometry import Point
from specklepy.objects.geometry import Point
from typing import List
from .base import Base

Просмотреть файл

Просмотреть файл

@ -1,4 +1,4 @@
from speckle.logging.exceptions import SpeckleException
from specklepy.logging.exceptions import SpeckleException
UNITS = ["mm", "cm", "m", "in", "ft", "yd", "mi"]

Просмотреть файл

Просмотреть файл

@ -4,10 +4,10 @@ import re
from uuid import uuid4
from typing import Any, Dict, List, Tuple
from speckle.objects.base import Base, DataChunk
from speckle.logging.exceptions import SerializationException, SpeckleException
from speckle.transports.abstract_transport import AbstractTransport
import speckle.objects.geometry
from specklepy.objects.base import Base, DataChunk
from specklepy.logging.exceptions import SerializationException, SpeckleException
from specklepy.transports.abstract_transport import AbstractTransport
import specklepy.objects.geometry
PRIMITIVES = (int, float, str, bool)

Просмотреть файл

Просмотреть файл

@ -1,7 +1,7 @@
import json
from typing import Any
from speckle.logging.exceptions import SpeckleException
from speckle.transports.abstract_transport import AbstractTransport
from specklepy.logging.exceptions import SpeckleException
from specklepy.transports.abstract_transport import AbstractTransport
class MemoryTransport(AbstractTransport):

Просмотреть файл

@ -1,4 +1,3 @@
import logging
import threading
import queue
@ -6,13 +5,20 @@ import time
import gzip
import requests
from speckle.logging.exceptions import SpeckleException
from specklepy.logging.exceptions import SpeckleException
LOG = logging.getLogger(__name__)
class BatchSender(object):
def __init__(self, endpoint, token, max_batch_size_mb=1, batch_buffer_length=10, thread_count=4):
def __init__(
self,
endpoint,
token,
max_batch_size_mb=1,
batch_buffer_length=10,
thread_count=4,
):
self.endpoint = endpoint
self._token = token
@ -84,12 +90,14 @@ class BatchSender(object):
def _bg_send_batch(self, session, batch):
upload_data = "[" + ",".join(batch) + "]"
upload_data_gzip = gzip.compress(upload_data.encode())
LOG.info("Uploading batch of %s objects (size: %s, compressed size: %s)" %
(len(batch), len(upload_data), len(upload_data_gzip)))
LOG.info(
"Uploading batch of %s objects (size: %s, compressed size: %s)"
% (len(batch), len(upload_data), len(upload_data_gzip))
)
r = session.post(
url=self.endpoint,
files={"batch-1": ("batch-1", upload_data_gzip, 'application/gzip')},
files={"batch-1": ("batch-1", upload_data_gzip, "application/gzip")},
)
if r.status_code != 201:
LOG.warning("Upload server response: %s", r.text)
@ -114,4 +122,3 @@ class BatchSender(object):
def __del__(self):
self._delete_threads()

Просмотреть файл

@ -2,9 +2,9 @@ import requests
from typing import Any, Dict, List, Type
from speckle.api.client import SpeckleClient
from speckle.logging.exceptions import SpeckleException
from speckle.transports.abstract_transport import AbstractTransport
from specklepy.api.client import SpeckleClient
from specklepy.logging.exceptions import SpeckleException
from specklepy.transports.abstract_transport import AbstractTransport
from .batch_sender import BatchSender
@ -22,7 +22,7 @@ class ServerTransport(AbstractTransport):
self.url = client.url
self.stream_id = stream_id
token = client.me['token']
token = client.me["token"]
endpoint = f"{self.url}/objects/{self.stream_id}"
self._batch_sender = BatchSender(endpoint, token, max_batch_size_mb=1)

Просмотреть файл

@ -7,8 +7,8 @@ from typing import Any
from appdirs import user_data_dir
from contextlib import closing
from multiprocessing import Process, Queue
from speckle.transports.abstract_transport import AbstractTransport
from speckle.logging.exceptions import SpeckleException
from specklepy.transports.abstract_transport import AbstractTransport
from specklepy.logging.exceptions import SpeckleException
class SQLiteTransport(AbstractTransport):

Просмотреть файл

@ -2,11 +2,11 @@ import uuid
import random
import pytest
import requests
from speckle.api.models import Stream
from speckle.api.client import SpeckleClient
from speckle.objects.base import Base
from speckle.objects.geometry import Point
from speckle.objects.fakemesh import FakeMesh
from specklepy.api.models import Stream
from specklepy.api.client import SpeckleClient
from specklepy.objects.base import Base
from specklepy.objects.geometry import Point
from specklepy.objects.fakemesh import FakeMesh
@pytest.fixture(scope="session")

Просмотреть файл

@ -1,6 +1,6 @@
import pytest
from speckle.objects import Base
from speckle.api import operations
from specklepy.objects import Base
from specklepy.api import operations
from contextlib import ExitStack as does_not_raise

Просмотреть файл

@ -1,4 +1,4 @@
from speckle.api.models import Branch, Commit, Stream
from specklepy.api.models import Branch, Commit, Stream
import pytest

Просмотреть файл

@ -1,5 +1,5 @@
import pytest
from speckle.api.models import Commit, Stream
from specklepy.api.models import Commit, Stream
@pytest.mark.run(order=4)

Просмотреть файл

@ -1,7 +1,7 @@
from speckle.objects import Base
from speckle.transports.memory import MemoryTransport
from speckle.api.models import Stream
from speckle.serialization.base_object_serializer import BaseObjectSerializer
from specklepy.objects import Base
from specklepy.transports.memory import MemoryTransport
from specklepy.api.models import Stream
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
import pytest

Просмотреть файл

@ -1,13 +1,13 @@
import json
from attr import has
import pytest
from speckle.api import operations
from speckle.transports.server import ServerTransport
from speckle.transports.memory import MemoryTransport
from speckle.serialization.base_object_serializer import BaseObjectSerializer
from speckle.objects import Base
from speckle.objects.geometry import Point
from speckle.objects.fakemesh import FakeMesh
from specklepy.api import operations
from specklepy.transports.server import ServerTransport
from specklepy.transports.memory import MemoryTransport
from specklepy.serialization.base_object_serializer import BaseObjectSerializer
from specklepy.objects import Base
from specklepy.objects.geometry import Point
from specklepy.objects.fakemesh import FakeMesh
@pytest.mark.run(order=3)

Просмотреть файл

@ -1,5 +1,5 @@
import pytest
from speckle.api.models import ServerInfo
from specklepy.api.models import ServerInfo
class TestServer:

Просмотреть файл

@ -1,6 +1,6 @@
import pytest
from speckle.api.models import Stream
from speckle.logging.exceptions import GraphQLException
from specklepy.api.models import Stream
from specklepy.logging.exceptions import GraphQLException
@pytest.mark.run(order=2)

Просмотреть файл

@ -1,5 +1,5 @@
from speckle.logging.exceptions import SpeckleException
from speckle.api.models import User
from specklepy.logging.exceptions import SpeckleException
from specklepy.api.models import User
import pytest