0

How to write a setup.py that would git clone a repository online to a specific directory (like external/)? This is for a python/c++ hybrid project.

I tried to write a setup.py with:

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

But that doesn't work.

I also can't use #egg=xyz described in (Fetching remote git branch through Python setuptools) because it is not a python repository.

The c++ repository is a header-only library.

hamster on wheels
  • 2,771
  • 17
  • 50
  • Maybe git-python is a solution. The github page says it leaks resource and not all test cases pass on window. Also need to make setup.py install gitpython before doing the `git clone` https://stackoverflow.com/questions/15315573/how-can-i-call-git-pull-from-within-python – hamster on wheels Aug 09 '17 at 19:50
  • At what stage do you want to run `git clone` — build_ext? What to do if the repository is already cloned? – phd Aug 09 '17 at 21:21
  • I want to git clone before the c++ components get compiled. – hamster on wheels Aug 09 '17 at 23:14

1 Answers1

2
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},
    …
)
phd
  • 82,685
  • 13
  • 120
  • 165