Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
RUN apt update && export DEBIAN_FRONTEND=noninteractive && apt -y install clangd-19 clang-tidy-19 python3-pip
RUN apt update && export DEBIAN_FRONTEND=noninteractive && apt -y install clangd-19 clang-tidy-19 python3-pip python3.12-venv
RUN update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-19 100
RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-19 100

2 changes: 1 addition & 1 deletion py/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
semver >= 3.0
jsonlogic-py == 0.2
jsonlogic-py == 0.2.1
2 changes: 1 addition & 1 deletion py/src/clippy/backends/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 21 additions & 21 deletions py/src/clippy/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,51 @@ class Selector(jl.Variable):

def __init__(self, parent: Selector | None, name: str, docstr: str):
super().__init__(name, docstr) # op and o2 are None to represent this as a variable.
self.parent = parent
self.name = name
self.fullname: str = self.name if self.parent is None else f"{self.parent.fullname}.{self.name}"
self.subselectors: set[Selector] = set()
self._parent = parent
self._name = name
self._fullname: str = self._name if self._parent is None else f"{self._parent._fullname}.{self._name}"
self._subselectors: set[Selector] = set()

def __hash__(self):
return hash(self.fullname)
return hash(self._fullname)

def prepare(self):
return {"var": self.fullname}
def _prepare(self):
return {"var": self._fullname}

def hierarchy(self, acc: list[tuple[str, str]] | None = None):
def _hierarchy(self, acc: list[tuple[str, str]] | None = None):
if acc is None:
acc = []
acc.append((self.fullname, self.__doc__ or ""))
for subsel in self.subselectors:
subsel.hierarchy(acc)
acc.append((self._fullname, self.__doc__ or ""))
for subsel in self._subselectors:
subsel._hierarchy(acc)
return acc

def describe(self):
hier = self.hierarchy()
def _describe(self):
hier = self._hierarchy()
maxlen = max(len(sub_desc[0]) for sub_desc in hier)
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}
def _to_serial(self):
return {"var": self._fullname}

def _add_subselector(self, name: str, docstr: str):
"""add a subselector to this selector"""
subsel = Selector(self, name, docstr)
setattr(self, name, subsel)
self.subselectors.add(subsel)
self._subselectors.add(subsel)

def _del_subselector(self, name: str):
delattr(self, name)
self.subselectors.remove(getattr(self, name))
self._subselectors.remove(getattr(self, name))

def _clear_subselectors(self):
"""removes all subselectors"""
for subsel in self.subselectors:
delattr(self, subsel.name)
self.subselectors = set()
for subsel in self._subselectors:
delattr(self, subsel._name)
self._subselectors = set()

def _import_from_dict(self, d: AnyDict, merge: bool = False):
"""Imports subselectors from a dictionary.
Expand Down
Loading