Skip to content

Commit

Permalink
Some reformatting and cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
daveraja committed May 6, 2024
1 parent 49d4d3a commit ee74651
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 6 deletions.
4 changes: 3 additions & 1 deletion clorm/_clingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def _check_is_func(obj: Any, name: str) -> None:
# Wrap clingo.Model and override some functions
# ------------------------------------------------------------------------------


# class Model(OModel, metaclass=WrapperMetaClass):
class ModelOverride(object):
"""Provides access to a model during a solve call.
Expand Down Expand Up @@ -236,6 +237,7 @@ class ClormSolveHandle(SolveHandleOverride, OSolveHandle):
# Wrap clingo.Control and override some functions
# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------
# Helper functions to expand the assumptions list as part of a solve() call. The
# assumptions list is a list of argument-boolean pairs where the argument can be
Expand All @@ -255,7 +257,7 @@ def _add_fact(fact: Union[Predicate, Symbol], bval: bool) -> None:
clingo_assump.append((raw, bool(bval)))

try:
for (arg, bval) in assumptions:
for arg, bval in assumptions:
if isinstance(arg, Predicate):
_add_fact(arg, bval)
elif isinstance(arg, Iterable):
Expand Down
9 changes: 8 additions & 1 deletion clorm/orm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def __hash__(self):
# conditions and other boolean conditions.
# ------------------------------------------------------------------------------


# comparator functions that always return true (or false). This is useful for
# the cross product join operator that always returns true
def trueall(x, y):
Expand Down Expand Up @@ -1205,6 +1206,7 @@ def kwargs_check_keys(validkeys, inputkeys):
# a field") between python and clingo.
# ------------------------------------------------------------------------------


# Create the pytocl and cltopy class member functions. If their inherit directly
# from BaseField then just return the result of the function. If they inherit
# from a sub-class of BaseField then call the parents conversion function first.
Expand Down Expand Up @@ -1290,6 +1292,7 @@ def _raise_pytocl_nie(v):
# and unifies, and the properties: default and has_default
# ------------------------------------------------------------------------------


# Mixin class to be able to use both MetaClasses
class _AbstractBaseFieldMeta(abc.ABCMeta, _BaseFieldMeta):
pass
Expand Down Expand Up @@ -1817,6 +1820,7 @@ def _process_field_definition(field_defn: _FieldDefinition) -> Type[BaseField]:
# restricts the allowable values.
# ------------------------------------------------------------------------------


# Support for refine_field
def _refine_field_functor(subclass_name, field_class, valfunc):
def _test_value(v):
Expand Down Expand Up @@ -2563,11 +2567,11 @@ def _magic_name(name):

PathIdentity = collections.namedtuple("PathIdentity", "predicate name")


# --------------------------------------------------------------------------
# One PredicateDefn object for each Predicate sub-class
# --------------------------------------------------------------------------
class PredicateDefn(object):

"""Encapsulates some meta-data for a Predicate definition.
Each Predicate class will have a corresponding PredicateDefn object that specifies some
Expand Down Expand Up @@ -2828,6 +2832,7 @@ def _set_fn(fname: str, docstring: str):
# Metaclass constructor support functions to create the fields
# ------------------------------------------------------------------------------


# Generate a default predicate name from the Predicate class name.
def _predicatedefn_default_predicate_name(class_name):

Expand Down Expand Up @@ -3266,6 +3271,7 @@ def __iter__(self) -> Iterator[PredicatePath]:
# underlying Symbol object.
# ------------------------------------------------------------------------------


# Mixin class to be able to use both MetaClasses
class _AbstractPredicateMeta(abc.ABCMeta, _PredicateMeta):
pass
Expand Down Expand Up @@ -3546,6 +3552,7 @@ def simple_predicate(
# Internal supporting functions
# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------
# Helper function to check if all the paths in a collection are root paths and
# return path objects.
Expand Down
1 change: 1 addition & 0 deletions clorm/orm/noclingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
will raise an exception.
"""

# --------------------------------------------------------------------------------
# --------------------------------------------------------------------------------

Expand Down
5 changes: 4 additions & 1 deletion clorm/orm/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
# Defining and manipulating conditional elements
# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------
# Placeholder allows for variable substituion of a query. Placeholder is
# an abstract class that exposes no API other than its existence.
# ------------------------------------------------------------------------------
class Placeholder(abc.ABC):

r"""An abstract class for defining parameterised queries.
Currently, Clorm supports 4 placeholders: ph1\_, ph2\_, ph3\_, ph4\_. These
Expand Down Expand Up @@ -514,6 +514,7 @@ def membership_op_keyable(sc, indexes):
# is not exposed outside clorm.
# ------------------------------------------------------------------------------


# Helper function to try to convert Python tuples into a matching clorm anon tuple. With this
# we can pass a Python tuple to a query and not have to overload the Predicate comparison
# operator and hash function to match the tuple.
Expand Down Expand Up @@ -2233,6 +2234,7 @@ def num(sc):
# describes the plan to execute a single link in a join.
# ------------------------------------------------------------------------------


# Check that the formula only refers to paths with the allowable roots
def _check_roots(allowable_roots, formula):
if not formula:
Expand Down Expand Up @@ -3067,6 +3069,7 @@ def make_query_plan(indexed_paths, qspec):
# generating an actual query.
# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------
# Creates a mechanism for sorting using the order_by statements within queries.
#
Expand Down
1 change: 1 addition & 0 deletions clorm/orm/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def expand_template(template: str, **kwargs: str) -> str:
line to preserve the correct indentation.
"""

# Add spaces to each line of some multi-text input
def add_spaces(num, text):
space = " " * num
Expand Down
1 change: 1 addition & 0 deletions tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Support functions for the unit tests
# ------------------------------------------------------------------------------


# ------------------------------------------------------------------------------
# Helper function for helping to test for good error messages.
# ------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions tests/test_orm_atsyntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ def test_register(self):
SF = StringField
IF = IntegerField
CF = ConstantField

# Functions to add to the context
def add(a: IF, b: IF) -> IF:
return a + b
Expand Down
15 changes: 12 additions & 3 deletions tests/test_orm_factbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,25 @@ class Meta:
# Test the asp output string with the sorted flag
# --------------------------------------------------------------------------
def test_factbase_aspstr_sorted(self):
class A(Predicate, name="bb"):
class A(Predicate):
a = IntegerField

class B(Predicate, name="aa"):
class Meta:
name = "bb"

class B(Predicate):
a = IntegerField

class C(Predicate, name="aa"):
class Meta:
name = "aa"

class C(Predicate):
a = IntegerField
b = IntegerField

class Meta:
name = "aa"

def tostr(facts):
return ".\n".join([str(f) for f in facts])

Expand Down
1 change: 1 addition & 0 deletions tests/test_orm_symbols_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Fun(ComplexTerm):

anum = IntegerField()
afun = Fun.Field()

# afun=ComplexField(Fun)
class Meta:
name = "afact"
Expand Down

0 comments on commit ee74651

Please sign in to comment.