Customise the virtualenv `activate` script

Tim Chase python.list at tim.thechases.com
Fri Jun 16 07:40:28 EDT 2017


On 2017-06-16 15:53, Ben Finney wrote:
> > 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?  
> 
> That “something opaque” is the ‘$VENV/bin/activate’ script; many
> people who join the team will already know that, and I'm trying to
> make use of that existing convention.
> 
> > 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.  
> 
> Yeah, I'd much prefer to be told there's a hook to use, so that
> someone who creates a standard Python virtualenv the conventional
> way will not need to then hack that virtualenv.

At least within virtualenvwrapper (I'm not sure whether they come
with virtualenv proper), in my $WORKON_HOME and
$WORKON_HOME/$VIRTUALENV/bin directories, I have a bunch of pre* and
post* templates including preactivate and postactivate hooks in which
I can put various bash scripting.  I've only used them once or twice
and don't have an example readily at hand, but it seems would give you
what you're looking for.

-tkc





More information about the Python-list mailing list