Skip to content

Conglomerated changes to optimize venv usage in pipeline #42486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
14 changes: 13 additions & 1 deletion eng/pipelines/templates/jobs/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ jobs:
os: linux

steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(PythonVersion)'
condition: succeededOrFailed()
inputs:
versionSpec: '$(PythonVersion)'

- template: /eng/pipelines/templates/steps/use-venv.yml

- template: /eng/common/pipelines/templates/steps/check-spelling.yml
parameters:
ContinueOnError: false
Expand Down Expand Up @@ -275,6 +283,7 @@ jobs:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.12'
- template: /eng/pipelines/templates/steps/use-venv.yml
- template: /eng/common/pipelines/templates/steps/save-package-properties.yml
parameters:
ServiceDirectory: ${{parameters.ServiceDirectory}}
Expand Down Expand Up @@ -310,8 +319,11 @@ jobs:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.12'
- template: /eng/pipelines/templates/steps/use-venv.yml
- pwsh: |
python -m pip install "./tools/azure-sdk-tools[build]"
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$(PIP_EXE) install "./tools/azure-sdk-tools[build]"
displayName: 'Prep Environment'
- task: PythonScript@0
displayName: 'Ensure service coverage'
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ steps:
Condition: succeededOrFailed()

- script: |
python -m pip install "./tools/azure-sdk-tools[build]" -q -I
$(PIP_EXE) install "./tools/azure-sdk-tools[build]"
sdk_find_invalid_versions --always-succeed --service=${{parameters.ServiceDirectory}}
displayName: Find Invalid Versions
condition: succeededOrFailed()
Expand Down
8 changes: 1 addition & 7 deletions eng/pipelines/templates/steps/analyze_dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ parameters:
ScanPath: ''

steps:
- task: UsePythonVersion@0
Copy link
Member Author

@scbedd scbedd Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This moved to the caller in jobs/ci.yml, it is not removed.

displayName: 'Use Python $(PythonVersion)'
condition: succeededOrFailed()
inputs:
versionSpec: '$(PythonVersion)'

- pwsh: |
python -m pip install -r eng/ci_tools.txt
$(PIP_EXE) install -r eng/ci_tools.txt
displayName: 'Install Python Tools'
condition: succeededOrFailed()

Expand Down
7 changes: 4 additions & 3 deletions eng/pipelines/templates/steps/build-extended-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ steps:
inputs:
versionSpec: '3.13'

- template: /eng/pipelines/templates/steps/use-venv.yml

- pwsh: |
if ("${{ parameters.ServiceDirectory }}" -ne "auto")
{
Expand All @@ -53,10 +55,9 @@ steps:
displayName: 'Tag scheduled builds'
condition: and(eq(variables['Build.SourceBranchName'], variables['DefaultBranch']), eq(variables['Build.Reason'],'Schedule'))

- template: /eng/pipelines/templates/steps/use-venv.yml

- script: |
python -m pip install -r eng/ci_tools.txt
which python
$(PIP_EXE) install -r eng/ci_tools.txt
displayName: 'Prep Environment'

- template: set-dev-build.yml
Expand Down
21 changes: 9 additions & 12 deletions eng/pipelines/templates/steps/build-package-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ steps:
inputs:
versionSpec: $(PythonVersion)

- template: /eng/pipelines/templates/steps/use-venv.yml

- template: /eng/common/pipelines/templates/steps/set-test-pipeline-version.yml@self
parameters:
PackageName: "azure-template"
Expand Down Expand Up @@ -85,21 +87,17 @@ steps:
parameters:
PackagePropertiesFolder: $(Build.ArtifactStagingDirectory)/PackageInfo

- template: /eng/pipelines/templates/steps/use-venv.yml
parameters:
VirtualEnvironmentName: "venv"
Activate: false
Condition: and(succeeded(), or(eq(variables['ENABLE_EXTENSION_BUILD'], 'true'), eq('${{ parameters.ArtifactSuffix }}', 'linux')))

- pwsh: |
$(VENV_ACTIVATION_SCRIPT)
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
which python
python -m pip install --force -r eng/ci_tools.txt
$(PIP_EXE) install -r eng/ci_tools.txt

if ($env:AGENT_OS -eq "Linux") {
Write-Host "Installing release reqs"
python -m pip install -r eng/release_requirements.txt
$(PIP_EXE) install -r eng/release_requirements.txt
}
python -m pip freeze --all
$(PIP_EXE) freeze
displayName: 'Prep Environment'
condition: and(succeeded(), or(eq(variables['ENABLE_EXTENSION_BUILD'], 'true'), eq('${{ parameters.ArtifactSuffix }}', 'linux')))

Expand All @@ -111,7 +109,6 @@ steps:
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))

- pwsh: |
$(VENV_ACTIVATION_SCRIPT)
which python
sdk_build -d "$(Build.ArtifactStagingDirectory)" "$(TargetingString)" --inactive
displayName: 'Generate Packages'
Expand All @@ -121,7 +118,7 @@ steps:
CIBW_BUILD_VERBOSITY: 3

