views:

232

answers:

2

I need to compile ICU using it's own build mechanism. Therefore the question:

How can I run a Makefile from setup.py? Obviously, I only want it to run during the build process, not while installing.

A: 

If you are building a python extension you can use the distutils/setuptools Extensions. For example:

from setuptools import Extension
# or:
# from distutils.extension import Extension
setup(...
      ext_modules = [Extension("pkg.icu",
                               ["icu-sqlite/icu.c"]),
                    ]
      )

There are lots of options to build extensions, see the docs: http://docs.python.org/distutils/setupscript.html

resi
It's not an extension that I want to build but just a C library that won't get linked with Python. (It's an extension to sqlite.)
Georg
+4  A: 

The method I normally use is to override the command in question:

from distutils.command.install import install as DistutilsInstall

def MyInstall(DistutilsInstall):
    def run(self):
        do_pre_install_stuff()
        DIstutilsInstall.run(self)
        do_post_install_stuff()

...

setup(..., cmdclass={'install': MyInstall}, ...)

This took me quite a while to figure out from the distutils documentation and source, so I hope it saves you the pain.

Note: you can also use this cmdclass parameter to add new commands.

Walter
Thanks for the answer. Saves me the pain? Sort of, I've already spent too much time looking for this answer...
Georg