Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional pip install requirements on Heroku for Django app

Let me start by saying, that I don't think there is a way to do this... but, there are a lot of clever people out there and so I thought I would ask! :)

I found a good article/post by Randall Degges on setting up a Django app on Heroku (Internet Archive link). I really like what he has to say about breaking your requirements up into different files (common.txt, dev.txt, prod.txt etc).

This works great on Heroku for production, but I also maintain a Dev/QA site on Heroku, and I have a few packages that I don't really need for prod that I do use for Dev/QA. The best example is django-debug-toolbar. Currently, I do have this in my production requirements.txt, and I dynamically decide if I need to add it to my installed apps, etc in settings.py at runtime by looking at the DEBUG setting.

Which works fine... but, it would be great if I could not even bother about installing it in prod. I guess what I sort of want is for pip to be able to take a requirements file that allows for conditionals includes (why couldn't it just take a python file?) or for Heroku to support a config setting that tells it which requirements file to use. Has anyone found a way of accomplishing this? Or is it just wishful thinking?

like image 476
David S Avatar asked Aug 22 '12 18:08

David S


2 Answers

Have you looked into this?

If your Python application contains a setup.py file but excludes a requirements.txt file, python setup.py develop will be used to install your package and resolve your dependencies. This works best with distribute or setuptools. Projects that use distutils directly will be installed, but not linked. The module won’t get updated until there’s a version bump. If you already have a requirements file but would like to utilize this feature, you can add the following to your requirements file:

-e .

and then follow on the recommendations in Conditionally installing importlib on python2.6

like image 182
Pratik Mandrekar Avatar answered Oct 24 '22 07:10

Pratik Mandrekar


I had similar needs in buildout and implemented it there. Now that I am migrating from buildout to pip, I came out with this script to use some various requirements files based on some conditions, that can based on os/arch or some environment variable or anything you like. Crude but effective for me.

See https://gist.github.com/pombredanne/72130ee6f202e89c13bb

like image 25
Philippe Ombredanne Avatar answered Oct 24 '22 06:10

Philippe Ombredanne