import * as fse from 'fs-extra' ; import * as path from 'path' ; import { Progress } from 'vscode' ; import { AzureWizardExecuteStep } from 'vscode-azureextensionui' ; import { requirementsFileName } from '../../../constants' ; import { ext } from '../../../extensionVariables' ; import { localize } from "../../../localize" ; import { cpUtils } from "../../../utils/cpUtils" ; import { nonNullProp } from '../../../utils/nonNull' ; import { venvUtils } from '../../../utils/venvUtils' ; import { IPythonVenvWizardContext } from './IPythonVenvWizardContext' ; import { getPythonVersion } from './pythonVersion' ; export class PythonVenvCreateStep extends AzureWizardExecuteStep < IPythonVenvWizardContext > { public priority : number = 12 ; public async execute ( context , progress ) { progress . report ( { message : localize ( 'creatingVenv' , 'Creating virtual environment...' ) } ) ; const pythonAlias = nonNullProp ( context , 'pythonAlias' ) ; if ( ! context . venvName ) { context . venvName = '.venv' ; } void getPythonVersion ( pythonAlias ) . then ( value => context . telemetry . properties . pythonVersion = value ) ; await cpUtils . executeCommand ( ext . outputChannel , context . projectPath , pythonAlias , '-m' , 'venv' , context . venvName ) ; const requirementsPath = path . join ( context . projectPath , requirementsFileName ) ; if ( await fse . pathExists ( requirementsPath ) ) { try { await venvUtils . runCommandInVenv ( `pip install -r ${ requirementsFileName }` , context . venvName , context . projectPath ) ; } catch { ext . outputChannel . appendLog ( localize ( 'pipInstallFailure' , 'WARNING: Failed to install packages in your virtual environment. Run "pip install" manually instead.' ) ) ; } } } public shouldExecute ( context ) { return ! context . useExistingVenv && ! ! context . pythonAlias ; } }