1+ <# !
2+ . SYNOPSIS
3+ Activates a virtual environment for a CI machine. Any further usages of "python" will utilize this virtual environment.
4+
5+ . DESCRIPTION
6+ When activating a virtual environment, only a few things are actually functionally changed on the machine.
7+
8+ # 1. PATH = path to the bin directory of the virtual env. "Scripts" on windows machines
9+ # 2. VIRTUAL_ENV = path to root of the virtual env
10+ # 3. VIRTUAL_ENV_PROMPT = the prompt that is displayed next to the CLI cursor when the virtual env is active
11+ # within a CI machine, we only need the PATH and VIRTUAL_ENV variables to be set.
12+ # 4. (optional and inconsistently) _OLD_VIRTUAL_PATH = the PATH before the virtual env was activated. This is not set in this script.
13+
14+ . PARAMETER VenvName
15+ The name of the virtual environment to activate.
16+
17+ . PARAMETER RepoRoot
18+ The root of the repository.
19+ #>
20+ param (
21+ [Parameter (Mandatory = $true )]
22+ [string ]$VenvName ,
23+ [Parameter (Mandatory = $true )]
24+ [string ]$RepoRoot # mandatory here, but $(Build.SourcesDirectory) will be passed in the template yaml
25+ )
26+
27+ Set-StrictMode - Version 4
28+ $ErrorActionPreference = " Stop"
29+
30+ $venvPath = Join-Path $RepoRoot $VenvName
31+ $venvBinPath = Join-Path $venvPath " bin"
32+ $env: VIRTUAL_ENV = $venvPath
33+
34+ if (-not (Test-Path $venvPath )) {
35+ Write-Error " Virtual environment '$venvPath ' does not exist at $venvPath "
36+ exit 1
37+ }
38+
39+ if ($IsWindows ) {
40+ $venvBinPath = Join-Path $venvPath " Scripts"
41+ $env: PATH = " $venvBinPath ;$ ( $env: PATH ) "
42+ }
43+ else {
44+ $env: PATH = " $venvBinPath `:$ ( $env: PATH ) "
45+ }
46+
47+ Write-Host " Activating virtual environment '$VenvName ' at $venvPath via AzDO to the value '$ ( $env: PATH ) '"
48+ Write-Host " ##vso[task.setvariable variable=VIRTUAL_ENV]$ ( $env: VIRTUAL_ENV ) "
49+ Write-Host " ##vso[task.prependpath]$ ( $env: PATH ) "
0 commit comments