Skip to content

Commit 1c45c90

Browse files
prathikrPrathik RaoCopilot
authored
implements python sdk (#533)
mvp --------- Co-authored-by: Prathik Rao <prathikrao@microsoft.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 0d7bab5 commit 1c45c90

40 files changed

Lines changed: 3813 additions & 0 deletions
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build Python SDK
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
required: true
8+
type: string
9+
useWinML:
10+
required: false
11+
type: boolean
12+
default: false
13+
platform:
14+
required: false
15+
type: string
16+
default: 'windows'
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
build:
23+
runs-on: ${{ inputs.platform }}-latest
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
clean: true
30+
31+
- name: Setup Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: '3.12'
35+
36+
# Clone test-data-shared from Azure DevOps (models for integration tests)
37+
- name: Checkout test-data-shared from Azure DevOps
38+
shell: pwsh
39+
working-directory: ${{ github.workspace }}/..
40+
run: |
41+
$pat = "${{ secrets.AZURE_DEVOPS_PAT }}"
42+
$encodedPat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat"))
43+
44+
git config --global http.https://dev.azure.com.extraheader "AUTHORIZATION: Basic $encodedPat"
45+
46+
git lfs install
47+
git clone --depth 1 https://dev.azure.com/microsoft/windows.ai.toolkit/_git/test-data-shared test-data-shared
48+
49+
Write-Host "Clone completed successfully to ${{ github.workspace }}/../test-data-shared"
50+
51+
- name: Checkout specific commit in test-data-shared
52+
shell: pwsh
53+
working-directory: ${{ github.workspace }}/../test-data-shared
54+
run: |
55+
git checkout 231f820fe285145b7ea4a449b112c1228ce66a41
56+
if ($LASTEXITCODE -ne 0) {
57+
Write-Error "Git checkout failed."
58+
exit 1
59+
}
60+
61+
- name: Install build tool
62+
run: |
63+
python -m pip install build
64+
65+
- name: Configure pip for Azure Artifacts
66+
run: |
67+
pip config set global.index-url https://pkgs.dev.azure.com/aiinfra/PublicPackages/_packaging/ORT-Nightly/pypi/simple/
68+
pip config set global.extra-index-url https://pypi.org/simple/
69+
pip config set global.pre true
70+
71+
- name: Set package version
72+
working-directory: sdk/python
73+
run: echo '__version__ = "${{ inputs.version }}"' > src/version.py
74+
75+
- name: Build wheel (Cross-Platform)
76+
if: ${{ inputs.useWinML == false }}
77+
working-directory: sdk/python
78+
run: python -m build --wheel --outdir dist/
79+
80+
- name: Build wheel (WinML)
81+
if: ${{ inputs.useWinML == true }}
82+
working-directory: sdk/python
83+
run: python -m build --wheel -C winml=true --outdir dist/
84+
85+
- name: Install built wheel
86+
working-directory: sdk/python
87+
shell: pwsh
88+
run: |
89+
$wheel = (Get-ChildItem dist/*.whl | Select-Object -First 1).FullName
90+
pip install $wheel
91+
92+
- name: Install test dependencies
93+
run: pip install coverage pytest>=7.0.0 pytest-timeout>=2.1.0
94+
95+
- name: Run tests
96+
working-directory: sdk/python
97+
run: python -m pytest test/ -v
98+
99+
- name: Upload Python packages
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: python-sdk-${{ inputs.platform }}${{ inputs.useWinML == true && '-winml' || '' }}
103+
path: sdk/python/dist/*
104+
105+
- name: Upload flcore logs
106+
uses: actions/upload-artifact@v4
107+
if: always()
108+
with:
109+
name: python-sdk-${{ inputs.platform }}${{ inputs.useWinML == true && '-winml' || '' }}-logs
110+
path: sdk/python/logs/**

.github/workflows/foundry-local-sdk-build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ jobs:
2929
version: '0.9.0.${{ github.run_number }}'
3030
platform: 'windows'
3131
secrets: inherit
32+
build-python-windows:
33+
uses: ./.github/workflows/build-python-steps.yml
34+
with:
35+
version: '0.9.0.${{ github.run_number }}'
36+
platform: 'windows'
37+
secrets: inherit
3238
build-rust-windows:
3339
uses: ./.github/workflows/build-rust-steps.yml
3440
with:
@@ -50,6 +56,13 @@ jobs:
5056
platform: 'windows'
5157
useWinML: true
5258
secrets: inherit
59+
build-python-windows-WinML:
60+
uses: ./.github/workflows/build-python-steps.yml
61+
with:
62+
version: '0.9.0.${{ github.run_number }}'
63+
platform: 'windows'
64+
useWinML: true
65+
secrets: inherit
5366
build-rust-windows-WinML:
5467
uses: ./.github/workflows/build-rust-steps.yml
5568
with:
@@ -70,6 +83,12 @@ jobs:
7083
version: '0.9.0.${{ github.run_number }}'
7184
platform: 'macos'
7285
secrets: inherit
86+
build-python-macos:
87+
uses: ./.github/workflows/build-python-steps.yml
88+
with:
89+
version: '0.9.0.${{ github.run_number }}'
90+
platform: 'macos'
91+
secrets: inherit
7392
build-rust-macos:
7493
uses: ./.github/workflows/build-rust-steps.yml
7594
with:

sdk/python/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Native binaries downloaded from NuGet (per-platform)
2+
packages/
3+
4+
# Build / egg info
5+
*.egg-info/
6+
dist/
7+
build/
8+
*.whl
9+
*.tar.gz
10+
__pycache__/
11+
12+
# Logs
13+
logs/
14+
15+
# IDE
16+
.vscode/
17+
.idea/
18+
19+
# pytest
20+
.pytest_cache/

sdk/python/LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)