sublimelsp / LSP-pyright

Python support for Sublime's LSP plugin provided through microsoft/pyright.
MIT License
126 stars 13 forks source link

VSCode's Python environment discovery #340

Open jfcherng opened 2 months ago

jfcherng commented 2 months ago

Repository: https://github.com/microsoft/python-environment-tools

They introduced this in VSCode v1.91.0. That basically has the same purpose with https://github.com/sublimelsp/LSP-pyright/blob/master/plugin/venv_finder.py

It doesn't have Releases on Github but there are artifacts in the CI. E.g., https://github.com/microsoft/python-environment-tools/actions/runs/9775250841

But those CI artifacts will be no longer available within days. Here are re-uploaded backups...


Here's an output example of the pet tool:

$ pet --help

Usage: pet.exe [COMMAND]

Commands:
  find    Finds the environments and reports them to the standard output
  server  Starts the JSON RPC Server
  help    Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

$ pet find

It seems only to search Venv in the EXACTLY current directory. If I run the command in D:\Repo\LSP-bash\plugin, it won't find a Venv but only WindowsRegistry.

Environment (WindowsRegistry)
   Display-Name: Python 3.12 (64-bit)
   Executable  : C:\Users\jfcherng\AppData\Local\Programs\Python\Python312\python.exe
   Version     : 3.12.4
   Prefix      : C:\Users\jfcherng\AppData\Local\Programs\Python\Python312
   Architecture: x64
   Symlinks    : "C:\\Users\\jfcherng\\AppData\\Local\\Programs\\Python\\Python312\\python.exe"

Environment (Venv)
   Executable  : D:\Repo\LSP-bash\.venv\Scripts\python.exe
   Prefix      : D:\Repo\LSP-bash\.venv
   Symlinks    : "D:\\Repo\\LSP-bash\\.venv\\Scripts\\python.exe"

Breakdown by each locator:
--------------------------
Conda                : 13.1382ms
PipEnv               : 200ns
Poetry               : 979.8µs
PyEnv                : 478.7µs
Venv                 : 2.5µs
VirtualEnv           : 200ns
VirtualEnvWrapper    : 100ns
WindowsRegistry      : 3.2133ms
WindowsStore         : 115.8µs

Breakdown for finding Environments:
-----------------------------------
Using locators       : 16.4946ms
PATH Variable        : 85.6641ms
Global virtual envs  : 756.3µs
Custom search paths  : 9.0257ms

Environments (2):
------------------
Venv                 : 1
WindowsRegistry      : 1

Refresh completed in 88ms