Skip to content

Commit

Permalink
UX: Node Validation Terminal Log Output (#221)
Browse files Browse the repository at this point in the history
* wrote a print statement to show things are happening in the background and it is not just standing still

* changing the validation terminal feedback from print to log statement

the log statement is generally better practice and has better UX

* give user the ability to turn off the terminal logs

* added comment for `verbose` class variable

* formatting for trunk

* formatted api.py with black
* added `levelname` to cspell for python the logger

* wrote documentation for `cript.API.verbose`
  • Loading branch information
nh916 authored Jul 26, 2023
1 parent a3c7075 commit 730a661
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .trunk/configs/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"openmm",
"equi",
"Navid",
"ipykernel"
"ipykernel",
"levelname"
]
}
27 changes: 27 additions & 0 deletions src/cript/api/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import json
import logging
import os
import uuid
import warnings
Expand Down Expand Up @@ -52,8 +53,28 @@ class API:
"""
## Definition
API Client class to communicate with the CRIPT API
Attributes
----------
verbose : bool
A boolean flag that controls whether verbose logging is enabled or not.
When `verbose` is set to `True`, the class will provide additional detailed logging
to the terminal. This can be useful for debugging and understanding the internal
workings of the class.
When `verbose` is set to `False`, the class will only provide essential and concise
logging information, making the terminal output less cluttered and more user-friendly.
```python
# turn off the terminal logs
api.verbose = False
```
"""

# dictates whether the user wants to see terminal log statements or not
verbose: bool = True

_host: str = ""
_api_token: str = ""
_storage_token: str = ""
Expand Down Expand Up @@ -490,6 +511,12 @@ def _is_node_schema_valid(self, node_json: str, is_patch: bool = False) -> bool:
else:
raise CRIPTJsonNodeError(node_list, str(node_list))

if self.verbose:
# logging out info to the terminal for the user feedback
# (improve UX because the program is currently slow)
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO)
logging.info(f"Validating {node_type} graph...")

# set the schema to test against http POST or PATCH of DB Schema
schema_http_method: str

Expand Down

0 comments on commit 730a661

Please sign in to comment.