Starting Django virtual environment + build commands with gulp

429 views Asked by At

I am trying to make my Django project super portable and easy to start/stop. I'm using python's virutal environments along with a pip requirements file to manage python versions and pip packages. One concern I've always wondered about is migrating test data between databases. I'm utilizing:

python manage.py dumpdata > fixtures/data.json

to dump the current test data to a file and I want the next developer to pull this test data when they start their env using:

python manage.py loaddata fixtures/data.txt

So, the overall goal is to create a simple gulp command to do the following:

pull latest git commit, start virtual env, merge test data into database, start server

I couldn't get gulp to start the virtual enviorment but if there is another way I should try and automate this, let me know.

1

There are 1 answers

3
Enix On

you can use gulp-shell to run system command with gulp

install gulp-shell with npm:

$ npm install --save-dev gulp gulp shell

here is the sample gulpfile.js for your reference:

var gulp = require('gulp'),
    shell = require('gulp-shell');


gulp.task('default', shell.task([
    'git pull origin master',          // pull the latest data from remote repo
    'source $virtualenv/bin/activate; python manage.py dumpdata --database test > fixtures/data.json',   // activate the python virtual env, dump the data from test database
    'source $virtualenv/bin/activate; python manage.py loaddata fixtures/data.json'   // activate the python virtual env, load the data into production database
]));

Run gulp default task

$ gulp