diff --git a/src/pyshape/__init__.py b/src/pyshape/__init__.py
index 7430b38..76692ae 100644
--- a/src/pyshape/__init__.py
+++ b/src/pyshape/__init__.py
@@ -1 +1,12 @@
+import sys
+from loguru import logger
+
+logger.remove()
+logger.add(
+ sys.stdout,
+ colorize=True,
+ format="{level: <8} | {message}",
+)
+
+
from pyshape.client import Client
diff --git a/src/pyshape/api/rest_api.py b/src/pyshape/api/rest_api.py
index 0081d6b..197faa8 100644
--- a/src/pyshape/api/rest_api.py
+++ b/src/pyshape/api/rest_api.py
@@ -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
@@ -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)}"
@@ -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)}"
)
diff --git a/src/pyshape/elements/partstudio.py b/src/pyshape/elements/partstudio.py
index 0443a72..86e2ce3 100644
--- a/src/pyshape/elements/partstudio.py
+++ b/src/pyshape/elements/partstudio.py
@@ -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
@@ -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),
diff --git a/src/pyshape/features/entities/base.py b/src/pyshape/features/entities/base.py
index 2feb58a..453aed6 100644
--- a/src/pyshape/features/entities/base.py
+++ b/src/pyshape/features/entities/base.py
@@ -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: ...
diff --git a/src/pyshape/features/entities/sketch_entities.py b/src/pyshape/features/entities/sketch_entities.py
index bf950a0..ff2b5f7 100644
--- a/src/pyshape/features/entities/sketch_entities.py
+++ b/src/pyshape/features/entities/sketch_entities.py
@@ -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):
@@ -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})"
diff --git a/src/pyshape/features/sketch.py b/src/pyshape/features/sketch.py
index 9c02ef9..3ae934c 100644
--- a/src/pyshape/features/sketch.py
+++ b/src/pyshape/features/sketch.py
@@ -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:
@@ -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(
diff --git a/src/pyshape/util/credentials.py b/src/pyshape/util/credentials.py
index 0acb337..614f0ff 100644
--- a/src/pyshape/util/credentials.py
+++ b/src/pyshape/util/credentials.py
@@ -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:"
@@ -125,7 +125,7 @@ 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
@@ -133,7 +133,7 @@ def fetch_or_prompt() -> tuple[str, str]:
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