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

Investigate where we should implicitly trigger the Python: Create Environment command #20133

Closed
brettcannon opened this issue Nov 1, 2022 · 11 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality needs spike Label for issues that need investigation before they can be worked on. on-testplan Added to test plan

Comments

@brettcannon
Copy link
Member

Two options:

  1. Prompt the user if they want to create an environment
  2. If there is a pyproject.toml or requirements.txt file in the workspace, run the Create Environment command (or ask the user to select a virtual environment or create environment)
@brettcannon brettcannon added the feature-request Request for new features or functionality label Nov 1, 2022
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Nov 1, 2022
@luabud
Copy link
Member

luabud commented Nov 3, 2022

We can start with option 2 as it shouldn't be hard to expand it to 1 if we want to?

@luabud luabud added needs PR Ready to be worked on and removed triage-needed Needs assignment to the proper sub-team labels Nov 3, 2022
@karrtikr
Copy link

Related: #4606. If we were to add such a prompt it could be used here.

@karrtikr karrtikr added the area-environments Features relating to handling interpreter environments label Dec 22, 2022
@cwebster-99
Copy link
Member

Investigate where we should implicitly trigger the Python: Create Environment command.

First school of thought are ideas that would result in triggers upon open.

  • When we detect a requirements.txt or pyproject.toml file in a workspace with no environment. This would catch users prior to installing requirements files which would likely happen before they hit the run button.
  • When the user opens a folder/workspace where we do not detect an environment

Alternatively, we can look at "just in time" triggers. A few ideas on what this can look like:

  • Run button when we don't detect an environment. Although, using the Run button wholistically is not ideal. We hypothesize there is a good number of users that have projects that do not use packages and/or their use of packages do not exceed the stdlib. We could use the Run button as a trigger for the Python: Create Environment command when we 1.) detect a requirements.txt file in the workspace 2.) detect a pyproject.toml file in the workspace 3.) detect import statements/unresolved imports
  • We can apply the same thinking to Run with/without debugging when we don't detect an environment
  • Leverage unresolved imports messaging. Is there a way we could integrate the flow with the quick fix - "Create and environment and install" ?

Final area of thought revolves around increased discoverability of the Python: Create Environment command. Are there places we can add UI elements that lead to the Python: Create Environment command:

  • Icon on the requrements.txt file in the explorer menu or within the file. "Create Environment and install requirements"
  • A workflow that creates a new workspace and an environment (related to #20649)
  • Create environment option within the Python: Select Interpreter dropdown
  • Icon on the status bar (likely not discoverable)

All of these items would require further discussion and partnership to execute but something to get the wheels turning :)

@luabud
Copy link
Member

luabud commented Feb 7, 2023

I particularly like the idea of only showing it when people try to run or debug a file but there are unresolved imports in their file (even better if it's in the workspace).

@karrtikr do you know whether this is possible today? I.e. does the Python extension get such context from Pylance?

@karrtikr

This comment was marked as resolved.

@karrtikr
Copy link

karrtikr commented Feb 8, 2023

Yes, we can use vscode.languages.getDiagnostics() to get all errors in the Problems window, and look for the error code reportMissingImports 🙂

@karthiknadig karthiknadig changed the title Have run button leverage the Create Environment command Investigate where we should implicitly trigger the Python: Create Environment command Apr 4, 2023
@karthiknadig karthiknadig added this to the April 2023 milestone Apr 4, 2023
@karthiknadig karthiknadig removed this from the April 2023 milestone Apr 21, 2023
@rchiodo
Copy link

rchiodo commented May 4, 2023

The problem with the get diagnostics solution (at least if you're using pylance) is that we only report diagnostics for open files. Not every file in the workspace (unless the user changes a setting).

However, there is a way to query pylance for the diagnostics for a specific file. We don't currently support this method (AFAICT) but shouldn't be too hard to add. (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_diagnostic)

So instead of querying the problems window, you'd query pylance with the file path to the requirements.txt or the pyproject.toml file.

@karrtikr
Copy link

karrtikr commented May 4, 2023

Here we're only trying to see if the file which is to be run or debugged has unresolved imports, so it should be open.

Also I'm not sure we should querying for every closed file in the repository as that would mean Pylance has to analyze the entire repository and not just the opened files.

@rchiodo
Copy link

rchiodo commented May 4, 2023

Also I'm not sure we should querying for every closed file in the repository as that would mean Pylance has to analyze the entire repository and not just the opened files.

Sorry I misunderstood, I thought you were querying the requirements.txt file for unresolved imports. I meant this wouldn't show any unresolved imports unless it was already open.

If you only need the unresolved import for the python file, then it should already work.

@luabud
Copy link
Member

luabud commented Sep 25, 2023

we ended up going with a notification prompt being shown when users attempt to run code (through any of our run commands like run in terminal or run selection in terminal, or when they start debugging), AND the following conditions are met:

  • The workspace does not have ".venv" or ".conda"
  • The selected interpreter is a global or system python
  • There are NO poetry.lock, pipfile, .python_version etc in the workspace
  • There IS either some file that matches "requirement.txt" or "requirements/*.txt"

@luabud luabud closed this as completed Sep 25, 2023
@luabud luabud added needs spike Label for issues that need investigation before they can be worked on. and removed needs PR Ready to be worked on labels Sep 25, 2023
@github-actions github-actions bot removed the needs spike Label for issues that need investigation before they can be worked on. label Sep 25, 2023
@luabud
Copy link
Member

luabud commented Sep 25, 2023

This is the issue tracking the work: #21965

@luabud luabud added the needs spike Label for issues that need investigation before they can be worked on. label Sep 25, 2023
@karthiknadig karthiknadig added the on-testplan Added to test plan label Sep 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 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 spike Label for issues that need investigation before they can be worked on. on-testplan Added to test plan
Projects
None yet
Development

No branches or pull requests

6 participants