Customise the virtualenv `activate` script

Cameron Simpson cs at zip.com.au
Tue Jun 13 03:50:57 EDT 2017


On 13Jun2017 11:57, Ben Finney <ben+python at benfinney.id.au> wrote:
>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’.

I cannot speak for the conventions.

I must admit my initial preference would be the differently named wrapper.  
Surely users of the codebase will be invoking stuff via something opaque which 
sources the requisite things?

Actually, on trying to write something simple and flexible, since once made the 
venv is basicly state WRT the activate script, I'm leaning towards hacking the 
activate script, probably by keeping a distinct file off the the side and 
modifying activate to source it.

Cheers,
Cameron Simpson <cs at zip.com.au>



More information about the Python-list mailing list