2017-08-09 139 views
0

如何編寫一個setup.py git克隆一個存儲庫聯機到一個特定的目錄(如external/)?這是一個python/C++混合項目。問setuptools git克隆C++存儲庫

我試着寫一個setup.py

setup(
    name='test', 
    ...  
    dependency_links=['https://blah/master.zip'], 
) 

但是,這並不工作。

我也不能使用(Fetching remote git branch through Python setuptools)中描述的#egg=xyz,因爲它不是python存儲庫。

C++存儲庫是一個只有標題的庫。

+0

也許git-python是一個解決方案。 github頁面說它泄露了資源,並不是所有的測試用例都通過窗口。在做'git clone'之前還需要make setup.py安裝gitpython https://stackoverflow.com/questions/15315573/how-can-i-call-git-pull-from-within-python –

+0

在什麼階段你想運行'git clone' - build_ext?如果存儲庫已被克隆,該怎麼辦? – phd

+0

我想在編譯C++組件之前克隆克隆。 –

回答

1
from setuptools.command.build_ext import build_ext 
import subprocess 

class git_clone_external(build_ext): 
    def run(self): 
     subprocess.check_call(['git', 'clone', 'https://git.example.com']) 
     build_ext.run(self) 

setup(… 
    cmdclass = {'build_ext': git_clone_external}, 
    … 
)