Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggestion: emit an event upon activation in activate.fish #1456

Closed
drcongo opened this issue Nov 29, 2019 · 6 comments
Closed

Feature suggestion: emit an event upon activation in activate.fish #1456

drcongo opened this issue Nov 29, 2019 · 6 comments

Comments

@drcongo
Copy link

drcongo commented Nov 29, 2019

Problem: Sometimes it's useful to be able to run a function upon activation of a virtualenv. As an example, we have many projects containing a fabfile folder with its own virtualenv, when activating that venv the shell session remains inside the fabfile directory but it would be useful to be one directory up. If the activate script emitted an event, users could hook into that event to do whatever they need.

Suggested change:
Add emit virtualenv_activated $VIRTUAL_ENV to activate.fish

I've tested this, it works and is pretty useful. Happy to put it in as a PR if there's support for the idea.

@gaborbernat
Copy link
Contributor

I like where this is going 😃 As much as possible though I'd like to special case fish, so would you be available to look into if the other shells support similar functionality? If so we should add a similar thing to all shells that support it.

FYI. Currently, virtualenv is having its rewrite, see #697; so you might want to put it against that, activation scripts are just been added via #1454 (but feel free to add it into current master too)

@drcongo
Copy link
Author

drcongo commented Nov 29, 2019

As far as I can work out, there's no equivalent in bash or zsh, though Xonsh does seem to have a similar concept: https://xon.sh/docs-ahundt-sphinx-readable-theme-pypi/api/events.html

I'm very much not a shells expert though, so I could be wrong about bash and zsh.

@gaborbernat
Copy link
Contributor

What about powershell? 🤔

@gaborbernat gaborbernat pinned this issue Nov 29, 2019
@gaborbernat gaborbernat unpinned this issue Dec 26, 2019
@gaborbernat gaborbernat added this to the 20.2.0 milestone Feb 6, 2020
@joaoe
Copy link

joaoe commented Jul 4, 2020

As far as I can work out, there's no equivalent in bash or zsh,

This could be easily emulated by invoking a global function created in the shell environment.
The venv activate script could check is there is a function called (example) on_virtualenv_activate and call it after the venv is set up. Then user would put that in their bashrc files.

There should also be a matching deactivate event btw, ideally before the venv is unloaded.

@pfmoore
Copy link
Member

pfmoore commented Jul 4, 2020

What about powershell?

I've not used it myself, but help New-Event shows:

The New-Event cmdlet creates a new custom event.

You can use custom events to notify users about state changes in your program and any change that your program can detect, including hardware or system conditions, application status, disk status, network status, or the completion of a background job.

@gaborbernat
Copy link
Contributor

Seems no longer an issue as no one reported it in 3 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants