import * as semver from 'semver' ; import { IActionContext } from 'vscode-azureextensionui' ; import { ext } from '../../../extensionVariables' ; import { getLocalFuncCoreToolsVersion } from '../../../funcCoreTools/getLocalFuncCoreToolsVersion' ; import { FuncVersion , getMajorVersion } from '../../../FuncVersion' ; import { localize } from "../../../localize" ; import { cpUtils } from "../../../utils/cpUtils" ; export async function getPythonVersion ( pyAlias ) { const result = await cpUtils . tryExecuteCommand ( undefined , undefined , `${ pyAlias } --version` ) ; if ( result . code !== 0 ) { throw new Error ( localize ( 'failValidate' , 'Failed to validate version: {0}' , result . cmdOutputIncludingStderr ) ) ; } const matches = result . cmdOutputIncludingStderr . match ( /^Python (\S*)/i ) ; if ( matches === null || ! matches [ 1 ] ) { throw new Error ( localize ( 'failedParse' , 'Failed to parse version: {0}' , result . cmdOutputIncludingStderr ) ) ; } else { return matches [ 1 ] ; } } export async function getSupportedPythonVersions ( context , funcVersionFromSetting ) { const localVersionTask = getLocalFuncCoreToolsVersion ( context , undefined ) ; const result = [ ] ; const versionInfo = [ [ '2.0.0' , '3.6' ] , [ '2.7.1846' , '3.7' ] , [ '3.0.2245' , '3.8' ] , [ '3.0.3216' , '3.9' ] ] ; for ( const [ minFuncVersion , pyVersion ] of versionInfo ) { function showVersionWarning ( currentVersion ) { ext . outputChannel . appendLine ( localize ( 'outOfDateWarning' , 'WARNING: Python version {0}+ is not supported with version "{1}" of the func CLI. Update to at least "{2}" for support.' , pyVersion , currentVersion , minFuncVersion ) ) ; } try { if ( semver . satisfies ( minFuncVersion , getMajorVersion ( funcVersionFromSetting ) ) ) { const currentVersion = await localVersionTask ; if ( currentVersion && semver . lt ( currentVersion , minFuncVersion ) ) { showVersionWarning ( currentVersion ) ; return result ; } } else if ( semver . gtr ( minFuncVersion , getMajorVersion ( funcVersionFromSetting ) ) ) { showVersionWarning ( funcVersionFromSetting ) ; return result ; } } catch { } result . push ( pyVersion ) ; } return result ; } export function isSupportedPythonVersion ( supportedVersions , version ) { try { return ! ! supportedVersions . some ( v => semver . satisfies ( version , v ) ) ; } catch { return false ; } }