Skip to content

Commit a3cf65c

Browse files
committed
Added new action to install python and install depenencies.
Also set up the repo to use uv.
1 parent f1503d0 commit a3cf65c

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: 'Python setup'
2+
description: 'Configures Python for the current workflow job using UV'
3+
4+
inputs:
5+
dependency-groups:
6+
description: |
7+
'The names of the dependency group configurations to use within pyproject.toml.
8+
Group names are separated by spaces (or use the | syntax in GHA).
9+
Special handling for dependency-group "all" to install all dependencies.'
10+
required: false
11+
repo-root:
12+
description: 'The root directory of the arc repository checkout.'
13+
required: true
14+
default: ${{ github.workspace }}
15+
16+
runs:
17+
using: 'composite'
18+
steps:
19+
- name: Install the latest version of uv
20+
uses: astral-sh/setup-uv@v5
21+
# uv misbehaves in the presence of the python 3.9 pythonarm64 Nuget package.
22+
# This is a workaround to remove it if it exists.
23+
- name: Uninstall pythonarm64 if installed
24+
if: runner.os == 'Windows' && runner.arch == 'ARM64'
25+
shell: pwsh
26+
run: |
27+
if (Get-Package -Name "pythonarm64" -ErrorAction SilentlyContinue) {
28+
Uninstall-Package -Name "pythonarm64"
29+
}
30+
31+
- name: Download python interpreter, install the venv and dependencies
32+
shell: pwsh
33+
working-directory: ${{ inputs.repo-root }}
34+
run: |
35+
Write-Host "::group::Running uv sync"
36+
37+
if (-not "${{ inputs.dependency-groups }}") {
38+
uv sync --no-default-groups
39+
}
40+
elseif ("${{ inputs.dependency-groups }}" -eq "all") {
41+
uv sync --all-groups
42+
}
43+
else {
44+
$groups = "${{ inputs.dependency-groups }}" -split ' '
45+
foreach ($group in $groups) {
46+
if ($group) {
47+
uv sync --no-default-groups --group $group
48+
}
49+
}
50+
}
51+
52+
Write-Host "::endgroup::"
53+
54+
- name: Activate venv (posix)
55+
if: runner.os != 'Windows'
56+
shell: bash
57+
working-directory: ${{ inputs.repo-root }}
58+
run: |
59+
# Activate the virtual environment
60+
source .venv/bin/activate
61+
62+
# Make the virtual environment variable persist to other steps
63+
echo "VIRTUAL_ENV=${VIRTUAL_ENV}" >> $GITHUB_ENV
64+
echo "${VIRTUAL_ENV}/bin" >> $GITHUB_PATH
65+
66+
- name: Activate venv (Windows)
67+
if: runner.os == 'Windows'
68+
shell: pwsh
69+
working-directory: ${{ inputs.repo-root }}
70+
run: |
71+
# The python3 exe is not created on windows for some reason so we need to create it
72+
Copy-Item .\.venv\Scripts\python.exe .\.venv\Scripts\python3.exe
73+
74+
# Activate the virtual environment
75+
.\.venv\Scripts\activate
76+
77+
# Make the virtual environment variable persist to other steps
78+
Write-Host "Virtual Env After: $Env:VIRTUAL_ENV"
79+
"VIRTUAL_ENV=$Env:VIRTUAL_ENV" | Out-File -FilePath $Env:GITHUB_ENV -Append
80+
"$Env:VIRTUAL_ENV\Scripts" | Out-File -FilePath $Env:GITHUB_PATH -Append
81+
82+
- name: Set Up UV Environment Options
83+
shell: pwsh
84+
run: |
85+
# UV_NO_SYNC is the equivalent of the --no-sync flag in uv
86+
# It is used to prevent `uv run` from syncing all dependencies
87+
"UV_NO_SYNC=1" | Out-File -FilePath $env:GITHUB_ENV -Append
88+
89+
- name: Check python versions
90+
shell: pwsh
91+
run: |
92+
Write-Host "python -- version: $(python --version) -- location: $(Get-Command python | Select-Object -ExpandProperty Source)"
93+
Write-Host "python3 -- version: $(python3 --version) -- location: $(Get-Command python3 | Select-Object -ExpandProperty Source)"
94+
95+
96+

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# If you are making changes in this file you will likely want one of these commands to clear venv and rebuild it
2+
# deactivate; uv cache clean; rm -rf .venv; uv sync; source .venv/bin/activate
3+
# uv cache clean; rm -rf .venv; uv sync; source .venv/bin/activate
4+
5+
[project]
6+
name = "swift-build"
7+
version = "1.0.0"
8+
description = "Python package to support the swift-build repository"
9+
readme = "README.md"
10+
requires-python = ">=3.11,<3.12"
11+
dependencies = []

0 commit comments

Comments
 (0)