From 94a1a701dc6fb0d8363742882838f6637e5cb8a3 Mon Sep 17 00:00:00 2001 From: Peter Badida Date: Tue, 5 Oct 2021 21:02:11 +0200 Subject: [PATCH] Fix broken Cython compilation due to baked C++ files --- reppy/robots.pyx | 1 + setup.py | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/reppy/robots.pyx b/reppy/robots.pyx index cbb634d..432ed16 100644 --- a/reppy/robots.pyx +++ b/reppy/robots.pyx @@ -1,4 +1,5 @@ # cython: linetrace=True +# cython: language=c++ # distutils: define_macros=CYTHON_TRACE=1 from contextlib import closing diff --git a/setup.py b/setup.py index 60eb3a9..fe2cdeb 100644 --- a/setup.py +++ b/setup.py @@ -34,26 +34,36 @@ 'reppy/rep-cpp/deps/url-cpp/src/psl.cpp' ] +ext_opts = dict( + language='c++', + extra_compile_args=['-std=c++11'], + include_dirs=[ + 'reppy/rep-cpp/include', + 'reppy/rep-cpp/deps/url-cpp/include' + ] +) + + kwargs = {} try: from Cython.Distutils import build_ext print('Building from Cython') - ext_files.append('reppy/robots.pyx') + from Cython.Build import cythonize + + # ensure any baked C++ code is cleaned + extra = ['reppy/robots.pyx'] + ext_files += extra + + for file in extra: + cythonize(file, force=True, language=ext_opts["language"]) kwargs['cmdclass'] = {'build_ext': build_ext} + except ImportError: print('Building from C++') ext_files.append('reppy/robots.cpp') -ext_modules = [ - Extension( - 'reppy.robots', ext_files, - language='c++', - extra_compile_args=['-std=c++11'], - include_dirs=[ - 'reppy/rep-cpp/include', - 'reppy/rep-cpp/deps/url-cpp/include']) -] +ext_modules = [Extension('reppy.robots', ext_files, **ext_opts)] setup( name='reppy',