- pwsh: |
$(VENV_ACTIVATION_SCRIPT)
which python
twine check $(Build.ArtifactStagingDirectory)/**/*.whl
twine check $(Build.ArtifactStagingDirectory)/**/*.tar.gz
displayName: 'Verify Readme'
Expand Down
38 changes: 3 additions & 35 deletions eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,15 @@ steps:
versionSpec: '${{ parameters.PythonVersion }}'

- template: /eng/pipelines/templates/steps/use-venv.yml
parameters:
Activate: false

- template: set-dev-build.yml

- pwsh: |
if ($IsWindows) {
. $(VENV_LOCATION)/Scripts/Activate.ps1
}
else {
. $(VENV_LOCATION)/bin/activate.ps1
}
Write-Host (Get-Command python).Source
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
python -m pip install --force -r eng/ci_tools.txt
python -m pip freeze --all
Write-Host (Get-Command python).Source
$(PIP_EXE) install -r eng/ci_tools.txt
$(PIP_EXE) freeze
displayName: 'Prep Environment'

- template: /eng/common/testproxy/test-proxy-tool.yml
Expand Down Expand Up @@ -75,12 +67,6 @@ steps:
$env:AZURESUBSCRIPTION_CLIENT_ID = $account.Id;
$env:AZURESUBSCRIPTION_TENANT_ID = $account.Tenants;

if ($IsWindows) {
. $(VENV_LOCATION)/Scripts/Activate.ps1
}
else {
. $(VENV_LOCATION)/bin/activate.ps1
}
Write-Host (Get-Command python).Source

