Customise the virtualenv `activate` script

Ben Finney ben+python at benfinney.id.au
Mon Jun 12 21:57:11 EDT 2017


Howdy all,

What is the conventional way to customise the changes made by a Python
virtualenv bin/activate script?


The Python virtualenv is activated by a ‘$VENV/bin/activate script’ [0].
This script works primarily by setting environment variables specific to
the virtualenv.

(This is different from the “bootstrap script” discussed in the
Virtualenv documentation. Those are used once, when creating the
virtualenv; they are not used when activating the virtualenv. This
question is about the activate script.)

Many of the code bases for which I use a Python virtualenv, need
additional (custom) environment variables set, each time the virtualenv
is activated.

How can I make this easy for developers who already know how to activate
a virtualenv?

* Edit the ‘$VENV/bin/activate’ script directly, to add statements that
  set more environment variables?

* Write a custom wrapper script, that incidentally calls
  ‘$VENV/bin/activate’?

* Write a separate script with a specific name, that will be
  automatically called by ‘$VENV/bin/activate’? Does such a thing exist?

Of course I could write a script with a different name, and instruct
developers to run that instead. Instead, this question is asking how to
hook into the existing convention, of activating the virtualenv with a
known name ‘$VENV/bin/activate’.


[0] https://virtualenv.pypa.io/en/stable/userguide/#activate

-- 
 \          “It is clear that thought is not free if the profession of |
  `\           certain opinions makes it impossible to earn a living.” |
_o__)  —Bertrand Russell, _Free Thought and Official Propaganda_, 1928 |
Ben Finney




More information about the Python-list mailing list