Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use virtualenv in makefile

I want to perform several operations while working on a specified virtualenv.

For example command

make install

would be equivalent to

source path/to/virtualenv/bin/activate
pip install -r requirements.txt

Is it possible?

like image 243
dev9 Avatar asked Jul 14 '14 12:07

dev9


2 Answers

I like using something that runs only when requirements.txt changes:

This assumes that source files are under project in your project's root directory and that tests are under project/test. (You should change project to match your actually project name.)

venv: venv/touchfile

venv/touchfile: requirements.txt
    test -d venv || virtualenv venv
    . venv/bin/activate; pip install -Ur requirements.txt
    touch venv/touchfile

test: venv
    . venv/bin/activate; nosetests project/test

clean:
    rm -rf venv
    find -iname "*.pyc" -delete
  • Run make to install packages in requirements.txt.
  • Run make test to run your tests (you can update this command if your tests are somewhere else).
  • run make clean to delete all artifacts.
like image 79
oneself Avatar answered Sep 21 '22 18:09

oneself


In make you can run a shell as command. In this shell you can do everything you can do in a shell you started from comandline. Example:

install:
    ( \
       source path/to/virtualenv/bin/activate; \
       pip install -r requirements.txt; \
    )

Attention must be paid to the ;and the \.

Everything between the open and close brace will be done in a single instance of a shell.

like image 35
Klaus Avatar answered Sep 20 '22 18:09

Klaus