本文介绍了我可以为我的Python扩展模块(用C ++编写)使用替代构建系统吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然distutils工作正常,我不是完全满意,我也有性能问题与。是否可以在我的setup.py脚本中集成Premake或cmake,以便 python setup.py build 调用它们,然后放置安装期望的输出。

While distutils works alright, I'm not entirely comfortable with it, and I also have performance problems with no apparent solution. Is it possible to integrate Premake or cmake in my setup.py script so that python setup.py build calls them and then places the output where install expects it?

推荐答案

我想出了一种方法,它不漂亮,但它的工作原理。

I figured out a way, it's not pretty but it works.

是我的 setup.py 脚本文件的总和 - 它应该是相当自我解释:

Here is a summation of my setup.py script file - it should be fairly self explanatory:

import shutil
import os

from distutils.core import setup
from distutils.core import Extension

from distutils.command.build_ext import build_ext
from distutils.command.install_lib import install_lib

library = None

def generate_lib():
    """
        Build library and copy it to a temp folder.
        :returns: Location of the generated library is returned.
    """
    raise NotImplementedError


class MyInstall(install_lib):
    def install(self):
        global library
        shutil.move(library, self.install_dir)
        return [os.path.join(self.install_dir, library.split(os.sep)[-1])]


class MyBuildExtension(build_ext):
    def run(self):
        global library
        library = create_lib();

module = Extension('name',
                   sources=[])

setup(
    name='...',
    version='...',
    ext_modules=[module],
    description='...',
    long_description='...',
    author='...',
    author_email='...',
    url='...',
    keywords='...',
    license='...',
    platforms=[],
    classifiers=[],
    cmdclass={
        'build_ext': MyBuildExtension,
        'install_lib': MyInstall
    },
)

我希望它有帮助。

这篇关于我可以为我的Python扩展模块(用C ++编写)使用替代构建系统吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:50