Can I force pip to make a shallow checkout when installing from git?

Viewed 1688

The following command installs a Python package from a git repository:

$ pip install git+ssh://git@github.com/username/repo.git
Collecting git+ssh://git@github.com/username/repo.git
  Cloning ssh://git@github.com/username/repo.git to /tmp/pip-req-build-8s4nci15

I'm not 100% certain, but as it takes quite long I guess it clones every commit. But for installation, I only need the latest.

Instead, I would like a shallow clone (with --depth 1). Is that possible?

2 Answers

In addition to work-arounds (like ZIP) that might be available depending on hosting, a generic git work-around would be to pre-create the shallow clone, and then (since your clone is itself a git repo) point PIP to the clone.

This is not ideal (hence "work-around") in that, for an automated case, you would have to script creation of the shallow clone(s) before invoking PIP, and the data you give to PIP would list the clones' URL's instead of the canonical URL's for the respective packages.

Also, for the reasons called out in the PIP 'depth=1' debate, it might end up not working for you depending on what tools you (or your dependencies) use. It seems git describe is the crux of the issue (or at least, of one common issue); so you might be able to put a tag on the one commit you hold locally as a further work-around.

Related