如何在setup.py中运行Makefile?

时间:2021-08-15 07:25:33

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

我需要使用它自己的构建机制来编译ICU。因此问题:

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

如何从setup.py运行Makefile?显然,我只希望它在构建过程中运行,而不是在安装时运行。

3 个解决方案

#1


37  

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

我通常使用的方法是覆盖有问题的命令:

from distutils.command.install import install as DistutilsInstall

class 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.

这花了我很长时间才从distutils文档和源代码中找出来,所以我希望它可以为你节省很多痛苦。

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

注意:您还可以使用此cmdclass参数添加新命令。

#2


1  

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

如果要构建python扩展,可以使用distutils / setuptools扩展。例如:

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

有很多选项可以构建扩展,请参阅文档:http://docs.python.org/distutils/setupscript.html

#3


0  

It is possible to build C libraries with distutils (see the libraries parameter of distutils.core.setup), but you may have to duplicate options that are already in the Makefile, so the easiest thing to do is probably to extend the install command as explained in other replies and call make with the subprocess module.

可以使用distutils构建C库(请参阅distutils.core.setup的libraries参数),但您可能必须复制Makefile中已有的选项,因此最简单的方法是将install命令扩展为在其他回复中解释并使用子进程模块调用make。

#1


37  

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

我通常使用的方法是覆盖有问题的命令:

from distutils.command.install import install as DistutilsInstall

class 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.

这花了我很长时间才从distutils文档和源代码中找出来,所以我希望它可以为你节省很多痛苦。

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

注意:您还可以使用此cmdclass参数添加新命令。

#2


1  

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

如果要构建python扩展,可以使用distutils / setuptools扩展。例如:

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

有很多选项可以构建扩展,请参阅文档:http://docs.python.org/distutils/setupscript.html

#3


0  

It is possible to build C libraries with distutils (see the libraries parameter of distutils.core.setup), but you may have to duplicate options that are already in the Makefile, so the easiest thing to do is probably to extend the install command as explained in other replies and call make with the subprocess module.

可以使用distutils构建C库(请参阅distutils.core.setup的libraries参数),但您可能必须复制Makefile中已有的选项,因此最简单的方法是将install命令扩展为在其他回复中解释并使用子进程模块调用make。