improved cython wrapper python3 support

release/4.3a0
Matthew Broadway 2019-01-08 10:28:19 +00:00
parent 435762ca81
commit 5670c73158
4 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -1,2 +1,2 @@
from gtsam import *
from .gtsam import *
${GTSAM_UNSTABLE_IMPORT}

View File

@ -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"

View File

@ -1,3 +1,5 @@
# cython: c_string_type=str, c_string_encoding=ascii
cimport numpy as np
import numpy as npp
cimport geometry