-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathbuild-python-steps.yml
More file actions
156 lines (142 loc) · 5.67 KB
/
build-python-steps.yml
File metadata and controls
156 lines (142 loc) · 5.67 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Steps to build and pack the Python SDK wheel.
# When test-data-shared is checked out alongside self, ADO places repos under
# $(Build.SourcesDirectory)/<repo-name>. The self repo is 'Foundry-Local'.
parameters:
- name: version
type: string
- name: isRelease
type: boolean
default: false
- name: isWinML
type: boolean
default: false
- name: flcWheelsDir
type: string
displayName: 'Path to directory containing the FLC wheels (for overriding foundry-local-core)'
- name: outputDir
type: string
default: '$(Build.ArtifactStagingDirectory)/python-sdk'
displayName: 'Path to directory for the built wheel'
- name: prereleaseId
type: string
default: ''
steps:
# Set paths for multi-repo checkout
- task: PowerShell@2
displayName: 'Set source paths'
inputs:
targetType: inline
script: |
$repoRoot = "$(Build.SourcesDirectory)/Foundry-Local"
$testDataDir = "$(Build.SourcesDirectory)/test-data-shared"
Write-Host "##vso[task.setvariable variable=repoRoot]$repoRoot"
Write-Host "##vso[task.setvariable variable=testDataDir]$testDataDir"
- task: UsePythonVersion@0
displayName: 'Use Python 3.12'
inputs:
versionSpec: '3.12'
# List downloaded FLC wheels for debugging
- task: PowerShell@2
displayName: 'List downloaded FLC wheels'
condition: and(succeeded(), ne('${{ parameters.flcWheelsDir }}', ''))
inputs:
targetType: inline
script: |
Write-Host "Contents of ${{ parameters.flcWheelsDir }}:"
Get-ChildItem "${{ parameters.flcWheelsDir }}" -Recurse | ForEach-Object { Write-Host $_.FullName }
# Compute package version
- task: PowerShell@2
displayName: 'Set package version'
inputs:
targetType: inline
script: |
$v = "${{ parameters.version }}"
$preId = "${{ parameters.prereleaseId }}"
if ($preId -ne '' -and $preId -ne 'none') {
$v = "$v-$preId"
} elseif ("${{ parameters.isRelease }}" -ne "True") {
$ts = Get-Date -Format "yyyyMMddHHmm"
$v = "$v-dev.$ts"
}
Write-Host "##vso[task.setvariable variable=packageVersion]$v"
Write-Host "Package version: $v"
# Configure pip to use ORT-Nightly feed (plus PyPI as fallback)
- task: PowerShell@2
displayName: 'Configure pip for Azure Artifacts'
inputs:
targetType: inline
script: |
pip config set global.index-url https://pkgs.dev.azure.com/aiinfra/PublicPackages/_packaging/ORT-Nightly/pypi/simple/
pip config set global.extra-index-url https://pypi.org/simple/
pip config set global.pre true
# Install the build tool
- script: python -m pip install build
displayName: 'Install build tool'
# Write version file
- task: PowerShell@2
displayName: 'Set SDK version'
inputs:
targetType: inline
script: |
Set-Content -Path "$(repoRoot)/sdk/python/src/version.py" -Value '__version__ = "$(packageVersion)"'
# Install the FLC wheels from the pipeline if provided, so the build
# backend picks up the freshly-built foundry-local-core instead of
# pulling a stale one from the feed.
- task: PowerShell@2
displayName: 'Pre-install pipeline-built FLC wheel'
condition: and(succeeded(), ne('${{ parameters.flcWheelsDir }}', ''))
inputs:
targetType: inline
script: |
# Determine platform wheel tag for the current machine
$arch = if ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'Arm64') { 'arm64' } else { 'amd64' }
if ($IsLinux) { $platTag = "manylinux*x86_64" }
elseif ($IsMacOS) { $platTag = "macosx*$arch" }
else { $platTag = "win_$arch" }
$filter = if ("${{ parameters.isWinML }}" -eq "True") { "foundry_local_core_winml*$platTag.whl" } else { "foundry_local_core-*$platTag.whl" }
$wheel = Get-ChildItem "${{ parameters.flcWheelsDir }}" -Recurse -Filter $filter | Select-Object -First 1
if ($wheel) {
Write-Host "Installing pipeline-built FLC wheel: $($wheel.FullName)"
pip install $($wheel.FullName)
} else {
Write-Warning "No FLC wheel found matching $filter in ${{ parameters.flcWheelsDir }}"
}
- ${{ if eq(parameters.isWinML, true) }}:
- script: pip install onnxruntime-core==1.23.2.3 onnxruntime-genai-core==0.12.1
displayName: 'Install ORT native packages (WinML)'
- ${{ else }}:
- script: pip install onnxruntime-core==1.24.3 onnxruntime-genai-core==0.12.1
displayName: 'Install ORT native packages'
- script: pip install "pydantic>=2.0.0" "requests>=2.32.4" "openai>=2.24.0"
displayName: 'Install pure python dependencies'
# Build wheel — standard or WinML variant
# The wheel retains all dependencies in its metadata so end users get
# native packages installed automatically. CI uses --no-deps to avoid
# re-downloading packages that were pre-installed from pipeline builds.
- ${{ if eq(parameters.isWinML, true) }}:
- script: python -m build --wheel -C winml=true --outdir dist/
displayName: 'Build wheel (WinML)'
workingDirectory: $(repoRoot)/sdk/python
- ${{ else }}:
- script: python -m build --wheel --outdir dist/
displayName: 'Build wheel'
workingDirectory: $(repoRoot)/sdk/python
# Install the built wheel
- task: PowerShell@2
displayName: 'Install built wheel'
inputs:
targetType: inline
script: |
$wheel = (Get-ChildItem "$(repoRoot)/sdk/python/dist/*.whl" | Select-Object -First 1).FullName
pip install --no-deps $wheel
# Stage output
- task: PowerShell@2
displayName: 'Stage wheel artifact'
inputs:
targetType: inline
script: |
$destDir = "${{ parameters.outputDir }}"
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
Copy-Item "$(repoRoot)/sdk/python/dist/*" "$destDir/"
Write-Host "Staged wheels:"
Get-ChildItem $destDir | ForEach-Object { Write-Host " $($_.Name)" }