2012-01-12 65 views
4

我使用easyinstall創建setup.py,並且需要在構建完成之前在同一個項目中執行某個py文件。我嘗試了setup_requires和ext_modules,但兩者似乎都無法在同一個項目中調用python文件。在setup.py中生成之前運行.py文件

回答

5

下面的代碼創建一個新的構建命令,在委派給原始構建命令之前調用您自己的自定義功能。在以下內容中,RunYourOtherScript()代表您想在build發生之前運行的任何內容。這可能是對execfile('src/something.py')的調用,或者最好是相對導入和函數調用。

from distutils.command import build as build_module 

class build(build_module.build): 
    def run(self): 
    RunYourOtherScript() 
    build_module.build.run(self) 

setup(
    ... 
    cmdclass = { 
     'build': build, 
    }, 
) 
相關問題