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

Test prototype to implicitly use environment variables for terminal activation #20884

Closed
3 tasks done
karrtikr opened this issue Mar 20, 2023 · 2 comments
Closed
3 tasks done

Comments

@karrtikr
Copy link

karrtikr commented Mar 20, 2023

Refs: #11039

Complexity: 5

Create Issue


Requirements

  • Pre release build of the python extension
  • VSCode Insiders
  • Do not use a multiroot workspace
  • Virtual or conda environment

Verification

  • Add following to user settings:
"python.experiments.optInto": ["pythonTerminalEnvVarActivation"]
  • Add following workspace folder settings:
"python.terminal.activateEnvInCurrentTerminal": true,
"python.terminal.activateEnvironment": true
  • Reload window and activate Python extension by opening a Python file.

  • Select a virtual or conda environment using Python: Select Interpreter command.

  • Open terminal, no activation commands should be sent.

  • Make sure terminal is activated using the selected environment. You can run the following script using python <script> in terminal to verify:

    import sys
    import os
    
    print('executable', sys.executable)
    print('sys.path', sys.path)
    print('PATH', os.environ['PATH'])
    Output should look something similar to this for `.venv` created via `python -m venv .venv`, make sure `PATH` begins with the activated environment, and `sys.path` has the appropriate directories as well.

    executable: C:\Users\karraj\OneDrive - Microsoft\Desktop\folders\crap\.venv\Scripts\python.exe
    sys.path: ['', 'C:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\crap\\hellozsas', 'c:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\crap\\.conda\\python38.zip', 'c:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\crap\\.conda\\DLLs', 'c:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\crap\\.conda\\lib', 'c:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\crap\\.conda', 'C:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\crap\\.venv', 'C:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\crap\\.venv\\lib\\site-packages']
    PATH: C:\Users\karraj\OneDrive - Microsoft\Desktop\folders\crap\.venv\Scripts;C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Users\karraj\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\Git LFS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Docker\Docker\resources\bin;C:\Users\karraj\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\karraj\AppData\Local\Programs\Python\Python37\;C:\Users\karraj\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\karraj\AppData\Local\Programs\Python\Python39\;C:\Users\karraj\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\karraj\AppData\Local\Programs\Python\Python36\;C:\Users\karraj\.pyenv\pyenv-win\bin;C:\Users\karraj\.pyenv\pyenv-win\shims;C:\Program Files\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program Files (x86)\Common Files\Microsoft Shared\Microsoft Online Services;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\OpenSSH;C:\Program Files\Git\cmd;C:\Users\karraj\AppData\Roaming\nvm;C:\Program Files\nodejs;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\karraj\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\karraj\AppData\Roaming\Python\Python38\Scripts;C:\Users\karraj\AppData\Local\Programs\Python\Python38\;C:\Users\karraj\Miniconda3;C:\Users\karraj\Miniconda3\Library\mingw-w64\bin;C:\Users\karraj\Miniconda3\Library\usr\bin;C:\Users\karraj\Miniconda3\Library\bin;C:\Users\karraj\Miniconda3\Scripts;C:\Users\karraj\AppData\Local\Microsoft\WindowsApps;C:\Users\karraj\AppData\Local\Programs\Microsoft VS Code Insiders\bin;c:\Users\karraj\AppData\Roaming\Code - Insiders\User\globalStorage\ms-vscode-remote.remote-containers\cli-bin;C:\Users\karraj\AppData\Local\Microsoft\WindowsApps;C:\Users\karraj\AppData\Local\Programs\Microsoft VS Code\bin;;C:\Users\karraj\.vscode-server-launcher\bin;C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\bin;
    

  • The prompt should be visible in most cases (create an issue if it points to the incorrect env):

    If nothing is visible, please add a comment here with the type of shell, OS and the Python logs: Prompt does not show up for terminal activation #20827.

  • Try changing interpreters, terminals should be re-activated with the new env. If a used terminal is currently open, a warning sign should appear to the right of terminal:
    image

  • Try changing shells using Select default profile command, verify terminals are re-activated.

  • Lastly, verify debugging when using "python" option works.

    • Add the following to launch.json:
    {
        "name": "Test Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "justMyCode": true,
        "python": "${command:python.interpreterPath}"
    }
    
    • Replace ${command:python.interpreterPath} with path to an interpreter. This is similar to sys.executable printed earlier, for eg. C:\Users\karraj\OneDrive - Microsoft\Desktop\folders\crap\.venv\Scripts\python.exe. Call it A.
    • Make sure to select a interpreter via Python: Select Interpreter that is different from the "python" specified earlier, call it B.
    • Debug the earlier python script using the above configuration, make sure the output is activated using interpreter A, and not B.
@andreamah
Copy link

Awesome! Also, is this testplan meant to be for the April milestone? I believe that it should be for March?

@karrtikr
Copy link
Author

Yep, not sure why April was added.

@karrtikr karrtikr modified the milestones: April 2023, March 2023 Mar 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants