Skip to content

TPI: Shell Startup Activation #340

@karthiknadig

Description

@karthiknadig

Refs: #227

Complexity: 3

Create Issue


Requirements

Install the latest pre-release of the Python Environments extension: https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-python-envs
add the following to your user settings.json and reload

    "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

Important (before start)

NOTE the following steps will change your shell startup scripts. Please take a backup of your shell startup.

Powershell:

  1. Open external powershell terminal
  2. See the value of $profile variable.
    Image

Bash/sh:

~/.bashrc

Git bash:

windows: %USERPROFILE%/.bashrc
other: ~/.bashrc

zsh:

~/.zshrc

fish:

~/.config/fish/config.fish

Setup

  1. Do this external to VS Code. Setup a directory with a python file and an environment. Creating python environment can be done by running python -m venv .venv from the workspace directory.
  2. Open that workspace and install the above extension. Make sure both python extension and python envs extension are activated. You should see python version in the bottom right corner if you have a python file open.
  3. Note: You may need to reload, if you already had python extension. (you will see 2 python versions in the bottom right corner)

Testing

  1. Go to settings and change this python-envs.terminal.autoActivationType setting to shellStartup.
  2. If you have, terminals open, you will see a modal asking you to update shell profiles for the open terminals.
  3. If you don't have any terminals open then you will not see the modal until you create a terminal
  4. Terminal should be activated with the environment you have selected. Already, open terminals will execute a command. Newly, opened terminals after settings and profile change should not execute a command on open.
  5. Opening a terminal in vscode should have the virtual environment activated. A test is to print VRITUAL_ENV env variable for your shell. like echo $VIRTUAL_ENV. Your prompt may also show .venv.
  6. Reloading VS Code should give you activated terminals. you should not see any modals asking you to update shell startup. This is a one time change.
  7. There is a command to revert all the changes: Python Envs: Revert Shell Startup Script Changes. running this should also switch you back to command mode in the python-envs.terminal.autoActivationType.
  8. Selecting Cancel when the profile update modal is shown only hides it in your current VS Code session. We plan on persisting explicit Cancel. Provide Feedback on your expectation.

Known Issues: ✋

  1. Command Prompt: You have to restart VS Code after updating command prompt profile. We don't automatically do this in this build.

Important (Finishing TPI)

NOTE: restore your profiles

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions