make install -j2
echo -e "#include <cvc4/cvc4.h>\nint main() { CVC4::ExprManager em; return 0; }" > /tmp/test.cpp
$CXX -std=c++11 /tmp/test.cpp -I install/include -L install/lib -lcvc4 -lcln || exit 1
+ # set PYTHONPATH to include the directory containing pycvc4 module
+ export PYTHONPATH=$PYTHONPATH:$(dirname $(find ./install/ -name "pycvc4" -type d))
+ if [[ "$TRAVIS_CVC4_PYTHON_BINDINGS" == "yes" ]]; then
+ $TRAVIS_PYTHON -c "import pycvc4" || exit 1
+ fi
)
}
run() {
env:
- TRAVIS_CVC4=yes
- TRAVIS_WITH_LFSC=yes
+ - TRAVIS_CVC4_PYTHON_BINDINGS=no
- TRAVIS_CVC4_CONFIG="production --language-bindings=java --lfsc"
- TRAVIS_PYTHON=python
- compiler: gcc
env:
- TRAVIS_CVC4=yes
- TRAVIS_WITH_LFSC=yes
+ - TRAVIS_CVC4_PYTHON_BINDINGS=no
- TRAVIS_CVC4_CONFIG="debug --symfpu --lfsc --no-debug-symbols"
- TRAVIS_PYTHON=python
# Test python bindings
env:
- TRAVIS_CVC4=yes
- TRAVIS_WITH_LFSC=yes
+ - TRAVIS_CVC4_PYTHON_BINDINGS=yes
- TRAVIS_CVC4_CONFIG="production --python-bindings --python2"
- TRAVIS_PYTHON=python
- compiler: gcc
env:
- TRAVIS_CVC4=yes
- TRAVIS_WITH_LFSC=yes
+ - TRAVIS_CVC4_PYTHON_BINDINGS=yes
- TRAVIS_CVC4_CONFIG="production --python-bindings --python3"
- TRAVIS_PYTHON=python3
#
env:
- TRAVIS_CVC4=yes
- TRAVIS_WITH_LFSC=yes
+ - TRAVIS_CVC4_PYTHON_BINDINGS=no
- TRAVIS_CVC4_CONFIG="debug --symfpu --cln --gpl --no-debug-symbols --no-proofs"
- TRAVIS_PYTHON=python
notifications:
"${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
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)
except:
pass
- try:
- indices = kind(<int> self.cop.getIndices[c_Kind]())
- except:
- pass
-
try:
indices = self.cop.getIndices[uint32_t]()
except:
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"
# 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"
"""
--- /dev/null
+#!/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})