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

Allow user to set their own custom activation commands for the interpreter #8870

Closed
karrtikr opened this issue Dec 2, 2019 · 11 comments
Closed
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality needs proposal Need to make some design decisions

Comments

@karrtikr
Copy link

karrtikr commented Dec 2, 2019

Upon creating a terminal, an activation command to activate the current environment is sent to the terminal.

There are often issues like #8770, where environment is not activated due to extension sending the wrong activation commands.

Example: An activation command used to work with conda x.x.x, but conda y.y.y changed something so it is no longer valid. And if the extension does not keep up with the change, activating the environment would fail.

Allow user to set their own activation commands for the interpreter they're using. Often they know the correct activation commands as you can notice in #8770.

@karrtikr karrtikr added feature-request Request for new features or functionality triage-needed Needs assignment to the proper sub-team area-environments Features relating to handling interpreter environments needs decision and removed triage-needed Needs assignment to the proper sub-team labels Dec 2, 2019
@DonJayamanne
Copy link

@karrtikr @karthiknadig Please see comments in #8770 (comment)

I agree with you about omething so it is no longer valid. And if the extension does not keep up with the change,
And also I believe in an alternative solution, which is to fix/deprecate the hack instead of allowing users to customize the commands. Fix it for everyone. E.g. on my machine i too don't need the double activation.

I believe only seasoned users would go into VS Code settings to customize the activation commands. Other would probably give up and just activate manually or file issues or even worse..

@karrtikr
Copy link
Author

karrtikr commented Dec 3, 2019

And also I believe in an alternative solution, which is to fix/deprecate the hack instead of allowing users to customize the commands

Yes we should definitely fix it. We should do our best in sending the correct default commands. But having support for custom activation command also seems like a nice workaround to have for the user.

There're things we can do for discoverability. For eg. we can test if an activation failed for a user and notify them of this option.

@xq114

This comment has been minimized.

@DonJayamanne

This comment has been minimized.

@luabud luabud added needs proposal Need to make some design decisions and removed needs decision labels Feb 12, 2020
@1st
Copy link

1st commented Mar 26, 2020

+1 I also need to set some env variables (db name, db user and password) when opening a new terminal tab. I do it now by source ~/.zshrc where I have such variables set. But will be better to set these variables per-project, because each project needs its own DB and credentials, and I don’t want to store them in a file like settings.py for known reason.

Waiting for this feature. Hope that this will help me to set env variables in the terminal, as well as do other shell commands (like change directory to src when open a new terminal window).

@otisdog8
Copy link

+1 This would allow me to fix an issue that I've been having #13854, and would allow me to quickly and easily fix similar issues without building from source or waiting for a release. It also gives users more control over their setup.

@GuillaumeDesforges
Copy link

GuillaumeDesforges commented Dec 17, 2020

+1 Same for me with #14794, it would even allow to use Nix shell

@raratiru
Copy link

raratiru commented Dec 19, 2020

Is #12020 going to help?

@Khazbs
Copy link

Khazbs commented Nov 28, 2021

Came here from #9917. There are a lot of things VSCode doesn't do right, and activating a Python virtual environment by source-ing the activate script instead of using workon is definitely one of them. The postactivate script is just ignored. Bummer! I really hope this feature would allow us to workon our virtual environments.

@gerardlt
Copy link

gerardlt commented Mar 8, 2022

As a workaround for the virtualenvwrapper use case, the following rather hideous hack could be added to your premkvirtualenv hook:

envname="${1}"
envpath="${WORKON_HOME}/${envname}"

echo "Patching activate script for ${envname} to always call virtualenvwrapper"

cat /dev/fd/3 "${envpath}/bin/activate" /dev/fd/4 3<< EOP 4<<EOS > "${envpath}/bin/patched_activate"
# This file has been modified by virtualenvwrapper premkvirtualenv script

if [ "\${BASH_SOURCE-}" = "\$0" ]; then
    echo "You must source this script: \\$ source \$0" >&2
    exit 33
fi

# Presence of cd_after_activate var is used as a proxy to indicate running from workon function
if [[ ! -v cd_after_activate ]]; then
    echo "activate sourced directly - calling virtualenvwrapper"
    workon ${envname}
else
EOP
fi
EOS

mv "${envpath}/bin/activate" "${envpath}/bin/unpatched_activate"
mv "${envpath}/bin/patched_activate" "${envpath}/bin/activate"

Any virtual envs created with that will always call workon if the activate script is sourced directly (not via workon).
With a little thought, the same script can be used to modify existing virtual envs.

It's not nice, might not be posix compliant, and I can't speak for the security of it, but it does make the relevant hooks get run.

Would be much nicer to get proper custom activation commands though! :-)

@cwebster-99
Copy link
Member

Closing as we do not plan to implement this change in the Python extension.

@cwebster-99 cwebster-99 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality needs proposal Need to make some design decisions
Projects
None yet
Development

No branches or pull requests