diff --git a/cmake/FindCython.cmake b/cmake/FindCython.cmake index 23afb00e6..292d9d51e 100644 --- a/cmake/FindCython.cmake +++ b/cmake/FindCython.cmake @@ -32,7 +32,7 @@ find_package( PythonInterp ) if ( PYTHONINTERP_FOUND ) execute_process( COMMAND "${PYTHON_EXECUTABLE}" "-c" - "import Cython; print Cython.__path__" + "import Cython; print(Cython.__path__[0])" RESULT_VARIABLE RESULT OUTPUT_VARIABLE CYTHON_PATH OUTPUT_STRIP_TRAILING_WHITESPACE @@ -51,7 +51,7 @@ endif () # RESULT=0 means ok if ( NOT RESULT ) execute_process( COMMAND "${PYTHON_EXECUTABLE}" "-c" - "import Cython; print Cython.__version__" + "import Cython; print(Cython.__version__)" RESULT_VARIABLE RESULT OUTPUT_VARIABLE CYTHON_VAR_OUTPUT ERROR_VARIABLE CYTHON_VAR_OUTPUT diff --git a/cython/gtsam/__init__.py.in b/cython/gtsam/__init__.py.in index 7d456023f..85451c680 100644 --- a/cython/gtsam/__init__.py.in +++ b/cython/gtsam/__init__.py.in @@ -1,2 +1,2 @@ -from gtsam import * +from .gtsam import * ${GTSAM_UNSTABLE_IMPORT} diff --git a/wrap/Module.cpp b/wrap/Module.cpp index a3b8df630..b2b1dc1dc 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -394,6 +394,10 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const { /* ************************************************************************* */ void Module::emit_cython_pyx(FileWriter& pyxFile) const { + // directives... + // allow str to automatically coerce to std::string and back (for python3) + pyxFile.oss << "# cython: c_string_type=str, c_string_encoding=ascii\n\n"; + // headers... string pxdHeader = name; pyxFile.oss << "cimport numpy as np\n" diff --git a/wrap/tests/expected-cython/geometry.pyx b/wrap/tests/expected-cython/geometry.pyx index 4bd14b130..7c20a500d 100644 --- a/wrap/tests/expected-cython/geometry.pyx +++ b/wrap/tests/expected-cython/geometry.pyx @@ -1,3 +1,5 @@ +# cython: c_string_type=str, c_string_encoding=ascii + cimport numpy as np import numpy as npp cimport geometry