Skip to content

Commit

Permalink
style(whole-project): fixing linting and typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedlicska committed Dec 20, 2022
1 parent b25f2ab commit 990cf4e
Show file tree
Hide file tree
Showing 41 changed files with 506 additions and 237 deletions.
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
hooks:
- id: ruff
rev: v0.0.186

- repo: https://github.com/commitizen-tools/commitizen
hooks:
- id: commitizen
Expand All @@ -8,9 +13,10 @@ repos:
rev: v2.38.0

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: v5.11.3
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
Expand All @@ -21,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.3.0
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
1 change: 0 additions & 1 deletion example/many_children.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def clean_db():


def one_pass(clean: bool, randomize: bool, child_count: int):

foo = Base()
for i in range(child_count):
stuff = random_string() if randomize else "stuff"
Expand Down
15 changes: 15 additions & 0 deletions example/send_receive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from devtools import debug

from specklepy.api import operations
from specklepy.api.wrapper import StreamWrapper

if __name__ == "__main__":
stream_url = "https://latest.speckle.dev/streams/7d051a6449"
wrapper = StreamWrapper(stream_url)

transport = wrapper.get_transport()

rec = operations.receive("98396753f8bf7fe1cb60c5193e9f9d86", transport)

# hash = operations.send(base=foo, transports=[transport], use_default_cache=False)
debug(rec)
1 change: 0 additions & 1 deletion example/stream_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def create_object(child_count: int) -> Base:


if __name__ == "__main__":

stream_url = "http://hyperion:3000/streams/2372b54c35"

child_count = 10
Expand Down
2 changes: 1 addition & 1 deletion patch_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def patch(tag):
lines = f.readlines()

if "version" not in lines[2]:
raise Exception(f"Invalid pyproject.toml. Could not patch version.")
raise Exception("Invalid pyproject.toml. Could not patch version.")

lines[2] = f'version = "{tag}"\n'
with open("pyproject.toml", "w") as file:
Expand Down
52 changes: 51 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pylint = "^2.14.4"
mypy = "^0.982"
pre-commit = "^2.20.0"
commitizen = "^2.38.0"
ruff = "^0.0.187"
types-deprecated = "^1.2.9"
types-ujson = "^5.6.0.0"

