From 4638957faf0c7e36d59940426fa00a3d1fe55fb8 Mon Sep 17 00:00:00 2001 From: nh916 Date: Mon, 24 Jul 2023 14:55:05 -0700 Subject: [PATCH 1/6] wrote a print statement to show things are happening in the background and it is not just standing still --- src/cript/api/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cript/api/api.py b/src/cript/api/api.py index caeef8c23..26c764414 100644 --- a/src/cript/api/api.py +++ b/src/cript/api/api.py @@ -475,6 +475,8 @@ def _is_node_schema_valid(self, node_json: str, is_patch: bool = False) -> bool: whether the node JSON is valid or not """ + print("validating nodes") + db_schema = self._get_db_schema() node_dict = json.loads(node_json) From 6c4237206af33e0bb05feaa6b8b81ba718ef1cb0 Mon Sep 17 00:00:00 2001 From: nh916 Date: Tue, 25 Jul 2023 13:11:39 -0700 Subject: [PATCH 2/6] changing the validation terminal feedback from print to log statement the log statement is generally better practice and has better UX --- src/cript/api/api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cript/api/api.py b/src/cript/api/api.py index 26c764414..950e0ca19 100644 --- a/src/cript/api/api.py +++ b/src/cript/api/api.py @@ -1,5 +1,6 @@ import copy import json +import logging import os import uuid import warnings @@ -475,8 +476,6 @@ def _is_node_schema_valid(self, node_json: str, is_patch: bool = False) -> bool: whether the node JSON is valid or not """ - print("validating nodes") - db_schema = self._get_db_schema() node_dict = json.loads(node_json) @@ -492,6 +491,10 @@ def _is_node_schema_valid(self, node_json: str, is_patch: bool = False) -> bool: else: raise CRIPTJsonNodeError(node_list, str(node_list)) + # 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 From f1dc7a2c232389baaa6b8e3551421e84932b56a1 Mon Sep 17 00:00:00 2001 From: nh916 Date: Tue, 25 Jul 2023 13:21:24 -0700 Subject: [PATCH 3/6] give user the ability to turn off the terminal logs --- src/cript/api/api.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cript/api/api.py b/src/cript/api/api.py index 950e0ca19..392c56f3c 100644 --- a/src/cript/api/api.py +++ b/src/cript/api/api.py @@ -55,6 +55,8 @@ class API: API Client class to communicate with the CRIPT API """ + verbose: bool = True + _host: str = "" _api_token: str = "" _storage_token: str = "" @@ -491,9 +493,11 @@ def _is_node_schema_valid(self, node_json: str, is_patch: bool = False) -> bool: else: raise CRIPTJsonNodeError(node_list, str(node_list)) - # 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...") + 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 From 3fa643ab55df525d3051e7eb1bc14a500f7940b0 Mon Sep 17 00:00:00 2001 From: nh916 Date: Tue, 25 Jul 2023 13:22:45 -0700 Subject: [PATCH 4/6] added comment for `verbose` class variable --- src/cript/api/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cript/api/api.py b/src/cript/api/api.py index 392c56f3c..7c8b8b720 100644 --- a/src/cript/api/api.py +++ b/src/cript/api/api.py @@ -55,6 +55,7 @@ class API: API Client class to communicate with the CRIPT API """ + # dictates whether the user wants to see terminal log statements or not verbose: bool = True _host: str = "" From e7f77abb86a611479a3c42e798b7d4e6c9c9d106 Mon Sep 17 00:00:00 2001 From: nh916 Date: Tue, 25 Jul 2023 13:46:13 -0700 Subject: [PATCH 5/6] formatting for trunk * formatted api.py with black * added `levelname` to cspell for python the logger --- .trunk/configs/.cspell.json | 3 ++- src/cript/api/api.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.trunk/configs/.cspell.json b/.trunk/configs/.cspell.json index 0d8bee15a..feea89f80 100644 --- a/.trunk/configs/.cspell.json +++ b/.trunk/configs/.cspell.json @@ -99,6 +99,7 @@ "openmm", "equi", "Navid", - "ipykernel" + "ipykernel", + "levelname" ] } diff --git a/src/cript/api/api.py b/src/cript/api/api.py index 7c8b8b720..862176002 100644 --- a/src/cript/api/api.py +++ b/src/cript/api/api.py @@ -497,7 +497,7 @@ def _is_node_schema_valid(self, node_json: str, is_patch: bool = False) -> bool: 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.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 From 75f7cd2eaad31a743447575e68f87fde4638a191 Mon Sep 17 00:00:00 2001 From: nh916 Date: Tue, 25 Jul 2023 14:43:41 -0700 Subject: [PATCH 6/6] wrote documentation for `cript.API.verbose` --- src/cript/api/api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/cript/api/api.py b/src/cript/api/api.py index 862176002..b83f7c6fd 100644 --- a/src/cript/api/api.py +++ b/src/cript/api/api.py @@ -53,6 +53,23 @@ 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