File: create-venv.ps1

package info (click to toggle)
python-azure 20251014%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 766,472 kB
  • sloc: python: 6,314,744; ansic: 804; javascript: 287; makefile: 198; sh: 198; xml: 109
file content (43 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<#!
.SYNOPSIS
Creates a virtual environment for a CI machine.

.DESCRIPTION
If the virtual environment directory already exists, it will skip the creation. The location of the virtual environment will be stored in a variable
named <VenvName>_LOCATION. The location will be RepoRoot + VenvName.

.PARAMETER VenvName
The name of the virtual environment which will be created.

.PARAMETER RepoRoot
The root of the repository.
#>
param(
    [Parameter(Mandatory = $true)]
    [string] $VenvName,
    # The root of the repository should be $(Build.SourcesDirectory) passed in from template
    [Parameter(Mandatory = $true)]
    [string] $RepoRoot
)

$venvPath = Join-Path $RepoRoot $VenvName

if (!(Test-Path $venvPath)) {
    $invokingPython = (Get-Command "python").Source

    if (Get-Command uv -ErrorAction SilentlyContinue) {
        Write-Host "Creating virtual environment '$VenvName' using uv."
        uv venv $venvPath  --verbose
    }
    else {
        Write-Host "Creating virtual environment '$VenvName' using virtualenv and python located at '$invokingPython'."
        python -m pip install virtualenv==20.25.1
        python -m virtualenv "$venvPath"
    }
    $pythonVersion = python --version
    Write-Host "Virtual environment '$VenvName' created at directory path '$venvPath' utilizing python version $pythonVersion."
    Write-Host "##vso[task.setvariable variable=$($VenvName)_LOCATION]$venvPath"
}
else {
    Write-Host "Virtual environment '$VenvName' already exists. Skipping creation."
}