[tool.black]
exclude = '''
Expand All @@ -50,7 +53,7 @@ exclude = '''
'''
include = '\.pyi?$'
line-length = 88
target-version = ["py37", "py38", "py39", "py310"]
target-version = ["py37", "py38", "py39", "py310", "py311"]


[tool.commitizen]
Expand Down
41 changes: 28 additions & 13 deletions src/specklepy/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@

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`.
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)
To authenticate the client, you'll need to have downloaded
the [Speckle Manager](https://speckle.guide/#speckle-manager)
and added your account.
```py
Expand Down Expand Up @@ -92,15 +95,22 @@ def __init__(self, host: str = DEFAULT_HOST, use_ssl: bool = USE_SSL) -> None:
# ) from ex

def __repr__(self):
return f"SpeckleClient( server: {self.url}, authenticated: {self.account.token is not None} )"
return (
f"SpeckleClient( server: {self.url}, authenticated:"
f" {self.account.token is not None} )"
)

@deprecated(
version="2.6.0",
reason="Renamed: please use `authenticate_with_account` or `authenticate_with_token` instead.",
reason=(
"Renamed: please use `authenticate_with_account` or"
" `authenticate_with_token` instead."
),
)
def authenticate(self, token: str) -> None:
"""Authenticate the client using a personal access token
The token is saved in the client object and a synchronous GraphQL entrypoint is created
The token is saved in the client object and a synchronous GraphQL
entrypoint is created
Arguments:
token {str} -- an api token
Expand All @@ -109,8 +119,10 @@ def authenticate(self, token: str) -> None:
self._set_up_client()

def authenticate_with_token(self, token: str) -> None:
"""Authenticate the client using a personal access token
The token is saved in the client object and a synchronous GraphQL entrypoint is created
"""
Authenticate the client using a personal access token.
The token is saved in the client object and a synchronous GraphQL
entrypoint is created
Arguments:
token {str} -- an api token
Expand All @@ -121,10 +133,12 @@ def authenticate_with_token(self, token: str) -> None:

def authenticate_with_account(self, account: Account) -> None:
"""Authenticate the client using an Account object
The account is saved in the client object and a synchronous GraphQL entrypoint is created
The account is saved in the client object and a synchronous GraphQL
entrypoint is created
Arguments:
account {Account} -- the account object which can be found with `get_default_account` or `get_local_accounts`
account {Account} -- the account object which can be found with
`get_default_account` or `get_local_accounts`
"""
metrics.track(metrics.CLIENT, account, {"name": "authenticate with account"})
self.account = account
Expand Down Expand Up @@ -153,7 +167,8 @@ def _set_up_client(self) -> None:
if self.user.get() is None:
warn(
SpeckleWarning(
f"Possibly invalid token - could not authenticate Speckle Client for server {self.url}"
"Possibly invalid token - could not authenticate Speckle Client"
f" for server {self.url}"
)
)

Expand All @@ -167,7 +182,7 @@ def _init_resources(self) -> None:
server_version = None
try:
server_version = self.server.version()
except:
except Exception:
pass
self.user = user.Resource(
account=self.account,
Expand Down Expand Up @@ -214,7 +229,7 @@ def __getattr__(self, name):
return attr.Resource(
account=self.account, basepath=self.url, client=self.httpclient
)
except:
except AttributeError:
raise SpeckleException(
f"Method {name} is not supported by the SpeckleClient class"
)
22 changes: 16 additions & 6 deletions src/specklepy/api/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Account(BaseModel):
id: Optional[str] = None

def __repr__(self) -> str:
return f"Account(email: {self.userInfo.email}, server: {self.serverInfo.url}, isDefault: {self.isDefault})"
return (
f"Account(email: {self.userInfo.email}, server: {self.serverInfo.url},"
f" isDefault: {self.isDefault})"
)

def __str__(self) -> str:
return self.__repr__()
Expand All @@ -45,7 +48,8 @@ def get_local_accounts(base_path: Optional[str] = None) -> List[Account]:
base_path {str} -- custom base path if you are not using the system default
Returns:
List[Account] -- list of all local accounts or an empty list if no accounts were found
List[Account] -- list of all local accounts or an empty list if
no accounts were found
"""
accounts: List[Account] = []
try:
Expand Down Expand Up @@ -95,7 +99,9 @@ def get_local_accounts(base_path: Optional[str] = None) -> List[Account]:


def get_default_account(base_path: Optional[str] = None) -> Optional[Account]:
"""Gets this environment's default account if any. If there is no default, the first found will be returned and set as default.
"""
Gets this environment's default account if any. If there is no default,
the first found will be returned and set as default.
Arguments:
base_path {str} -- custom base path if you are not using the system default
Expand All @@ -121,7 +127,8 @@ def get_account_from_token(token: str, server_url: str = None) -> Account:
token {str} -- the api token
Returns:
Account -- the local account with this token or a shell account containing just the token and url if no local account is found
Account -- the local account with this token or a shell account containing
just the token and url if no local account is found
"""
accounts = get_local_accounts()
if not accounts:
Expand All @@ -145,6 +152,9 @@ def get_account_from_token(token: str, server_url: str = None) -> Account:
class StreamWrapper:
def __init__(self, url: str = None) -> None:
raise SpeckleException(
message="The StreamWrapper has moved as of v2.6.0! Please import from specklepy.api.wrapper",
exception=DeprecationWarning,
message=(
"The StreamWrapper has moved as of v2.6.0! Please import from"
" specklepy.api.wrapper"
),
exception=DeprecationWarning(),
)
33 changes: 27 additions & 6 deletions src/specklepy/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ class Commit(BaseModel):
parents: Optional[List[str]]

def __repr__(self) -> str:
return f"Commit( id: {self.id}, message: {self.message}, referencedObject: {self.referencedObject}, authorName: {self.authorName}, branchName: {self.branchName}, createdAt: {self.createdAt} )"
return (
f"Commit( id: {self.id}, message: {self.message}, referencedObject:"
f" {self.referencedObject}, authorName: {self.authorName}, branchName:"
f" {self.branchName}, createdAt: {self.createdAt} )"
)

def __str__(self) -> str:
return self.__repr__()
Expand Down Expand Up @@ -75,7 +79,10 @@ class Stream(BaseModel):
favoritesCount: Optional[int] = None

def __repr__(self):
return f"Stream( id: {self.id}, name: {self.name}, description: {self.description}, isPublic: {self.isPublic})"
return (
f"Stream( id: {self.id}, name: {self.name}, description:"
f" {self.description}, isPublic: {self.isPublic})"
)

def __str__(self) -> str:
return self.__repr__()
Expand All @@ -99,7 +106,10 @@ class User(BaseModel):
streams: Optional[Streams]

def __repr__(self):
return f"User( id: {self.id}, name: {self.name}, email: {self.email}, company: {self.company} )"
return (
f"User( id: {self.id}, name: {self.name}, email: {self.email}, company:"
f" {self.company} )"
)

def __str__(self) -> str:
return self.__repr__()
Expand Down Expand Up @@ -129,7 +139,11 @@ class PendingStreamCollaborator(BaseModel):
token: Optional[str]

def __repr__(self):
return f"PendingStreamCollaborator( inviteId: {self.inviteId}, streamId: {self.streamId}, role: {self.role}, title: {self.title}, invitedBy: {self.user.name if self.user else None})"
return (
f"PendingStreamCollaborator( inviteId: {self.inviteId}, streamId:"
f" {self.streamId}, role: {self.role}, title: {self.title}, invitedBy:"
f" {self.user.name if self.user else None})"
)

def __str__(self) -> str:
return self.__repr__()
Expand All @@ -146,7 +160,10 @@ class Activity(BaseModel):
time: Optional[datetime]

def __repr__(self) -> str:
return f"Activity( streamId: {self.streamId}, actionType: {self.actionType}, message: {self.message}, userId: {self.userId} )"
return (
f"Activity( streamId: {self.streamId}, actionType: {self.actionType},"
f" message: {self.message}, userId: {self.userId} )"
)

def __str__(self) -> str:
return self.__repr__()
Expand All @@ -158,7 +175,11 @@ class ActivityCollection(BaseModel):
cursor: Optional[datetime]

def __repr__(self) -> str:
return f"ActivityCollection( totalCount: {self.totalCount}, items: {len(self.items) if self.items else 0}, cursor: {self.cursor.isoformat() if self.cursor else None} )"
return (
f"ActivityCollection( totalCount: {self.totalCount}, items:"
f" {len(self.items) if self.items else 0}, cursor:"
f" {self.cursor.isoformat() if self.cursor else None} )"
)

def __str__(self) -> str:
return self.__repr__()
Expand Down
Loading

0 comments on commit 990cf4e

Please sign in to comment.