|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import shutil |
| 4 | +import sys |
4 | 5 | from functools import partial |
5 | 6 | from subprocess import CalledProcessError |
6 | 7 | from typing import Any, override |
@@ -53,45 +54,24 @@ async def ensure_basedpyright_installed() -> None: |
53 | 54 | if shutil.which("basedpyright-langserver"): |
54 | 55 | return |
55 | 56 |
|
56 | | - # Try uv tool install |
57 | | - if shutil.which("uv"): |
58 | | - logger.info("Attempting to install basedpyright via uv tool install...") |
59 | | - try: |
60 | | - await anyio.run_process(["uv", "tool", "install", "basedpyright"]) |
61 | | - logger.info("Successfully installed basedpyright via uv") |
62 | | - return |
63 | | - except CalledProcessError: |
64 | | - logger.warning( |
65 | | - "Failed to install basedpyright via uv, trying other methods..." |
66 | | - ) |
67 | | - |
68 | | - # Try npm |
69 | | - if shutil.which("npm"): |
70 | | - logger.info("Attempting to install basedpyright via npm...") |
71 | | - try: |
72 | | - await anyio.run_process(["npm", "install", "-g", "basedpyright"]) |
73 | | - logger.info("Successfully installed basedpyright via npm") |
74 | | - return |
75 | | - except CalledProcessError: |
76 | | - logger.warning( |
77 | | - "Failed to install basedpyright via npm, trying other methods..." |
78 | | - ) |
79 | | - |
80 | | - # Try pip |
81 | | - import sys |
82 | | - |
83 | | - logger.info("Attempting to install basedpyright via pip...") |
84 | | - try: |
85 | | - await anyio.run_process( |
86 | | - [sys.executable, "-m", "pip", "install", "basedpyright"] |
87 | | - ) |
88 | | - logger.info("Successfully installed basedpyright via pip") |
89 | | - return |
90 | | - except CalledProcessError as e: |
91 | | - raise ServerInstallationError( |
92 | | - "Could not install basedpyright-langserver. Please install it manually with 'uv tool install basedpyright', 'npm install -g basedpyright' or 'pip install basedpyright'. " |
93 | | - "See https://github.com/detachhead/basedpyright for more information." |
94 | | - ) from e |
| 57 | + installers = [ |
| 58 | + (["uv", "tool", "install", "basedpyright"], "uv"), |
| 59 | + (["npm", "install", "-g", "basedpyright"], "npm"), |
| 60 | + ([sys.executable, "-m", "pip", "install", "basedpyright"], "pip"), |
| 61 | + ] |
| 62 | + |
| 63 | + for cmd, name in installers: |
| 64 | + if shutil.which(cmd[0]): |
| 65 | + try: |
| 66 | + logger.info("Attempting to install basedpyright via {}...", name) |
| 67 | + await anyio.run_process(cmd) |
| 68 | + return |
| 69 | + except CalledProcessError: |
| 70 | + continue |
| 71 | + |
| 72 | + raise ServerInstallationError( |
| 73 | + "Could not install basedpyright. Please install it manually with 'uv tool install basedpyright', 'npm install -g basedpyright' or 'pip install basedpyright'." |
| 74 | + ) |
95 | 75 |
|
96 | 76 |
|
97 | 77 | BasedpyrightLocalServer = partial( |
|
0 commit comments