diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml index 4600ff4b..a50c6c2c 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -18,9 +18,6 @@ jobs: # - "3.12" # - "3.13" runs-on: "${{ matrix.github_actions_runner }}" - env: - LOCK: true - TEST: true steps: - if: startsWith(matrix.github_actions_runner, 'ubuntu-') name: Install PySide6 system dependencies @@ -34,16 +31,22 @@ jobs: - uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c" # v5.0.0 with: python-version: "${{ matrix.python_version }}" - - run: ".tools/sync.ps1" + - run: ". .tools/sync.ps1" + shell: "pwsh" + - run: "SETUP" + shell: "pwsh" + - run: "CI_ONLY_SETUP" + shell: "pwsh" + - run: "LOCK" + shell: "pwsh" + - run: "TEST" shell: "pwsh" - uses: "actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3" #v4.3.1 with: - path: ".lock/*" + path: ".lock/${{ matrix.github_actions_runner }}/${{ matrix.python_version }}" combine: needs: ["lock"] runs-on: "ubuntu-22.04" - env: - COMBINE: true steps: - uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1 with: @@ -55,7 +58,13 @@ jobs: - uses: "actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c" # v5.0.0 with: python-version: "3.11" - - run: ".tools/sync.ps1" + - run: ". .tools/sync.ps1" + shell: "pwsh" + - run: "SETUP" + shell: "pwsh" + - run: "CI_ONLY_SETUP" + shell: "pwsh" + - run: "COMBINE" shell: "pwsh" - uses: "stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d" # v5.0.0 with: diff --git a/.tools/boilercv_tools.py b/.tools/boilercv_tools.py index ec871dd3..c931c929 100644 --- a/.tools/boilercv_tools.py +++ b/.tools/boilercv_tools.py @@ -68,7 +68,7 @@ def sync(): DEV = Path(".tools/requirements/dev.in") NODEPS = Path(".tools/requirements/nodeps.in") PLATFORM_LOCKS = Path(".lock") -ENVIRONMENT = "_".join(["requirements", RUNNER, PYTHON_VERSION.replace(".", "")]) +ENVIRONMENT = "_".join(["requirements", RUNNER, PYTHON_VERSION]) ENVIRONMENT_LOCK = PLATFORM_LOCKS / ENVIRONMENT LOCK = ENVIRONMENT_LOCK / f"{ENVIRONMENT}.txt" diff --git a/.tools/sync.ps1 b/.tools/sync.ps1 index 11b2203f..246e5a7e 100644 --- a/.tools/sync.ps1 +++ b/.tools/sync.ps1 @@ -9,63 +9,41 @@ Param( ) $PSNativeCommandUseErrorActionPreference = $true +$PSNativeCommandUseErrorActionPreference | Out-Null -function Main { - function Main { - run "pip install uv" - inst "-e .tools/." - $tools = 'boilercv_tools' - $lock = run "$tools get-lockfile" - if ($Env:CI) { - run "$tools sync" - if ($Env:LOCK) { - run "$tools lock" - sync $lock - run "$tools lock --highest" - } - # ! Invoke-Expression "$Py -m copier update --defaults --vcs-ref $(git rev-parse HEAD:submodules/template)" - #! if ($Env:TEST) { Invoke-Expression "$Py -m pytest" } - elseif ($Env:COMBINE) { - run "$tools combine-locks" - } - elseif ($Env:TEST) { - run "pytest" - } - return - } - run "$tools find-lock" - sync $lock +function Start-PythonEnv { + <#.SYNOPSIS + Activate a Python virtual environment and return its interpreter. + #> + Param( + # Virtual environment name to activate. + [Parameter(ValueFromPipeline)][string]$Name = '.venv' + ) + if ($IsWindows) { + . "$Name/Scripts/activate" + return "$Env:VIRTUAL_ENV/Scripts/python.exe" } - - $Py = Get-Python - - function run { - Param([Parameter(Mandatory, ValueFromPipeline)][string]$String) - Invoke-Expression "$Py -m $String" + else { + . "$Name/bin/activate" + return "$Env:VIRTUAL_ENV/bin/python" } - function inst { - Param([Parameter(Mandatory, ValueFromPipeline)][string]$String) - if ($Env:CI) { - run "uv pip install --system --break-system-packages $String" - } - else { - run "uv pip install $String" +} + +function Get-GlobalPython { + <#.SYNOPSIS + Get the global Python interpreter for a certain Python version. + #> + if (Get-Command 'py' -ErrorAction Ignore) { + if (py --list | Select-String -Pattern "^\s?-V:$([Regex]::Escape($Version))") { + return "py -$Version" } } - function sync { - Param([Parameter(Mandatory, ValueFromPipeline)][string]$String) - if ($Env:CI) { - run "uv pip sync --system --break-system-packages $String" - } - else { - run "uv pip sync $String" - } + elseif (Get-Command "python$Version" -ErrorAction Ignore) { + return "python$Version" } - - Main + Write-Warning "Python $Version does not appear to be installed. Download and install from 'https://www.python.org/downloads/'." + return } - - function Get-Python { <#.SYNOPSIS Get Python environment for this project. @@ -90,38 +68,68 @@ function Get-Python { return $Py } -function Get-GlobalPython { - <#.SYNOPSIS - Get the global Python interpreter for a certain Python version. - #> - if (Get-Command 'py' -ErrorAction Ignore) { - if (py --list | Select-String -Pattern "^\s?-V:$([Regex]::Escape($Version))") { - return "py -$Version" - } +$Py = Get-Python + +function run { + Param([Parameter(Mandatory, ValueFromPipeline)][string]$String) + Invoke-Expression "$Py -m $String" +} + +function inst { + Param([Parameter(Mandatory, ValueFromPipeline)][string]$String) + if ($Env:CI) { + run "uv pip install --system --break-system-packages $String" } - elseif (Get-Command "python$Version" -ErrorAction Ignore) { - return "python$Version" + else { + run "uv pip install $String" } - Write-Warning "Python $Version does not appear to be installed. Download and install from 'https://www.python.org/downloads/'." - return } -function Start-PythonEnv { - <#.SYNOPSIS - Activate a Python virtual environment and return its interpreter. - #> - Param( - # Virtual environment name to activate. - [Parameter(Mandatory, ValueFromPipeline)][string]$Name = '.venv' - ) - if ($IsWindows) { - . "$Name/Scripts/activate" - return "$Env:VIRTUAL_ENV/Scripts/python.exe" +function sync { + Param([Parameter(Mandatory, ValueFromPipeline)][string]$String) + if ($Env:CI) { + run "uv pip sync --system --break-system-packages $String" } else { - . "$Name/bin/activate" - return "$Env:VIRTUAL_ENV/bin/python" + run "uv pip sync $String" } } -Main +function tools { + Param([Parameter(Mandatory, ValueFromPipeline)][string]$String) + run "boilercv_tools $String" +} + +function SETUP { + run 'pip install uv' + inst '-e .tools/.' + run "$tools find-lock" + sync $lock +} + +function CI_ONLY_SETUP { + run "copier update --defaults --vcs-ref $(git rev-parse HEAD:submodules/template)" + run "$tools sync" +} + +function LOCK { + $lock = tools 'get-lockfile' + run "$tools lock" + sync $lock + run "$tools lock --highest" + elseif ($Env:TEST) { + run 'pytest' + } +} + +function TEST { + run 'pytest' +} + +# * -------------------------------------------------------------------------------- * # + +function COMBINE { + tools 'combine-locks' + run "$tools sync" + run "$tools combine-locks" +}