Here's my setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
wrapper = Extension(
name="libwrapper",
...
)
setup(
name="libwrapper",
ext_modules=cythonize([wrapper])
)
When I run python3 setup.py build_ext the output file is called libwrapper.cpython-36m-x86_64-linux-gnu.so, but I want to name it only libwrapper.so, how can I do that?
Try the following code. sysconfig.get_config_var('EXT_SUFFIX') returns platform-specific suffix which can be removed from the final filename by subclassing build_ext and overriding get_ext_filename.
from distutils import sysconfig
from Cython.Distutils import build_ext
from distutils.core import setup
import os
class NoSuffixBuilder(build_ext):
def get_ext_filename(self, ext_name):
filename = super().get_ext_filename(ext_name)
suffix = sysconfig.get_config_var('EXT_SUFFIX')
ext = os.path.splitext(filename)[1]
return filename.replace(suffix, "") + ext
setup(
....
cmdclass={"build_ext": NoSuffixBuilder},
)
Final filename will be test.so
A slightly more minimal version of hurlenko's answer with the option of including whatever suffix you want, in case anyone else wanted this
import setuptools
from distutils.command.build_ext import build_ext
import os
class MySuffix(build_ext):
suffix = '.library'
def get_ext_filename(self, ext_name):
return os.path.join(*ext_name.split('.')) + self.suffix
setuptools.setup(
....
cmdclass={'build_ext': MySuffix},
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With