def wrapped(*args, **kwargs): was_using_module = clyngor.clingo_module_actived() clyngor.use_clingo_module() ret = func(*args, **kwargs) if not was_using_module: clyngor.use_clingo_binary() return ret
def wrapped(*args, **kwargs): if clyngor.clingo_module_actived(): clyngor.deactivate_clingo_module() ret = func(*args, **kwargs) clyngor.use_clingo_module() else: # clingo module not here, so there is nothing to do ret = func(*args, **kwargs) return ret
def clingo_version(clingo_bin_path: str = None) -> dict: """Return clingo's version information in a dict""" if clyngor.clingo_module_actived(): return { 'clingo version': clingo.__version__, 'python': '3' if clyngor.utils.try_python_availability_in_clingo_module() else None, 'lua': 'yes' if clyngor.utils.try_lua_availability_in_clingo_module() else None, } clingo = subprocess.Popen( [clingo_bin_path or clyngor.CLINGO_BIN_PATH, '--version', '--outf=2'], stderr=subprocess.PIPE, stdout=subprocess.PIPE, ) fields = { 'address model': re.compile(r'Address model: ([3264]{2})-bit'), 'clingo version': re.compile(r'clingo version ([0-9\.]+)'), 'libgringo': re.compile(r'libgringo version ([0-9\.]+)'), 'libclasp': re.compile(r'libclasp version ([0-9\.]+)'), 'libpotassco': re.compile(r'libpotassco version ([0-9\.]+)'), 'python': re.compile(r'with[out]{0,3}\sPython\s?([0-9\.]+)?' ), # later loop will yields None if python is available 'lua': re.compile(r'with[out]{0,3}\sLua\s?([0-9\.]+)?'), # same for lua } stdout = clingo.communicate()[0].decode() values = {} for field, reg in fields.items(): match = reg.search(stdout) values[field] = match.groups()[0] if match else None return values
def try_lua_availability_in_clingo() -> bool: return (try_lua_availability_in_clingo_module if clyngor.clingo_module_actived() else try_lua_availability_in_clingo_binary)()
def try_python_availability_in_clingo(py3=True) -> bool: func = try_python_availability_in_clingo_module if clyngor.clingo_module_actived( ) else try_python_availability_in_clingo_binary return func(py3)