Skip to content

Commit

Permalink
Fix build scripts for python3 (#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterychang authored and jackgerrits committed Apr 10, 2019
1 parent 6ef7676 commit d55d83c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
5 changes: 1 addition & 4 deletions python/pylibvw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/make_shared.hpp>
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
Expand Down Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d55d83c

Please sign in to comment.