if ($env:TESTMARKARGUMENT) {
Expand All @@ -104,12 +90,6 @@ steps:

- ${{ else }}:
- pwsh: |
if ($IsWindows) {
. $(VENV_LOCATION)/Scripts/Activate.ps1
}
else {
. $(VENV_LOCATION)/bin/activate.ps1
}
Write-Host (Get-Command python).Source

if ($env:TESTMARKARGUMENT) {
Expand Down Expand Up @@ -145,12 +125,6 @@ steps:
- ${{ parameters.AfterTestSteps }}

- pwsh: |
if ($IsWindows) {
. $(VENV_LOCATION)/Scripts/Activate.ps1
}
else {
. $(VENV_LOCATION)/bin/activate.ps1
}
Write-Host (Get-Command python).Source

python scripts/devops_tasks/create_coverage.py
Expand All @@ -176,12 +150,6 @@ steps:
$env:AZURESUBSCRIPTION_CLIENT_ID = $account.Id;
$env:AZURESUBSCRIPTION_TENANT_ID = $account.Tenants;

if ($IsWindows) {
. $(VENV_LOCATION)/Scripts/Activate.ps1
}
else {
. $(VENV_LOCATION)/bin/activate.ps1
}
Write-Host (Get-Command python).Source

python scripts/devops_tasks/dispatch_tox.py "$(TargetingString)" `
Expand Down
26 changes: 26 additions & 0 deletions eng/pipelines/templates/steps/install-uv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

steps:
- task: Bash@3
displayName: 'Install uv (Linux/macOS)'
inputs:
targetType: inline
script: |
curl -LsSf https://astral.sh/uv/install.sh | sh
condition: or(eq(variables['Agent.OS'], 'Linux'), eq(variables['Agent.OS'], 'Darwin'))

- task: Bash@3
inputs:
targetType: inline
script: |
echo "##vso[task.prependpath]$HOME/.local/bin"
displayName: 'Prepend path for MacOS'
condition: eq(variables['Agent.OS'], 'Darwin')

- task: PowerShell@2
displayName: 'Install uv (Windows)'
inputs:
targetType: inline
script: |
iex (irm https://astral.sh/uv/install.ps1)
Write-Host "##vso[task.prependpath]$env:USERPROFILE\.local\bin"
condition: eq(variables['Agent.OS'], 'Windows_NT')
10 changes: 3 additions & 7 deletions eng/pipelines/templates/steps/release-candidate-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ steps:
versionSpec: $(PythonVersion)

- template: /eng/pipelines/templates/steps/use-venv.yml
parameters:
Activate: false

- pwsh: |
$(VENV_ACTIVATION_SCRIPT)
Write-Host (Get-Command python).Source
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
python -m pip install -r $(Build.SourcesDirectory)/eng/ci_tools.txt
python -m pip freeze --all
Write-Host (Get-Command python).Source
$(PIP_EXE) install -r $(Build.SourcesDirectory)/eng/ci_tools.txt
$(PIP_EXE) freeze
displayName: 'Install Dependencies'

- template: /eng/common/testproxy/test-proxy-tool.yml
parameters:
runProxy: false

- pwsh: |
$(VENV_ACTIVATION_SCRIPT)
python ./scripts/devops_tasks/dispatch_tox.py "$(TargetedPackages)" --junitxml="junit/test_results.xml" --toxenv="whl" --filter-type="Build"
displayName: 'Setup - Run Filtered Tests For Python $(PythonVersion)'
env:
Expand Down
10 changes: 8 additions & 2 deletions eng/pipelines/templates/steps/run_apistub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ steps:
versionSpec: '3.10'
condition: and(succeededOrFailed(), ne(variables['Skip.ApiStubGen'],'true'))

- script: |
python -m pip install -r eng/ci_tools.txt
- template: /eng/pipelines/templates/steps/use-venv.yml
parameters:
VirtualEnvironmentName: "venv-api-stub"

- pwsh: |
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$(PIP_EXE) install -r eng/ci_tools.txt
displayName: 'Prep Environment'
condition: and(succeededOrFailed(), ne(variables['Skip.ApiStubGen'],'true'))

Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/templates/steps/seed-virtualenv-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:

steps:
- pwsh: |
python -m pip install virtualenv
$(PIP_EXE) install virtualenv
displayName: Ensure virtualenv installed

- pwsh: |
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/templates/steps/set-dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ steps:
- template: /eng/common/pipelines/templates/steps/daily-dev-build-variable.yml

- pwsh: |
python -m pip install "tools/azure-sdk-tools[build]"
$(PIP_EXE) install "tools/azure-sdk-tools[build]"
sdk_set_dev_version "*" --build-id="$(Build.BuildNumber)"
displayName: "Update package versions for dev build"
condition: and(succeededOrFailed(), eq(variables['SetDevVersion'],'true'), ${{ parameters.Condition }})
21 changes: 20 additions & 1 deletion eng/pipelines/templates/steps/use-venv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,27 @@ parameters:
- name: Condition
type: string
default: succeeded()
- name: UseUv
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't currently set UseUv. So we can change this to default to false at any time and use bog-standard pip if we need to.

type: boolean
default: true

steps:
- ${{ if eq(parameters.UseUv, true) }}:
- template: install-uv.yml

- pwsh: |
if (Get-Command uv -ErrorAction SilentlyContinue) {
Write-Host "##vso[task.setvariable variable=PIP_EXE]uv pip"
} else {
Write-Error "Expected 'uv' command to be available, but it was not. Exiting with error."
exit 1
}
displayName: Setting PIP_EXE to 'uv pip'
- ${{ else }}:
- pwsh: |
Write-Host "##vso[task.setvariable variable=PIP_EXE]python -m pip"
displayName: Setting PIP_EXE to 'python -m pip'

- pwsh: |
$(Build.SourcesDirectory)/eng/scripts/create-venv.ps1 `
-VenvName "${{ parameters.VirtualEnvironmentName }}" `
Expand All @@ -23,4 +42,4 @@ steps:
-VenvName "${{ parameters.VirtualEnvironmentName }}" `
-RepoRoot "$(Build.SourcesDirectory)"
displayName: Use ${{ parameters.VirtualEnvironmentName }} Virtual Environment
condition: ${{ parameters.Condition }}
condition: ${{ parameters.Condition }}
20 changes: 17 additions & 3 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,18 @@ function Get-AllPackageInfoFromRepo ($serviceDirectory)
$allPkgPropLines = $null
try
{
Push-Location $RepoRoot
$null = python -m pip install "./tools/azure-sdk-tools[build]" -q -I
# Use ‘uv pip install’ if uv is on PATH, otherwise fall back to python -m pip
if (Get-Command uv -ErrorAction SilentlyContinue) {
Write-Host "Using uv pip install"
$null = uv pip install "./tools/azure-sdk-tools[build]"
$freezeOutput = uv pip freeze
Write-Host "Pip freeze output: $freezeOutput"
} else {
Write-Host "Using python -m pip install"
$null = python -m pip install "./tools/azure-sdk-tools[build]" -q -I
}

Write-Host "Running get_package_properties.py to retrieve package properties"
$allPkgPropLines = python (Join-path eng scripts get_package_properties.py) -s $searchPath
}
catch
Expand Down Expand Up @@ -412,7 +422,11 @@ function SetPackageVersion ($PackageName, $Version, $ServiceDirectory, $ReleaseD
{
$ReleaseDate = Get-Date -Format "yyyy-MM-dd"
}
python -m pip install "$RepoRoot/tools/azure-sdk-tools[build]" -q -I
if (Get-Command uv -ErrorAction SilentlyContinue) {
uv pip install "$RepoRoot/tools/azure-sdk-tools[build]"
} else {
python -m pip install "$RepoRoot/tools/azure-sdk-tools[build]" -q -I
}
sdk_set_version --package-name $PackageName --new-version $Version `
--service $ServiceDirectory --release-date $ReleaseDate --replace-latest-entry-title $ReplaceLatestEntryTitle
}
Expand Down
Loading
Loading