How to use aliases and postactivate with virtualenvwrapper to make easier your development tasks.


This is just a TIP, you can follow it or create yours based on it as well.

I like to use virtualenvwrapper for my Django and Python projects. I usually add some alias to postactivate file in order to avoid type a lot of commands with frequent tasks (reset default testing data for example).

So this is quite simple you just need to add aliases according your needs and practices.

Step 1: Locate and open with some text editor your postactivate script:

e.g:

sergio$ vim ~/.virtualenvs/your_project_name/bin/postactivate

Step 2: Add aliases and save:

e.g:

alias code_review='flake8 . --ignore=E501,F403'
alias migrate='rm your_project/db.sqlite3 && python manage.py makemigrations && python manage.py migrate'

Step 3: Activate (or deactivate and activate) your environment to test your aliases:

e.g activate:

sergio$ workon your_project

e.g deactivate and activate

(your_project) sergio$ deactivate
sergio$ workon your_project
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s