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

Incorrect virtualenv activate script executed | Nushell #22036

Closed
alex-way opened this issue Sep 20, 2023 · 7 comments
Closed

Incorrect virtualenv activate script executed | Nushell #22036

alex-way opened this issue Sep 20, 2023 · 7 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@alex-way
Copy link

alex-way commented Sep 20, 2023

Type: Bug

Behaviour

Expected vs. Actual

When opening a new terminal window (Nushell) the incorrect activate script is being executed for my virtualenvironment:

& C:/Users/WayA/AppData/Local/pypoetry/Cache/virtualenvs/cloud-billing-VTFyPfP7-py3.11/Scripts/Activate.ps1

Rather than:

overlay use C:/Users/WayA/AppData/Local/pypoetry/Cache/virtualenvs/cloud-billing-VTFyPfP7-py3.11/Scripts/activate.nu

Steps to reproduce:

  1. Open a new nushell terminal window

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.0
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Poetry
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

User Settings


venvPath: "<placeholder>"

venvFolders: "<placeholder>"

languageServer: "Pylance"

linting
• pylamaArgs: "<placeholder>"
• pylintArgs: "<placeholder>"

formatting
• provider: "none"

testing
• pytestEnabled: true

Extension version: 2023.16.0
VS Code version: Code 1.82.2 (abd2f3db4bdb28f9e95536dfa84d8479f1eb312d, 2023-09-14T05:55:25.390Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz (8 x 2611)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.69GB (14.92GB free)
Process Argv
Screen Reader no
VM 0%
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 20, 2023
@alex-way
Copy link
Author

I will also add that this has been working up until the most recent VSCode update, although it does seem that the extension was also updated yesterday. Will try to find any more relevant changes which may have caused this bug.

@alex-way
Copy link
Author

Rolling back to v2023.14.0 doesn't fix the issue so I'm going to assume this is some kind've bug in vscode (Perhaps they've changed some kind've API)

@alex-way
Copy link
Author

Found some additional info in the output which is seeming to suggest that my current shell is commandPrompt:

2023-09-20 11:16:35.437 [info] > ~/AppData/Local/pypoetry/Cache/virtualenvs/cloud-billing-VTFyPfP7-py3.11/Scripts/activate.bat && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2023.16.0/pythonFiles/printEnvVariables.py
2023-09-20 11:16:35.437 [info] shell: commandPrompt

@alex-way
Copy link
Author

alex-way commented Sep 20, 2023

Okay I think I've figured it out.

The following line is looking for the shell being named nu. https://github.com/microsoft/vscode-python/blob/main/src/client/common/terminal/shellDetectors/baseShellDetector.ts#L33

Mine was called Nushell (via the official nushell extension):

image

Changing to Nu as the default correctly activates the overlay.

However, I will say that I think we should be using both nu and Nushell as the default name in the extension is Nushell: https://github.com/nushell/vscode-nushell-lang/blob/main/client/src/extension.ts#L106

@alex-way alex-way changed the title Incorrect virtualenv activate script executed Incorrect virtualenv activate script executed | Nushell Sep 20, 2023
@karrtikr
Copy link

karrtikr commented Oct 26, 2023

@alex-way Thanks for the looking into it.

The following line is looking for the shell being named nu. https://github.com/microsoft/vscode-python/blob/main/src/client/common/terminal/shellDetectors/baseShellDetector.ts#L33

The code you pointed to looks into the path of the shell, not the name. It checks whether that path of shells ends with "nu" or "NU" or any case insensitive comparision.

In case of Nushell, the path of the shell reported to us by vscode.env.shell (doc link) is Powershell, which seems like a bug on either VS Code or Nushell extension.

In case of Nu, the path to shell is actually the path to nu.exe, so it works out fine.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
@JamzumSum
Copy link

In case of Nu, the path to shell is actually the path to nu.exe, so it works out fine.

const basePath = shellPath.replace(/\.exe$/, '');

@karrtikr Could we use a case-insensitive replace?

const basePath = shellPath.replace(/\.exe$/i, '');

Since I found my Nushell profile is giving a C:\Program Files\nu\bin\nu.EXE executable path, in which the .EXE extension cannot be removed and the IS_NUSHELL test does not pass.

@karrtikr
Copy link

Sure, if you send up a PR for it we would be happy to take it.

JamzumSum added a commit to JamzumSum/vscode-python that referenced this issue Oct 31, 2023
Use case-insensitive regex to remove `.exe`  extension.

microsoft#22036 (comment)
JamzumSum added a commit to JamzumSum/vscode-python that referenced this issue Nov 1, 2023
Use case-insensitive regex to remove `.exe`  extension.

microsoft#22036 (comment)
karrtikr pushed a commit that referenced this issue Nov 7, 2023
Use case-insensitive regex to remove `.exe`  extension.

See:
#22036 (comment)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants