@@ -22,6 +22,7 @@ import {
2222import which from "which" ;
2323import { existsSync } from "fs" ;
2424import { join } from "path" ;
25+ import { PythonExtension } from "@vscode/python-extension" ;
2526
2627interface SubmitMessageValue {
2728 projectName : string ;
@@ -37,10 +38,11 @@ export class NewMicroPythonProjectPanel {
3738 private readonly _panel : WebviewPanel ;
3839 private readonly _extensionUri : Uri ;
3940 private readonly _settings : Settings ;
40- private readonly _logger : Logger = new Logger ( "NewProjectPanel " ) ;
41+ private readonly _logger : Logger = new Logger ( "NewMicroPythonProjectPanel " ) ;
4142 private _disposables : Disposable [ ] = [ ] ;
4243
4344 private _projectRoot ?: Uri ;
45+ private _pythonExtensionApi ?: PythonExtension ;
4446
4547 public static createOrShow ( extensionUri : Uri , projectUri ?: Uri ) : void {
4648 const column = window . activeTextEditor
@@ -347,6 +349,9 @@ print("Finished.")\r\n`;
347349 "web" ,
348350 "raspberry-128.png"
349351 ) ;
352+ if ( ! this . _pythonExtensionApi ) {
353+ this . _pythonExtensionApi = await PythonExtension . api ( ) ;
354+ }
350355 const html = await this . _getHtmlForWebview ( this . _panel . webview ) ;
351356
352357 if ( html !== "" ) {
@@ -407,8 +412,13 @@ print("Finished.")\r\n`;
407412 Uri . joinPath ( this . _extensionUri , "web" , "raspberrypi-nav-header-dark.svg" )
408413 ) ;
409414
410- // TODO: maybe use python extension api
411- // TODO: check python version, workaround, ownly allow python3 commands on unix
415+ // TODO: add support for onDidChangeActiveEnvironment and filter envs that don't directly point
416+ // to an executable
417+ const environments = this . _pythonExtensionApi ?. environments ;
418+ const knownEnvironments = environments ?. known ;
419+ const activeEnv = environments ?. getActiveEnvironmentPath ( ) ;
420+
421+ // TODO: check python version, workaround, only allow python3 commands on unix
412422 const isPythonSystemAvailable =
413423 ( await which ( "python3" , { nothrow : true } ) ) !== null ||
414424 ( await which ( "python" , { nothrow : true } ) ) !== null ;
@@ -484,29 +494,54 @@ print("Finished.")\r\n`;
484494 </div>
485495
486496 <div class="ms-6">
487- ${
488- process . platform === "darwin" || process . platform === "win32"
489- ? `
490- <div class="col-span-2">
491- <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Python Version:</label>
492-
493- ${
494- isPythonSystemAvailable
495- ? `<div class="flex items-center mb-2" >
496- <input type="radio" id="python-radio-system-version" name="python-version-radio" value="1" class="mr-1 text-blue-500">
497- <label for="python-radio-system-version" class="text-gray-900 dark:text-white">Use system version</label>
498- </div>`
499- : ""
500- }
501-
502- <div class="flex items-center mb-2">
503- <input type="radio" id="python-radio-path-executable" name="python-version-radio" value="2" class="mr-1 text-blue-500">
504- <label for="python-radio-path-executable" class="text-gray-900 dark:text-white">Path to executable:</label>
505- <input type="file" id="python-path-executable" multiple="false" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 ms-2">
506- </div>
497+ <div class="col-span-2">
498+ <label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Python Version:</label>
499+
500+ ${
501+ knownEnvironments && knownEnvironments . length > 0
502+ ? `
503+ <div class="flex items-center mb-2">
504+ <input type="radio" id="python-radio-known" name="python-version-radio" value="0" class="mr-1 text-blue-500">
505+ <label for="python-radio-known" class="text-gray-900 dark:text-white">From Python extension</label>
506+ <!-- show a select dropdown with python environments -->
507+ <select id="sel-pyenv-known" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
508+ ${ knownEnvironments
509+ . map (
510+ env =>
511+ `<option value="${ env . path } " ${
512+ ( activeEnv ?. id ?? "" ) === env . id
513+ ? "selected"
514+ : ""
515+ } >${ env . path } </option>`
516+ )
517+ . join ( "" ) }
518+ </select>
519+ </div>
520+ `
521+ : ""
522+ }
523+
524+ ${
525+ process . platform === "darwin" ||
526+ process . platform === "win32"
527+ ? `
528+ ${
529+ isPythonSystemAvailable
530+ ? `<div class="flex items-center mb-2" >
531+ <input type="radio" id="python-radio-system-version" name="python-version-radio" value="1" class="mr-1 text-blue-500">
532+ <label for="python-radio-system-version" class="text-gray-900 dark:text-white">Use system version</label>
507533 </div>`
508- : ""
509- }
534+ : ""
535+ }
536+
537+ <div class="flex items-center mb-2">
538+ <input type="radio" id="python-radio-path-executable" name="python-version-radio" value="2" class="mr-1 text-blue-500">
539+ <label for="python-radio-path-executable" class="text-gray-900 dark:text-white">Path to executable:</label>
540+ <input type="file" id="python-path-executable" multiple="false" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 ms-2">
541+ </div>`
542+ : ""
543+ }
544+ </div>
510545 </div>
511546
512547 <div class="mt-6 mb-4 col-span-2">
0 commit comments