summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/python/CMakeLists.txt37
-rw-r--r--src/api/python/cvc4.pxi12
-rwxr-xr-xsrc/api/python/genkinds.py2
-rw-r--r--src/api/python/setup.py.in31
4 files changed, 67 insertions, 15 deletions
diff --git a/src/api/python/CMakeLists.txt b/src/api/python/CMakeLists.txt
index 166a728de..1998954e5 100644
--- a/src/api/python/CMakeLists.txt
+++ b/src/api/python/CMakeLists.txt
@@ -23,7 +23,7 @@ add_custom_target(
"${PYTHON_EXECUTABLE}"
"${CMAKE_CURRENT_LIST_DIR}/genkinds.py"
--kinds-header "${PROJECT_SOURCE_DIR}/src/api/cvc4cppkind.h"
- --kinds-file-prefix "cvc4kinds"
+ --kinds-file-prefix "${CMAKE_CURRENT_BINARY_DIR}/cvc4kinds"
DEPENDS
genkinds.py
COMMENT
@@ -39,4 +39,37 @@ add_library(pycvc4
target_link_libraries(pycvc4 cvc4 ${PYTHON_LIBRARIES})
python_extension_module(pycvc4)
-install(TARGETS pycvc4 DESTINATION lib)
+
+# Installation based on https://bloerg.net/2012/11/10/cmake-and-distutils.html
+# Create a wrapper python directory and generate a distutils setup.py file
+configure_file(setup.py.in setup.py)
+set(PYCVC4_MODULE "${CMAKE_CURRENT_BINARY_DIR}/pycvc4")
+file(MAKE_DIRECTORY "${PYCVC4_MODULE}")
+file(WRITE ${PYCVC4_MODULE}/__init__.py
+"import sys
+from .pycvc4 import *
+# fake a submodule for dotted imports, e.g. from pycvc4.kinds import *
+sys.modules['%s.%s'%(__name__, kinds.__name__)] = kinds")
+
+set(PYCVC4_LOC "${PYCVC4_MODULE}/$<TARGET_FILE_NAME:pycvc4>")
+add_custom_command(TARGET pycvc4 POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E rename $<TARGET_FILE:pycvc4> ${PYCVC4_LOC}
+)
+
+# figure out if we're in a virtualenv
+execute_process(OUTPUT_VARIABLE IN_VIRTUALENV
+ COMMAND
+ "${PYTHON_EXECUTABLE}"
+ -c
+ "from __future__ import print_function; import os;
+print('YES' if 'VIRTUAL_ENV' in os.environ else 'NO', end='')")
+
+set(INSTALL_CMD "${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install")
+# if we're in a virtualenv, we install it in the virtualenv lib location
+if ("${IN_VIRTUALENV}" STREQUAL "NO")
+ set(INSTALL_CMD "${INSTALL_CMD} --prefix=${CMAKE_INSTALL_PREFIX}")
+endif()
+
+message("Python bindings install command: ${INSTALL_CMD}")
+
+install(CODE "execute_process(COMMAND ${INSTALL_CMD})" FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
diff --git a/src/api/python/cvc4.pxi b/src/api/python/cvc4.pxi
index 39d9d4686..7e0e2e3c8 100644
--- a/src/api/python/cvc4.pxi
+++ b/src/api/python/cvc4.pxi
@@ -231,11 +231,6 @@ cdef class Op:
pass
try:
- indices = kind(<int> self.cop.getIndices[c_Kind]())
- except:
- pass
-
- try:
indices = self.cop.getIndices[uint32_t]()
except:
pass
@@ -553,12 +548,7 @@ cdef class Solver:
def mkReal(self, val, den=None):
cdef Term term = Term()
if den is None:
- try:
- term.cterm = self.csolver.mkReal(str(val).encode())
- except Exception as e:
- raise ValueError("Expecting a number"
- " or a string representing a number"
- " but got: {}".format(val))
+ term.cterm = self.csolver.mkReal(str(val).encode())
else:
if not isinstance(val, int) or not isinstance(den, int):
raise ValueError("Expecting integers when"
diff --git a/src/api/python/genkinds.py b/src/api/python/genkinds.py
index 1e22875e7..4fe7347e6 100755
--- a/src/api/python/genkinds.py
+++ b/src/api/python/genkinds.py
@@ -95,8 +95,6 @@ cdef class kind:
# create a kinds submodule
kinds = ModuleType('kinds')
-# fake a submodule for dotted imports, e.g. from pycvc4.kinds import *
-sys.modules['%s.%s'%(__name__, kinds.__name__)] = kinds
kinds.__file__ = kinds.__name__ + ".py"
"""
diff --git a/src/api/python/setup.py.in b/src/api/python/setup.py.in
new file mode 100644
index 000000000..079aa468e
--- /dev/null
+++ b/src/api/python/setup.py.in
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+# This script is automatically configured with cmake when CVC4
+# is built with --python-bindings. It is called during make
+# install to automatically install the python bindings using
+# distutils.
+# If it is called from a python virtualenv, the bindings are
+# installed in the virtualenv, otherwise, it respects the
+# configured install prefix using the setup.py --prefix option
+
+from distutils.core import setup
+from distutils.command.clean import clean
+from distutils.command.install import install
+
+class PyCVC4Install(install):
+
+ # Calls the default run command, then deletes the build area
+ # (equivalent to "setup clean --all").
+ def run(self):
+ install.run(self)
+ c = clean(self.distribution)
+ c.all = True
+ c.finalize_options()
+ c.run()
+
+setup(name='pycvc4',
+ version='${CVC4_MAJOR}.${CVC4_MINOR}.${CVC4_RELEASE}',
+ packages=['pycvc4'],
+ package_dir={'pycvc4': '${CMAKE_CURRENT_BINARY_DIR}/pycvc4'},
+ package_data={'pycvc4': ['pycvc4.so']},
+ cmdclass={'install': PyCVC4Install})
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback