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

Get "select virtual environment for the worskpace" prompt to show up regardless of pythonpath setting #5499

Closed
luabud opened this issue Apr 26, 2019 · 5 comments
Assignees
Labels
feature-request Request for new features or functionality

Comments

@luabud
Copy link
Member

luabud commented Apr 26, 2019

#4908 but right now we're displaying it only only if there isn't an interpreter path set in the settings.json file. We should display it also when a global interpreter (i.e. not a virtual environment) is set there.

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Apr 26, 2019
@DonJayamanne DonJayamanne added needs PR feature-request Request for new features or functionality labels Apr 29, 2019
@ghost ghost removed triage-needed Needs assignment to the proper sub-team labels Apr 29, 2019
@DonJayamanne DonJayamanne added triage-needed Needs assignment to the proper sub-team feature-interpreter labels Apr 29, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Apr 29, 2019
@DonJayamanne DonJayamanne added this to the 2019 - August Sprint 16 milestone Aug 14, 2019
@DonJayamanne
Copy link

Prescribed solution

  • Display prompt regardless (currently we have an if condition that displays prompt only if no interpreter has been selected.

@ericsnowcurrently
Copy link
Member

[using the most recent insiders build of the extension ("2019.9.33401-rc")]
[3 "system" Pythons installed: 2.7, 3.6, and 3.7]

I was able to verify that, if "python.pythonPath" is not set in my workspace settings.json file, I get prompted to switch to the new environment (a la #4908). However, if "python.pythonPath" is set then I still do not get prompted.

steps:

  1. create a new workspace with an empty "spam.py"
  2. verify that settings.json is empty
  3. in the workspace directory run python3 -m venv .venv
  1. click on "no" (not on "stop prompting me")
  2. verify that settings.json is still empty
  3. click on the Python version in the status bar and pick one of the system Pythons
  4. verify that settings.json now has a "python.pythonPath" entry
  5. delete the .venv directory created in step 3
  6. in the workspace directory run python3 -m venv .venv

At this point I expected to be prompted, but was not.

(possibly related: #7132)

@ericsnowcurrently
Copy link
Member

FWIW, if I reload the window between steps 8 and 9 then it works as expected.

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Aug 29, 2019

This is likely an upstream VS Code issue. It is ignoring the re-creation of the .venv directory at step 9. From what Kartik said, this isn't a problem on Windows (I'm testing on Linux).

details

Order of events:

  1. src/client/interpreter/locators/services/workspaceVirtualEnvWatcherService.ts
    • during activation we register an "onDidCreate" event handler on a new filesystem watcher
    • we only watch for files named "python" (or "python.exe" on Windows)
    • we create an internal event to indicate that a new virtual environment was created
  2. src/client/interpreter/virtualEnvs/virtualEnvPrompt.ts
    • we register a handler on that internal event
  3. src/client/interpreter/locators/services/workspaceVirtualEnvWatcherService.ts
    • if the filesystem watcher emits the "onDidCreate" event for files named "python" then we fire the internal event
  4. src/client/interpreter/virtualEnvs/virtualEnvPrompt.ts
    • if the internal event is fired then the handler (maybe) creates the prompt

I tried debugging this. First I checked to see if that "internal" event was fired. It did for step 1 in my earlier comment. For step 9 it did not. So then I checked to see if the filesystem watcher fired the "onDidCreate" event for step 9. It did not.

This means that, on linux at least, the filesystem watcher (upstream VS Code code) is ignoring the re-creation of the .venv directory. I wouldn't be surprised if there is some sort of cache involved which isn't getting flushed when the directory is deleted in step 8. This does not seem to be a problem on Windows.

Also, all the events fire properly if I create a new virtual environment with a different name.

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Aug 29, 2019

We're okay to consider this validated. Aside from the corner case I found, everything works as expected (i.e. if I move step 6 to right before step 3). After talking with @luabud, we're okay to release with the edge case. I'll open a separate issue (#7147) to track it.

@ghost ghost removed the needs PR label Aug 29, 2019
@ericsnowcurrently ericsnowcurrently removed their assignment Aug 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants