diff --git a/package.json b/package.json index e1605c2..8854d43 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "ms-vscode.cpptools-extension-pack", "ms-vscode.vscode-serial-monitor", "marus25.cortex-debug", - "paulober.pico-w-go" + "paulober.pico-w-go", + "ms-python.python" ], "main": "./dist/extension.cjs", "markdown": "github", @@ -64,7 +65,8 @@ }, "activationEvents": [ "workspaceContains:./pico_sdk_import.cmake", - "onWebviewPanel:newPicoProject" + "onWebviewPanel:newPicoProject", + "onWebviewPanel:newPicoMicroPythonProject" ], "contributes": { "commands": [ @@ -273,6 +275,7 @@ "typescript-eslint": "^8.1.0" }, "dependencies": { + "@vscode/python-extension": "^1.0.5", "adm-zip": "^0.5.14 <0.5.15", "ini": "^4.1.3", "rimraf": "^5.0.7", diff --git a/src/utils/githubREST.mts b/src/utils/githubREST.mts index 74cd1f7..51c95d0 100644 --- a/src/utils/githubREST.mts +++ b/src/utils/githubREST.mts @@ -60,15 +60,13 @@ export const PYENV_REPOSITORY_URL = "https://github.com/pyenv/pyenv.git"; export function ownerOfRepository(repository: GithubRepository): string { switch (repository) { case GithubRepository.picoSDK: + case GithubRepository.tools: + case GithubRepository.picotool: return "raspberrypi"; case GithubRepository.cmake: return "Kitware"; case GithubRepository.ninja: return "ninja-build"; - case GithubRepository.tools: - return "raspberrypi"; - case GithubRepository.picotool: - return "raspberrypi"; } } diff --git a/src/webview/newMicroPythonProjectPanel.mts b/src/webview/newMicroPythonProjectPanel.mts index 2bc6c1e..4a582f9 100644 --- a/src/webview/newMicroPythonProjectPanel.mts +++ b/src/webview/newMicroPythonProjectPanel.mts @@ -22,6 +22,7 @@ import { import which from "which"; import { existsSync } from "fs"; import { join } from "path"; +import { PythonExtension } from "@vscode/python-extension"; interface SubmitMessageValue { projectName: string; @@ -37,10 +38,11 @@ export class NewMicroPythonProjectPanel { private readonly _panel: WebviewPanel; private readonly _extensionUri: Uri; private readonly _settings: Settings; - private readonly _logger: Logger = new Logger("NewProjectPanel"); + private readonly _logger: Logger = new Logger("NewMicroPythonProjectPanel"); private _disposables: Disposable[] = []; private _projectRoot?: Uri; + private _pythonExtensionApi?: PythonExtension; public static createOrShow(extensionUri: Uri, projectUri?: Uri): void { const column = window.activeTextEditor @@ -347,6 +349,9 @@ print("Finished.")\r\n`; "web", "raspberry-128.png" ); + if (!this._pythonExtensionApi) { + this._pythonExtensionApi = await PythonExtension.api(); + } const html = await this._getHtmlForWebview(this._panel.webview); if (html !== "") { @@ -407,8 +412,13 @@ print("Finished.")\r\n`; Uri.joinPath(this._extensionUri, "web", "raspberrypi-nav-header-dark.svg") ); - // TODO: maybe use python extension api - // TODO: check python version, workaround, ownly allow python3 commands on unix + // TODO: add support for onDidChangeActiveEnvironment and filter envs that don't directly point + // to an executable + const environments = this._pythonExtensionApi?.environments; + const knownEnvironments = environments?.known; + const activeEnv = environments?.getActiveEnvironmentPath(); + + // TODO: check python version, workaround, only allow python3 commands on unix const isPythonSystemAvailable = (await which("python3", { nothrow: true })) !== null || (await which("python", { nothrow: true })) !== null; @@ -484,29 +494,54 @@ print("Finished.")\r\n`;
- ${ - process.platform === "darwin" || process.platform === "win32" - ? ` -
- - - ${ - isPythonSystemAvailable - ? `
- - -
` - : "" - } - -
- - - -
+
+ + + ${ + knownEnvironments && knownEnvironments.length > 0 + ? ` +
+ + + + +
+ ` + : "" + } + + ${ + process.platform === "darwin" || + process.platform === "win32" + ? ` + ${ + isPythonSystemAvailable + ? `
+ +
` - : "" - } + : "" + } + +
+ + + +
` + : "" + } +
diff --git a/web/mpy/main.js b/web/mpy/main.js index 2262119..2acf3f0 100644 --- a/web/mpy/main.js +++ b/web/mpy/main.js @@ -86,13 +86,12 @@ var submitted = false; } } if (pythonVersionRadio.length == 0) { - // default to python mode 1 == System version - pythonMode = 1; + // default to python mode 0 == python ext version + pythonMode = 0; } // if python version is null or not a number, smaller than 0 or bigger than 3, set it to 0 if (pythonMode === null || isNaN(pythonMode) || pythonMode < 0 || pythonMode > 3) { - // TODO: first check if defaul is supported pythonMode = 0; console.debug('Invalid python version value: ' + pythonMode.toString()); vscode.postMessage({ @@ -103,11 +102,14 @@ var submitted = false; return; } - if (pythonMode == 2) { + if (pythonMode === 0) { + const pyenvKnownSel = document.getElementById("sel-pyenv-known"); + pythonPath = pyenvKnownSel.value; + } else if (pythonMode === 2) { const files = document.getElementById('python-path-executable').files; if (files.length == 1) { - cmakePath = files[0].name; + pythonPath = files[0].name; } else { console.debug("Please select a valid python executable file"); vscode.postMessage({ diff --git a/yarn.lock b/yarn.lock index 7697fab..c578380 100644 --- a/yarn.lock +++ b/yarn.lock @@ -555,6 +555,13 @@ __metadata: languageName: node linkType: hard +"@vscode/python-extension@npm:^1.0.5": + version: 1.0.5 + resolution: "@vscode/python-extension@npm:1.0.5" + checksum: 10/aeaa1ee9275f8679aa745c3096a68e1952328b8c7de90e1665f369e321dafb3e1271d42c32e4f8d6a3c92f6cdbb4aaef22cc45101764a623900efc4f3dfd3270 + languageName: node + linkType: hard + "abbrev@npm:^1.0.0": version: 1.1.1 resolution: "abbrev@npm:1.1.1" @@ -2197,6 +2204,7 @@ __metadata: "@types/uuid": "npm:^10.0.0" "@types/vscode": "npm:^1.92.0" "@types/which": "npm:^3.0.4" + "@vscode/python-extension": "npm:^1.0.5" adm-zip: "npm:^0.5.14 <0.5.15" eslint: "npm:^9.9.0" eslint-config-prettier: "npm:^9.1.0"