
I have some less elegant suggestions. In my ed25519ll package I abuse the Extension class to compile some source code (that is not a Python extension). This works if the C package you are compiling is simple enough that it can be built with the limited Extension interface. https://bitbucket.org/dholth/ed25519ll/src/37719c56b7b621a98dc694b109ccfca1c... For example setup( ... ext_modules=[ Extension('ed25519ll._ed25519_%s' % plat_name, sources=[ 'ed25519-supercop-ref10/ge_frombytes.c', # many more 'ed25519-supercop-ref10/py.c'], include_dirs=['ed25519-supercop-ref10', ], export_symbols=["crypto_sign", "crypto_sign_open", "crypto_sign_keypair"]) ) I added the file `py.c` with an empty function `void init_ed25519_win32() {}` to make the linker happy, and I list the symbols that need to be exported, otherwise those symbols would not be visible on Windows. Then I open the shared module with cffi or ctypes. Not very pretty but it works well enough. Another thing you can do without extending distutils that may not be immediately obvious is to run as much code as you want before calling setup(). It is even possible to install other Python modules by calling pip in a subprocess, then importing them, then calling setup(), all in the same file. On Fri, Jun 3, 2016 at 9:47 AM Ionel Cristian Mărieș < distutils-sig@python.org> wrote:
On Fri, Jun 3, 2016 at 5:35 AM, Young Yang <afe.young@gmail.com> wrote:
my_install is a subclass of `from setuptools.command.install import install` ``` class my_install(install): def run(self): # DO something I want. Such as compiling the code of project A and copy the output of it (i.e. the .so file) to my binding folder install.run(self) ```
At last I add these options in my setup function in setup.py to include the shared library in the install package. ``` package_dir={'my_binding_package': 'my_binding_folder'}, package_data={ 'my_binding_package': ['Shared_lib.so'], }, include_package_data=True, ```
But I think there should be better ways to achieve these.
Overriding only the `install` will make bdist_wheel produce the wrong result. There's also the `develop` command. Some ideas about what commands you might need to override: https://github.com/pytest-dev/pytest-cov/blob/master/setup.py#L30-L63
An alternative approach would be to create a custom Extension class, check this https://github.com/cython/cython/tree/master/Cython/Distutils for ideas.
Unfortunately the internals of distutils/setuptools aren't really well documented so you'll have to rely on examples, simply reading distutils code, coffee or even painkillers :-)
Thanks, -- Ionel Cristian Mărieș, http://blog.ionelmc.ro _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org https://mail.python.org/mailman/listinfo/distutils-sig