1
雖然distutils工作正常,但我並不完全適應它,而且我也有性能問題no apparent solution。是否可以將Premake或cmake集成到我的setup.py腳本中,以便python setup.py build
調用它們,然後將輸出放置在安裝期望的位置?我可以爲我的Python擴展模塊(用C++編寫)使用替代構建系統嗎?
雖然distutils工作正常,但我並不完全適應它,而且我也有性能問題no apparent solution。是否可以將Premake或cmake集成到我的setup.py腳本中,以便python setup.py build
調用它們,然後將輸出放置在安裝期望的位置?我可以爲我的Python擴展模塊(用C++編寫)使用替代構建系統嗎?
我想出了一個辦法,它不漂亮,但它的工作原理。
這裏是我的setup.py
腳本文件的總和 - 它應該是相當自我解釋:
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
},
)
我希望它能幫助。
恰恰相反,這是一個很好的解決方案。謝謝! –
我很高興你這麼認爲。這可能是惹惱我的全局變量。 – jpihl