7

Is it possible to create a setup.py file that:

  • Pulls in a github repository
  • places the files from that repository into a specified folder

I'm setting up a django package/app that uses third-party JavaScript frameworks available on github. I'd like to be able to have setup.py pull the latest version from github and then places those files into the appropriate static/js folder. So this is different from normal dependencies that are Python packages with their own setup.py files.

Jordan Reiter
  • 19,139
  • 11
  • 90
  • 150

2 Answers2

2

If you are using setuptool (setup.py) you can use the dependency requirement: https://stackoverflow.com/a/3481388/496445

Otherwise as comments have suggested, set up your django project as an actual git repo and then add the github repo as a submodule

cd myProject
git init
git submodule add git://path/to/repo.git local/location/repo

Then you would just be able to cd into that submodule and git pull

If you dont want to set your project up as a git repo, then the brute force way would be to manually clone the github repo where you want it, and then add some manual commands in your setup.py

import os
os.system("cd path/to/repo && git pull")
Community
  • 1
  • 1
jdi
  • 83,050
  • 18
  • 151
  • 188
  • Does that work if the item in question isn't a python module? Er, everything before the otherwise. I'm still planning on using setuptool or distutils (depending on which is easier to configure) but the object I'm pulling in is not a module, so I'm pretty sure dependency won't work. – Jordan Reiter Dec 28 '11 at 23:34
  • I suppose not, if its not a python package. Option two is very simple though. – jdi Dec 28 '11 at 23:53
  • Okay, I've setup the submodules but they're empty and when pip is called for some reason the clone action doesn't cause them to be loaded. Is there any way for me to do this so that when pip gets run it updates the submodules as well? – Jordan Reiter Dec 30 '11 at 17:13
  • pip has no direct VCS support for git specific commands like for submodules, so I imagine what you would need to do is put a 'post' command at the end of your setup.py that does: `git submodule update --init` – jdi Dec 30 '11 at 18:30
  • "Fixed" it by modifying pip. See my change here: https://github.com/JordanReiter/pip/commit/2e2716bab33c415e0785e074cfcc145b8a26e881 – Jordan Reiter Dec 30 '11 at 21:23
2

An alternative to this would be to provide a requirements.txt file for use with pip. You can specify git and mercurial repos as well as packages from PyPI, so that the user would just have to do pip install -r requirements.txt to get the whole project.

Daniel Roseman
  • 541,889
  • 55
  • 754
  • 786
  • Does that work if the repositories in questions don't have setup.py files? – Jordan Reiter Dec 28 '11 at 23:34
  • Sorry to vote you down, but this answer only works if I was dealing with python repositories, which I'm not. Just thinking some people might try this out and have it not work. If there is a magic way to get pip to pull in non-Python modules via the requirements.txt file let me know, because there's nothing about this in the documentation. – Jordan Reiter Dec 30 '11 at 17:15