Starting a Django virtual environment in Grunt
django, gruntjs, virtualenv
Solution
Normally when trying to get other tooling to launch django while using a virtualenv the normal thing is to perform both of the following in one command :
- activate the virtualenv
- run the command you want.
so this ends up being :
`. ${VIRTUALENVHOME}/bin/activate && ${PROJECTROOT}/manage.py runserver 0:8000`
This is pretty much how it's done with Fabric, Ansible and any other automation tool.
edit: of course you'd be supplying the values for the variables `VIRTUALENVHOME` and `PROJECTROOT`
Problem
Coming from a JS / Node development background, I like to use Grunt for a lot of my automation. For a recent project I picked up some baby Django, to get a feel for how it operated, but still wanted to integrate Grunt for some of my workflow. I am currently starting my Django server via Grunt, using the spawn-shell module. This works just fine, but I am also using a virtualenv setup, and would as well like to start that up via Grunt. The command I am using to start the virtual enviornment is: ``` source ./venv/bin/activate ``` Which works just fine from the terminal command line as is. However, executing this command from either grunt shell or grunt exec does nothing. I get no errors from Grunt (it says running, then done without errors), but nothing gets started. The grunt exec command is as follows: ``` exec: { start: { cmd: function() { return "source ./venv/bin/activate"; } } } ``` And the shell command is: shell: { ``` start: { command: 'source ./venv/bin/activate', options: { stdout: true } } } ``` Any ideas on how to get this working? Or is it not possible, and I should just resort to entering the command manually at start?