Skip to content

Commit

Permalink
Cleanup output (#11)
Browse files Browse the repository at this point in the history
* updated format

* add outputs

* lint
  • Loading branch information
kyle-tennison authored Apr 26, 2024
1 parent 4f43c59 commit 4ea4c58
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/pyshape/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
import sys
from loguru import logger

logger.remove()
logger.add(
sys.stdout,
colorize=True,
format="<level>{level: <8}</level> | <level>{message}</level>",
)


from pyshape.client import Client
6 changes: 4 additions & 2 deletions src/pyshape/api/rest_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Rest Api interface to OnShape server"""

import json
import sys
from pyshape.api.endpoints import EndpointContainer
from pyshape.api.model import ApiModel
from pyshape.util.model import HttpMethod
Expand Down Expand Up @@ -69,7 +70,8 @@ def http_wrap[
if isinstance(payload, ApiModel):
payload_json = payload.model_dump(exclude_none=True)

logger.debug(
logger.debug(f"{http_method.name} {endpoint}")
logger.trace(
f"Calling {http_method.name} {endpoint}"
+ (
f" with payload:\n{json.dumps(payload_json, indent=4)}"
Expand All @@ -92,7 +94,7 @@ def http_wrap[
response_dict: dict = {} # allow empty responses
else:
response_dict = r.json()
logger.debug(
logger.trace(
f"{http_method.name} {endpoint} responded with:\n"
f"{json.dumps(response_dict, indent=4)}"
)
Expand Down
3 changes: 0 additions & 3 deletions src/pyshape/elements/partstudio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""PartStudio element interface"""

from pprint import pprint
from loguru import logger
from pyshape.elements.base import Element
import pyshape.api.model as model
Expand Down Expand Up @@ -73,8 +72,6 @@ def add_feature(self, feature: Feature):

fm = feature._to_model()

pprint(fm.model_dump(exclude_none=True))

response = self._api.endpoints.add_feature(
document_id=self.document.id,
version=WorkspaceWVM(self.document.default_workspace.id),
Expand Down
6 changes: 6 additions & 0 deletions src/pyshape/features/entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ def to_model(self) -> model.FeatureEntity:
def generate_entity_id(self) -> str:
"""Generates a random entity id"""
return str(uuid.uuid4()).replace("-", "")

def __str__(self) -> str:
return repr(self)

@abstractmethod
def __repr__(self) -> str: ...
10 changes: 6 additions & 4 deletions src/pyshape/features/entities/sketch_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def to_model(self) -> model.SketchCurveEntity:
entityId=f"{self.entity_id}",
)

@override
def __repr__(self) -> str:
return f"Circle(radius={self.radius}, center={self.center})"


class SketchLine(Entity):

Expand Down Expand Up @@ -86,8 +90,6 @@ def to_model(self) -> model.SketchCurveSegmentEntity:
},
)

def __str__(self) -> str:
return repr(self)

@override
def __repr__(self) -> str:
return f"SketchLine(start={self.start}, end={self.end})"
return f"Line(start={self.start}, end={self.end})"
5 changes: 5 additions & 0 deletions src/pyshape/features/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def add_circle(self, center: tuple[float, float], radius: float) -> None:
entity = SketchCircle(
radius=radius, center=center_point, units=self._client.units
)

logger.info(f"Added circle to sketch: {entity}")

self._entities.append(entity)

def add_line(self, start: tuple[float, float], end: tuple[float, float]) -> None:
Expand All @@ -71,6 +74,8 @@ def add_line(self, start: tuple[float, float], end: tuple[float, float]) -> None

entity = SketchLine(start_point, end_point, self._client.units)

logger.info(f"Added line to sketch: {entity}")

self._entities.append(entity)

def trace_points(
Expand Down
6 changes: 3 additions & 3 deletions src/pyshape/util/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def fetch_or_prompt() -> tuple[str, str]:
if tokens:
return tokens

print(
logger.error(
"pyshape needs your OnShape credentials. \n"
"navagate to https://dev-portal.onshape.com/keys and generate a pair of "
"access & secret keys. Paste them here when prompted:"
Expand All @@ -125,15 +125,15 @@ def fetch_or_prompt() -> tuple[str, str]:
secret_key = input("secret key: ")

if not CredentialManager.is_secret_key(secret_key):
print(
logger.error(
"the key you entered does not match the expected pattern of a secret key. please try again."
)
continue

access_key = input("access key: ")

if not CredentialManager.is_access_key(access_key):
print(
logger.error(
"the key you entered does not match the expected pattern of a access key. please try again."
)
continue
Expand Down

0 comments on commit 4ea4c58

Please sign in to comment.