From 38e608e3532caafc8b194fc714a2b3d453a05215 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy <8000722+mhegazy@users.noreply.github.com> Date: Tue, 27 May 2025 10:41:41 -0700 Subject: [PATCH 1/4] Added new action to install python and install depenencies. Also set up the repo to use uv. --- .github/actions/setup-python/action.yml | 96 +++++++++++++++++++++++++ pyproject.toml | 11 +++ 2 files changed, 107 insertions(+) create mode 100644 .github/actions/setup-python/action.yml create mode 100644 pyproject.toml diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml new file mode 100644 index 000000000..840229e84 --- /dev/null +++ b/.github/actions/setup-python/action.yml @@ -0,0 +1,96 @@ +name: 'Python setup' +description: 'Configures Python for the current workflow job using UV' + +inputs: + dependency-groups: + description: | + 'The names of the dependency group configurations to use within pyproject.toml. + Group names are separated by spaces (or use the | syntax in GHA). + Special handling for dependency-group "all" to install all dependencies.' + required: false + repo-root: + description: 'The root directory of the arc repository checkout.' + required: true + default: ${{ github.workspace }} + +runs: + using: 'composite' + steps: + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v5 + # uv misbehaves in the presence of the python 3.9 pythonarm64 Nuget package. + # This is a workaround to remove it if it exists. + - name: Uninstall pythonarm64 if installed + if: runner.os == 'Windows' && runner.arch == 'ARM64' + shell: pwsh + run: | + if (Get-Package -Name "pythonarm64" -ErrorAction SilentlyContinue) { + Uninstall-Package -Name "pythonarm64" + } + + - name: Download python interpreter, install the venv and dependencies + shell: pwsh + working-directory: ${{ inputs.repo-root }} + run: | + Write-Host "::group::Running uv sync" + + if (-not "${{ inputs.dependency-groups }}") { + uv sync --no-default-groups + } + elseif ("${{ inputs.dependency-groups }}" -eq "all") { + uv sync --all-groups + } + else { + $groups = "${{ inputs.dependency-groups }}" -split ' ' + foreach ($group in $groups) { + if ($group) { + uv sync --no-default-groups --group $group + } + } + } + + Write-Host "::endgroup::" + + - name: Activate venv (posix) + if: runner.os != 'Windows' + shell: bash + working-directory: ${{ inputs.repo-root }} + run: | + # Activate the virtual environment + source .venv/bin/activate + + # Make the virtual environment variable persist to other steps + echo "VIRTUAL_ENV=${VIRTUAL_ENV}" >> $GITHUB_ENV + echo "${VIRTUAL_ENV}/bin" >> $GITHUB_PATH + + - name: Activate venv (Windows) + if: runner.os == 'Windows' + shell: pwsh + working-directory: ${{ inputs.repo-root }} + run: | + # The python3 exe is not created on windows for some reason so we need to create it + Copy-Item .\.venv\Scripts\python.exe .\.venv\Scripts\python3.exe + + # Activate the virtual environment + .\.venv\Scripts\activate + + # Make the virtual environment variable persist to other steps + Write-Host "Virtual Env After: $Env:VIRTUAL_ENV" + "VIRTUAL_ENV=$Env:VIRTUAL_ENV" | Out-File -FilePath $Env:GITHUB_ENV -Append + "$Env:VIRTUAL_ENV\Scripts" | Out-File -FilePath $Env:GITHUB_PATH -Append + + - name: Set Up UV Environment Options + shell: pwsh + run: | + # UV_NO_SYNC is the equivalent of the --no-sync flag in uv + # It is used to prevent `uv run` from syncing all dependencies + "UV_NO_SYNC=1" | Out-File -FilePath $env:GITHUB_ENV -Append + + - name: Check python versions + shell: pwsh + run: | + Write-Host "python -- version: $(python --version) -- location: $(Get-Command python | Select-Object -ExpandProperty Source)" + Write-Host "python3 -- version: $(python3 --version) -- location: $(Get-Command python3 | Select-Object -ExpandProperty Source)" + + + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..6573b2805 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +# If you are making changes in this file you will likely want one of these commands to clear venv and rebuild it +# deactivate; uv cache clean; rm -rf .venv; uv sync; source .venv/bin/activate +# uv cache clean; rm -rf .venv; uv sync; source .venv/bin/activate + +[project] +name = "swift-build" +version = "1.0.0" +description = "Python package to support the swift-build repository" +readme = "README.md" +requires-python = ">=3.11,<3.12" +dependencies = [] From 5777df5dea4909ef98d22efbcad1ca3868867d90 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 27 Jun 2025 10:26:14 -0700 Subject: [PATCH 2/4] Add explicit step to setup python --- .github/actions/setup-python/action.yml | 6 ++++++ .github/workflows/swift-toolchain.yml | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml index 840229e84..065f4670b 100644 --- a/.github/actions/setup-python/action.yml +++ b/.github/actions/setup-python/action.yml @@ -18,6 +18,12 @@ runs: steps: - name: Install the latest version of uv uses: astral-sh/setup-uv@v5 + with: + working-directory: ${{ inputs.repo-root }} + # Explicitly set where the pyproject.toml file is located untill we + # a fix for https://github.com/astral-sh/setup-uv/issues/441 + cache-dependency-glob: ${{ inputs.repo-root }}/**/pyproject.toml + # uv misbehaves in the presence of the python 3.9 pythonarm64 Nuget package. # This is a workaround to remove it if it exists. - name: Uninstall pythonarm64 if installed diff --git a/.github/workflows/swift-toolchain.yml b/.github/workflows/swift-toolchain.yml index c958ad771..2debf3681 100644 --- a/.github/workflows/swift-toolchain.yml +++ b/.github/workflows/swift-toolchain.yml @@ -686,7 +686,10 @@ jobs: ref: ${{ inputs.swift_revision }} path: ${{ github.workspace }}/SourceCache/swift show-progress: false - + - name: Setup python + uses: ./SourceCache/ci-build/.github/actions/setup-python + with: + repo-root: ${{ github.workspace }}/SourceCache/ci-build - name: Configure Tools run: | cmake -B ${{ github.workspace }}/BinaryCache/0 ` @@ -1174,7 +1177,11 @@ jobs: Copy-Item -Path "${{ github.workspace }}/BinaryCache/Library/cmark-gfm-${{ inputs.swift_cmark_version }}/usr/lib/*.dylib" -Destination "${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/${{ inputs.swift_version }}+Asserts/usr/lib/swift/host/compiler" } - - uses: actions/setup-python@v5 + - name: Setup python + uses: ./SourceCache/ci-build/.github/actions/setup-python + with: + repo-root: ${{ github.workspace }}/SourceCache/ci-build + - uses: jannekem/run-python-script-action@v1 with: script: | @@ -1688,6 +1695,11 @@ jobs: ndk-version: ${{ inputs.ANDROID_NDK_VERSION }} local-cache: true + - name: Setup python + uses: ./SourceCache/ci-build/.github/actions/setup-python + with: + repo-root: ${{ github.workspace }}/SourceCache/ci-build + - name: Configure LLVM if: matrix.os != 'Android' || inputs.build_android run: | @@ -2565,7 +2577,11 @@ jobs: run: | cmake --build ${{ github.workspace }}/BinaryCache/libdispatch --target install - - uses: actions/setup-python@v5 + - name: Setup python + uses: ./SourceCache/ci-build/.github/actions/setup-python + with: + repo-root: ${{ github.workspace }}/SourceCache/ci-build + - uses: jannekem/run-python-script-action@v1 if: matrix.os != 'Android' || inputs.build_android with: From a6e85924d81ca1117ec1f081abfed1a9a612085e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 1 Jul 2025 19:14:02 -0700 Subject: [PATCH 3/4] Remove custom action to setup python --- .github/actions/setup-python/action.yml | 102 ------------------------ .github/workflows/swift-toolchain.yml | 24 ++---- pyproject.toml | 11 --- 3 files changed, 6 insertions(+), 131 deletions(-) delete mode 100644 .github/actions/setup-python/action.yml delete mode 100644 pyproject.toml diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml deleted file mode 100644 index 065f4670b..000000000 --- a/.github/actions/setup-python/action.yml +++ /dev/null @@ -1,102 +0,0 @@ -name: 'Python setup' -description: 'Configures Python for the current workflow job using UV' - -inputs: - dependency-groups: - description: | - 'The names of the dependency group configurations to use within pyproject.toml. - Group names are separated by spaces (or use the | syntax in GHA). - Special handling for dependency-group "all" to install all dependencies.' - required: false - repo-root: - description: 'The root directory of the arc repository checkout.' - required: true - default: ${{ github.workspace }} - -runs: - using: 'composite' - steps: - - name: Install the latest version of uv - uses: astral-sh/setup-uv@v5 - with: - working-directory: ${{ inputs.repo-root }} - # Explicitly set where the pyproject.toml file is located untill we - # a fix for https://github.com/astral-sh/setup-uv/issues/441 - cache-dependency-glob: ${{ inputs.repo-root }}/**/pyproject.toml - - # uv misbehaves in the presence of the python 3.9 pythonarm64 Nuget package. - # This is a workaround to remove it if it exists. - - name: Uninstall pythonarm64 if installed - if: runner.os == 'Windows' && runner.arch == 'ARM64' - shell: pwsh - run: | - if (Get-Package -Name "pythonarm64" -ErrorAction SilentlyContinue) { - Uninstall-Package -Name "pythonarm64" - } - - - name: Download python interpreter, install the venv and dependencies - shell: pwsh - working-directory: ${{ inputs.repo-root }} - run: | - Write-Host "::group::Running uv sync" - - if (-not "${{ inputs.dependency-groups }}") { - uv sync --no-default-groups - } - elseif ("${{ inputs.dependency-groups }}" -eq "all") { - uv sync --all-groups - } - else { - $groups = "${{ inputs.dependency-groups }}" -split ' ' - foreach ($group in $groups) { - if ($group) { - uv sync --no-default-groups --group $group - } - } - } - - Write-Host "::endgroup::" - - - name: Activate venv (posix) - if: runner.os != 'Windows' - shell: bash - working-directory: ${{ inputs.repo-root }} - run: | - # Activate the virtual environment - source .venv/bin/activate - - # Make the virtual environment variable persist to other steps - echo "VIRTUAL_ENV=${VIRTUAL_ENV}" >> $GITHUB_ENV - echo "${VIRTUAL_ENV}/bin" >> $GITHUB_PATH - - - name: Activate venv (Windows) - if: runner.os == 'Windows' - shell: pwsh - working-directory: ${{ inputs.repo-root }} - run: | - # The python3 exe is not created on windows for some reason so we need to create it - Copy-Item .\.venv\Scripts\python.exe .\.venv\Scripts\python3.exe - - # Activate the virtual environment - .\.venv\Scripts\activate - - # Make the virtual environment variable persist to other steps - Write-Host "Virtual Env After: $Env:VIRTUAL_ENV" - "VIRTUAL_ENV=$Env:VIRTUAL_ENV" | Out-File -FilePath $Env:GITHUB_ENV -Append - "$Env:VIRTUAL_ENV\Scripts" | Out-File -FilePath $Env:GITHUB_PATH -Append - - - name: Set Up UV Environment Options - shell: pwsh - run: | - # UV_NO_SYNC is the equivalent of the --no-sync flag in uv - # It is used to prevent `uv run` from syncing all dependencies - "UV_NO_SYNC=1" | Out-File -FilePath $env:GITHUB_ENV -Append - - - name: Check python versions - shell: pwsh - run: | - Write-Host "python -- version: $(python --version) -- location: $(Get-Command python | Select-Object -ExpandProperty Source)" - Write-Host "python3 -- version: $(python3 --version) -- location: $(Get-Command python3 | Select-Object -ExpandProperty Source)" - - - diff --git a/.github/workflows/swift-toolchain.yml b/.github/workflows/swift-toolchain.yml index 2debf3681..0c944f77e 100644 --- a/.github/workflows/swift-toolchain.yml +++ b/.github/workflows/swift-toolchain.yml @@ -686,10 +686,9 @@ jobs: ref: ${{ inputs.swift_revision }} path: ${{ github.workspace }}/SourceCache/swift show-progress: false - - name: Setup python - uses: ./SourceCache/ci-build/.github/actions/setup-python - with: - repo-root: ${{ github.workspace }}/SourceCache/ci-build + + - uses: actions/setup-python@v5 + - name: Configure Tools run: | cmake -B ${{ github.workspace }}/BinaryCache/0 ` @@ -1177,11 +1176,7 @@ jobs: Copy-Item -Path "${{ github.workspace }}/BinaryCache/Library/cmark-gfm-${{ inputs.swift_cmark_version }}/usr/lib/*.dylib" -Destination "${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/${{ inputs.swift_version }}+Asserts/usr/lib/swift/host/compiler" } - - name: Setup python - uses: ./SourceCache/ci-build/.github/actions/setup-python - with: - repo-root: ${{ github.workspace }}/SourceCache/ci-build - + - uses: actions/setup-python@v5 - uses: jannekem/run-python-script-action@v1 with: script: | @@ -1695,10 +1690,7 @@ jobs: ndk-version: ${{ inputs.ANDROID_NDK_VERSION }} local-cache: true - - name: Setup python - uses: ./SourceCache/ci-build/.github/actions/setup-python - with: - repo-root: ${{ github.workspace }}/SourceCache/ci-build + - uses: actions/setup-python@v5 - name: Configure LLVM if: matrix.os != 'Android' || inputs.build_android @@ -2577,11 +2569,7 @@ jobs: run: | cmake --build ${{ github.workspace }}/BinaryCache/libdispatch --target install - - name: Setup python - uses: ./SourceCache/ci-build/.github/actions/setup-python - with: - repo-root: ${{ github.workspace }}/SourceCache/ci-build - + - uses: actions/setup-python@v5 - uses: jannekem/run-python-script-action@v1 if: matrix.os != 'Android' || inputs.build_android with: diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 6573b2805..000000000 --- a/pyproject.toml +++ /dev/null @@ -1,11 +0,0 @@ -# If you are making changes in this file you will likely want one of these commands to clear venv and rebuild it -# deactivate; uv cache clean; rm -rf .venv; uv sync; source .venv/bin/activate -# uv cache clean; rm -rf .venv; uv sync; source .venv/bin/activate - -[project] -name = "swift-build" -version = "1.0.0" -description = "Python package to support the swift-build repository" -readme = "README.md" -requires-python = ">=3.11,<3.12" -dependencies = [] From dba409ed632739cfac8061192451a51fe56e9692 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 2 Jul 2025 08:55:24 -0700 Subject: [PATCH 4/4] Specify python version to use --- .github/workflows/swift-toolchain.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/swift-toolchain.yml b/.github/workflows/swift-toolchain.yml index 0c944f77e..48a066c38 100644 --- a/.github/workflows/swift-toolchain.yml +++ b/.github/workflows/swift-toolchain.yml @@ -688,6 +688,8 @@ jobs: show-progress: false - uses: actions/setup-python@v5 + with: + python-version: '3.11' - name: Configure Tools run: | @@ -1177,6 +1179,9 @@ jobs: } - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - uses: jannekem/run-python-script-action@v1 with: script: | @@ -1691,6 +1696,8 @@ jobs: local-cache: true - uses: actions/setup-python@v5 + with: + python-version: '3.11' - name: Configure LLVM if: matrix.os != 'Android' || inputs.build_android @@ -2570,6 +2577,9 @@ jobs: cmake --build ${{ github.workspace }}/BinaryCache/libdispatch --target install - uses: actions/setup-python@v5 + with: + python-version: '3.11' + - uses: jannekem/run-python-script-action@v1 if: matrix.os != 'Android' || inputs.build_android with: