pyenv-virtualenv icon indicating copy to clipboard operation
pyenv-virtualenv copied to clipboard

Hook for pyenv activate

Open danfrankj opened this issue 3 years ago • 2 comments

I would like to be able to add a hook script when pyenv activate runs. In particular it would be helpful for me to be able to modify some environment vars.

It appears that some commands have such hooks: https://github.com/pyenv/pyenv-virtualenv/blob/master/bin/pyenv-virtualenv#L515

Let me know if you'd be open to adding such functionality to activate. Happy to create a PR if so

See also: https://github.com/pyenv/pyenv/issues/2337

Too many issues will kill our team's development velocity, drastically. Make sure you have checked all steps below.

Prerequisite

  • [X] Make sure your problem is not listed in the common build problems.
  • [X] Make sure no duplicated issue has already been reported in the pyenv-virtualenv issues. You should look in closed issues, too.
  • [X] Make sure you are not asking us to help solving your specific issue.
    • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
  • [X] Make sure your problem is not derived from packaging (e.g. Homebrew).
    • Please refer to the package documentation for the installation issues, etc.
  • [X] Make sure your problem is not derived from other plugins.
    • This repository is maintaining the pyenv-virtualenv plugin only. Please refrain from reporting issues of other plugins here.

Description

  • [ ] Platform information (e.g. Ubuntu Linux 20.04):
  • [ ] OS architecture (e.g. amd64):
  • [ ] pyenv version:
  • [ ] pyenv-virtualenv version:
  • [ ] Python version:
  • [ ] virtualenv version (if installed):
  • [ ] Please attach the debug log of a faulty Pyenv invocation as a gist
    • If the problem happens in a Pyenv invocation, you can turn on debug logging by setting PYENV_DEBUG=1, e.g. env PYENV_DEBUG=1 pyenv install -v 3.6.4
    • If the problem happens outside of a Pyenv invocation, get the debug log like this:
      export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
      set -x
      <reproduce the problem>
      set +x
      

danfrankj avatar Apr 30 '22 16:04 danfrankj

@yyuu has approved it in https://github.com/pyenv/pyenv/issues/2337#issuecomment-1107797056. I trust his judgement here so no objections from me, either.

Go ahead but do heed his warnings about possible side effects -- in particular, think carefully where exactly to insert the call point so that it's potentially useful for more use cases than just yours and how to name and/or where to locate the hook executables to avoid confusion.

native-api avatar May 04 '22 01:05 native-api

+1 This would be really helpful - currently I just source the 'activate' script to work around this, would be nice to just use the pyenv tooling.

williamtwomey avatar May 18 '22 15:05 williamtwomey