import { AzureWizardPromptStep , parseError } from "vscode-azureextensionui" ; import { localize } from "../../../localize" ; import { IPythonVenvWizardContext } from "./IPythonVenvWizardContext" ; import { getPythonVersion , getSupportedPythonVersions , isSupportedPythonVersion } from './pythonVersion' ; export class EnterPythonAliasStep extends AzureWizardPromptStep < IPythonVenvWizardContext > { public hideStepCount : boolean = true ; public async prompt ( context ) { const prompt = localize ( 'pyAliasPlaceholder' , 'Enter the Python interpreter or full path' ) ; const supportedVersions = await getSupportedPythonVersions ( context , context . version ) ; context . pythonAlias = await context . ui . showInputBox ( { prompt , validateInput : async ( value ) : Promise < string | undefined > => await validatePythonAlias ( supportedVersions , value ) } ) ; } public shouldPrompt ( context ) { return ! ! context . manuallyEnterAlias && ! context . useExistingVenv && ! context . pythonAlias ; } } async function validatePythonAlias ( supportedVersions , pyAlias ) { let pyVersion ; try { pyVersion = await getPythonVersion ( pyAlias ) ; } catch ( error ) { return parseError ( error ) . message ; } if ( isSupportedPythonVersion ( supportedVersions , pyVersion ) ) { return undefined ; } else { const supportedVersionsString = supportedVersions . map ( v => `"${ v }.x"` ) . join ( ', ' ) ; return localize ( 'notMatchingVersion' , 'Python version "{0}" does not match supported versions: {1}' , pyVersion , supportedVersionsString ) ; } }