Skip to content

Commit

Permalink
try this
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeNaccarato committed Mar 13, 2024
1 parent 2575fe4 commit 5b46d3e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 85 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .tools/boilercv_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
160 changes: 84 additions & 76 deletions .tools/sync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
}

0 comments on commit 5b46d3e

Please sign in to comment.