2

I'm trying make setup.py for my tiny module, which uses numpy. To compile this module I need extra library which locates in same directory

ls -l audiotools 
total 20
-rw-rw-r-- 1 rth rth 4405 Sep  9 10:58 audiotools.c
drwxr-xr-x 6 rth rth 4096 Sep  9 11:13 libresample-0.1.3
-rw-rw-r-- 1 rth rth  741 Sep  9 11:56 setup.py

So I need add something in setup.py which will call configure and make in libresample-0.1.3 and then add 'libresample.a' to the linker command.

I've tried used add_library, but it requires just source files but not whole source directory. How I can do it?

This doesn't work.

def configuration(parent_package='', top_path=None):
        import numpy
        from numpy.distutils.misc_util import Configuration

        config = Configuration('audiotools',parent_package,top_path)
        config.add_extension('audiotools', ['audiotools.c'])
        config.add_library('libresample',['libresample.a'])
        return config

if __name__ == "__main__":
        from numpy.distutils.core import setup
        setup(
                name = "audiotools",
                version='0.01',
                description='Python wrapper for GNU libresample-0.1.3 and reader of Wave 24bit files',
                author='Ruben Tikidji-Hamburyan, Timur Pinin',
                author_email='[email protected], [email protected]',
                configuration=configuration
        )

Thanks!

2 Answers 2

1

As far as i know this is quite a hassle. The usual approach is to basically require the lib to be installed on the system as a shared lib.

pyzmq do some kind of attempt on this, but it aint trivial: https://github.com/zeromq/pyzmq/blob/master/setup.py

Sign up to request clarification or add additional context in comments.

1 Comment

Wow! It is really complicated stuff.... Probably my setup.py will be bigger than module :(
0

The simplest way which I have found is to use os.system. But it isn't look well for me.

def configuration(parent_package='', top_path=None):
        import numpy
        from numpy.distutils.misc_util import Configuration

        config = Configuration('audiotools',parent_package,top_path)
        config.add_extension('audiotools', ['audiotools.c'],
                extra_link_args=[os.getcwd()+'/libresample-0.1.3/libresample.a'], 
                depends=['libresample-0.1.3/libresample.a'],

        return config

if __name__ == "__main__":
        import os
        os.system('pushd libresample-0.1.3 && ./configure CFLAGS=-fPIC && make &&popd')
        from numpy.distutils.core import setup
        setup(
                name = "audiotools",
                version='0.01',
                description='Python wrapper for GNU libresample-0.1.3 and reader Wave 24 files',
                author='Ruben Tikidji-Hamburyan, Timur Pinin',
                author_email='[email protected], [email protected]',
                configuration=configuration
        )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.