import { AzureWizardPromptStep , IAzureQuickPickItem , IWizardOptions } from "vscode-azureextensionui" ; import { localize } from "../../../localize" ; import { getGlobalSetting } from "../../../vsCodeConfig/settings" ; import { EnterPythonAliasStep } from "./EnterPythonAliasStep" ; import { IPythonVenvWizardContext } from "./IPythonVenvWizardContext" ; import { getPythonVersion , getSupportedPythonVersions , isSupportedPythonVersion } from './pythonVersion' ; export class PythonAliasListStep extends AzureWizardPromptStep < IPythonVenvWizardContext > { public hideStepCount : boolean = true ; public async prompt ( context ) { const placeHolder = localize ( 'selectAlias' , 'Select a Python interpreter to create a virtual environment' ) ; const result = ( await context . ui . showQuickPick ( getPicks ( context ) , { placeHolder } ) ) . data ; if ( typeof result === 'string' ) { context . pythonAlias = result ; context . telemetry . properties . pythonAliasBehavior = 'selectAlias' ; } else { context . manuallyEnterAlias = result ; context . telemetry . properties . pythonAliasBehavior = result ? 'enterAlias' : 'skipVenv' ; } } public shouldPrompt ( context ) { return ! context . useExistingVenv && ! context . pythonAlias ; } public async getSubWizard ( context ) { if ( context . manuallyEnterAlias ) { return { promptSteps : [ new EnterPythonAliasStep ( ) ] } ; } else { return undefined ; } } } async function getPicks ( context ) { const supportedVersions = await getSupportedPythonVersions ( context , context . version ) ; const aliasesToTry = [ 'python' , 'python3' , 'py' ] ; for ( const version of supportedVersions ) { aliasesToTry . push ( `python${ version }` , `py -${ version }` ) ; } const globalPythonPathSetting = getGlobalSetting ( 'pythonPath' , 'python' ) ; if ( globalPythonPathSetting ) { aliasesToTry . unshift ( globalPythonPathSetting ) ; } const picks = [ ] ; const versions = [ ] ; for ( const alias of aliasesToTry ) { let version ; try { version = await getPythonVersion ( alias ) ; } catch { continue ; } if ( isSupportedPythonVersion ( supportedVersions , version ) && ! versions . some ( v => v === version ) ) { picks . push ( { label : alias , description : version , data : alias } ) ; versions . push ( version ) ; } } context . telemetry . properties . detectedPythonVersions = versions . join ( ',' ) ; picks . push ( { label : localize ( 'enterAlias' , '$(keyboard) Manually enter Python interpreter or full path' ) , data : true } ) ; if ( ! context . suppressSkipVenv ) { picks . push ( { label : localize ( 'skipVenv' , '$(circle-slash) Skip virtual environment' ) , data : false , suppressPersistence : true } ) ; } return picks ; }