From d55d83cf73e4a87159c3dd10a54d60390f028a8d Mon Sep 17 00:00:00 2001 From: peterychang <49209570+peterychang@users.noreply.github.com> Date: Wed, 10 Apr 2019 09:55:29 -0400 Subject: [PATCH] Fix build scripts for python3 (#1823) --- python/CMakeLists.txt | 2 +- python/pylibvw.cc | 5 +---- python/setup.py | 26 +++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 6433d657901..74992edad18 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -18,7 +18,7 @@ else(Boost_MINOR_VERSION GREATER 66) endif(PY_VERSION_STRIPPED_FIRST_CHAR STREQUAL "2") endif(Boost_MINOR_VERSION GREATER 66) -find_package(PythonInterp REQUIRED) +find_package(PythonInterp ${PY_VERSION} REQUIRED) find_package(PythonLibs ${PY_VERSION} REQUIRED) find_package(Boost REQUIRED COMPONENTS system python${BOOST_PY_VERSION_SUFFIX}) diff --git a/python/pylibvw.cc b/python/pylibvw.cc index 41cb216c4c8..8d9742841af 100644 --- a/python/pylibvw.cc +++ b/python/pylibvw.cc @@ -11,7 +11,7 @@ // see http://www.boost.org/doc/libs/1_56_0/doc/html/bbv2/installation.html #define BOOST_PYTHON_STATIC_LIB - +#define BOOST_PYTHON_USE_GCC_SYMBOL_VISIBILITY 1 #include #include #include @@ -701,9 +701,6 @@ void my_set_condition_range(predictor_ptr P, ptag hi, ptag count, char name0) { void my_set_learner_id(predictor_ptr P, size_t id) { P->set_learner_id(id); } void my_set_tag(predictor_ptr P, ptag t) { P->set_tag(t); } -//We need to forward declare this here to be able to add VW_DLL_MEMBER as BOOST_PYTHON_MODULE doesn't help -extern "C" VW_DLL_MEMBER void initpylibvw(); - BOOST_PYTHON_MODULE(pylibvw) { // This will enable user-defined docstrings and python signatures, // while disabling the C++ signatures diff --git a/python/setup.py b/python/setup.py index 2a0d0af75c8..e2a837be80e 100644 --- a/python/setup.py +++ b/python/setup.py @@ -22,8 +22,32 @@ class CMakeExtension(Extension): def __init__(self, name): # don't invoke the original build_ext for this special extension Extension.__init__(self, name, sources=[]) - + +def get_ext_filename_without_platform_suffix(filename): + from distutils.sysconfig import get_config_var + ext_suffix = get_config_var('EXT_SUFFIX') + name, ext = os.path.splitext(filename) + + if not ext_suffix: + return filename + + if ext_suffix == ext: + return filename + + ext_suffix = ext_suffix.replace(ext, '') + idx = name.find(ext_suffix) + + if idx == -1: + return filename + else: + return name[:idx] + ext + class BuildPyLibVWBindingsModule(_build_ext): + def get_ext_filename(self, ext_name): + # don't append the extension suffix to the binary name + # see https://stackoverflow.com/questions/38523941/change-cythons-naming-rules-for-so-files/40193040#40193040 + filename = _build_ext.get_ext_filename(self, ext_name) + return get_ext_filename_without_platform_suffix(filename) def run(self): for ext in self.extensions: