Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aluriak committed Mar 1, 2022
1 parent a1dbeff commit d4abbd5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 8 additions & 3 deletions clyngor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
from clyngor.grounding import solve_from_grounded, grounded_program
from clyngor.inline import ASP
from clyngor.decoder import decode
from clyngor.upapi import converted_types, converted_types_or_symbols
from clyngor.propagators import Propagator, Variable, Main, Constraint


def load_clingo_module() -> bool:
global clingo_module
global clingo_module, clingo_module_available
try:
import clingo
clingo_module = clingo
clingo_module_available = True
except ImportError:
clingo_module = None
clingo_module_available = False

def have_clingo_module() -> bool:
return clingo_module is not None
Expand Down Expand Up @@ -58,8 +59,12 @@ def have_lua_support() -> bool:


load_clingo_module() # just initialize clingo module state, whether it is available or not
# use_clingo_binary() # use binary by default
use_clingo_binary() # use binary by default
# use_clingo_module() # use module by default

if CLINGO_BIN_PATH != 'clingo':
assert get_clingo_binary() == CLINGO_BIN_PATH


# last, clyngor depending modules
from clyngor.upapi import converted_types, converted_types_or_symbols
6 changes: 4 additions & 2 deletions clyngor/upapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import math
import inspect
from functools import wraps, partial
import clyngor
from functools import wraps


def _converted_types(ignore_bad_type:bool=True):
Expand All @@ -19,6 +20,8 @@ def _converted_types(ignore_bad_type:bool=True):
ignore_bad_type -- Non-conformant types are ignored.
"""
if not clyngor.have_python_support() or not clyngor.clingo_module_available:
return clyngor.utils.null_decorator
from clingo import symbol
def clingo_to_python(val:symbol, annot:type) -> object:
if annot is None or not type(val).__name__ == 'Symbol':
Expand Down Expand Up @@ -87,6 +90,5 @@ def decorated(*args, **kwargs):
return decorated
return decorator


converted_types = _converted_types(True)
converted_types_or_symbols = _converted_types(False)
7 changes: 7 additions & 0 deletions clyngor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,10 @@ def try_lua_availability_in_clingo_module() -> bool:
return False
else: # lua support available
return True


def null_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func(func, *args, **kwargs)
return wrapper

0 comments on commit d4abbd5

Please sign in to comment.