From 8aad98bcee5d46a7e6b54de158e17c81f1f784d3 Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Fri, 16 Jan 2026 01:48:40 +0000 Subject: [PATCH 1/2] updated jsonlogic to 0.2.1, fixed prepare -> _prepare, and added loglevel as state so that YGM can use it --- py/requirements.txt | 2 +- py/src/clippy/backends/fs/__init__.py | 5 +++++ py/src/clippy/backends/serialization.py | 2 +- py/src/clippy/constants.py | 4 +++- py/src/clippy/selectors.py | 4 ++-- test/run_ipython.sh | 6 ++++++ 6 files changed, 18 insertions(+), 5 deletions(-) create mode 100755 test/run_ipython.sh diff --git a/py/requirements.txt b/py/requirements.txt index 321477a..c6bcb4a 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -1,2 +1,2 @@ semver >= 3.0 -jsonlogic-py == 0.2 +jsonlogic-py == 0.2.1 diff --git a/py/src/clippy/backends/fs/__init__.py b/py/src/clippy/backends/fs/__init__.py index e49b2b7..6ce9b5f 100644 --- a/py/src/clippy/backends/fs/__init__.py +++ b/py/src/clippy/backends/fs/__init__.py @@ -202,6 +202,11 @@ def m(self, *args, **kwargs): # .. add state # argdict[STATE_KEY] = self._state argdict[clippy_constants.STATE_KEY] = getattr(self, clippy_constants.STATE_KEY) + + # explicitly add loglevel to state if it doesn't already exist. + argdict[clippy_constants.STATE_KEY][clippy_constants.LOGLEVEL_KEY] = self.logger.getEffectiveLevel() # Returns python integer that gets converted by cpp + + # ~ for key in statedesc: # ~ statej[key] = getattr(self, key) diff --git a/py/src/clippy/backends/serialization.py b/py/src/clippy/backends/serialization.py index 7a8f626..f1f8257 100644 --- a/py/src/clippy/backends/serialization.py +++ b/py/src/clippy/backends/serialization.py @@ -118,7 +118,7 @@ def encode_clippy_json(o: Any) -> Any: json encoder that is clippy-object aware. """ if isinstance(o, jl.Operand): # expression or variable - return {"expression_type": "jsonlogic", "rule": o.prepare()} + return {"expression_type": "jsonlogic", "rule": o._prepare()} return o diff --git a/py/src/clippy/constants.py b/py/src/clippy/constants.py index acdc4e7..820b479 100644 --- a/py/src/clippy/constants.py +++ b/py/src/clippy/constants.py @@ -1,3 +1,4 @@ +import logging """Clippy constants.""" # These should probably not be changed, which is why they're not in config. @@ -23,7 +24,8 @@ REFERENCE_KEY = "references" # key to json entry that holds return data from backend functions. RETURN_KEY = "returns" - +# key inside STATE_KEY that provides state information for the loglevel +LOGLEVEL_KEY = "loglevel" # these keys are returned from the _help output when creating methods # for classes. diff --git a/py/src/clippy/selectors.py b/py/src/clippy/selectors.py index 5854606..bc07b3e 100644 --- a/py/src/clippy/selectors.py +++ b/py/src/clippy/selectors.py @@ -21,7 +21,7 @@ def __init__(self, parent: Selector | None, name: str, docstr: str): def __hash__(self): return hash(self.fullname) - def prepare(self): + def _prepare(self): return {"var": self.fullname} def hierarchy(self, acc: list[tuple[str, str]] | None = None): @@ -38,7 +38,7 @@ def describe(self): return "\n".join(f"{sub_desc[0]:<{maxlen + 2}} {sub_desc[1]}" for sub_desc in hier) def __str__(self): - return repr(self.prepare()) + return repr(self._prepare()) def to_serial(self): return {"var": self.fullname} diff --git a/test/run_ipython.sh b/test/run_ipython.sh new file mode 100755 index 0000000..849661c --- /dev/null +++ b/test/run_ipython.sh @@ -0,0 +1,6 @@ +#!/bin/sh +PROJ_ROOT_DIR=$(pwd)/.. +CPP_BUILD_DIR=$PROJ_ROOT_DIR/cpp/build +export PYTHONPATH=$PROJ_ROOT_DIR/py/src:$PYTHONPATH +export CLIPPY_BACKEND_PATH=$CPP_BUILD_DIR/examples +CLIPPY_LOGLEVEL=DEBUG ipython From 4c6b3ae585b5e26b571a44fc857989d0e3e977a7 Mon Sep 17 00:00:00 2001 From: Seth Bromberger Date: Fri, 16 Jan 2026 03:00:56 +0000 Subject: [PATCH 2/2] lint fixes --- py/src/clippy/backends/fs/__init__.py | 3 ++- py/src/clippy/constants.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/py/src/clippy/backends/fs/__init__.py b/py/src/clippy/backends/fs/__init__.py index 6ce9b5f..2cfde7d 100644 --- a/py/src/clippy/backends/fs/__init__.py +++ b/py/src/clippy/backends/fs/__init__.py @@ -204,7 +204,8 @@ def m(self, *args, **kwargs): argdict[clippy_constants.STATE_KEY] = getattr(self, clippy_constants.STATE_KEY) # explicitly add loglevel to state if it doesn't already exist. - argdict[clippy_constants.STATE_KEY][clippy_constants.LOGLEVEL_KEY] = self.logger.getEffectiveLevel() # Returns python integer that gets converted by cpp + argdict[clippy_constants.STATE_KEY][clippy_constants.LOGLEVEL_KEY] = self.logger.getEffectiveLevel() + # Returns python integer that gets converted by cpp # ~ for key in statedesc: diff --git a/py/src/clippy/constants.py b/py/src/clippy/constants.py index 820b479..5bdbc49 100644 --- a/py/src/clippy/constants.py +++ b/py/src/clippy/constants.py @@ -1,4 +1,3 @@ -import logging """Clippy constants.""" # These should probably not be changed, which is why they're not in config.