triggering different app environments with pyenv-virtualenv
Asked Answered
S

2

7

with virtualenvwrapper, I could setup separate virtualenvs and calling workon venv have them link to specific settings files (ex. test_settings.py or dev_settings.py) I preset using hooks in the virtualenv's bin - preactivate, postactivate, predeactivate and postdeactivate.

Is there something equivalent for pyenv? pyenv-virtualenv automatically switches virtualenvs based on .python-version set in the current directory, so there's no need to activate and the .pyenv/versions/venv/bin/ dir doesn't have the compliment of hooks that virtualwrapper has anyway.

I can easily create different virtualenvs for my various app environments but how can I link them to different environment-specific app settings?

Steamheated answered 27/5, 2015 at 8:31 Comment(0)
S
2

I ended up adding environment variable export something='something-else' commands to the activate file ~/.pyenv/versions/my_venv/bin/activate in the spirit of autoenv after reading this forum reply elsewhere.

Steamheated answered 30/5, 2015 at 23:7 Comment(0)
P
0

Two ideas:

  • The obvious one: Try the pyenv-virtualenvwrapper plugin to pyenv?

  • You can add hooks for a specific pyenv command in $PYENV_ROOT/pyenv.d/<command>. You can do this even for for pyenv’s “porcelain” commands which aren’t normally called directly by the user. You could write a hook for activate that changes settings based on the name of the virtualenv you’re switching to. (pyenv-virtualenv implicitly pyenv activate when switching to a virtualenv). Note: I’ve created pyenv hooks, but not for activate, so this is just an idea…

Pawl answered 3/2, 2016 at 15:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.