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

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.