From 2f20e9029b92c0bd6a314b6aa333eb7302a19b74 Mon Sep 17 00:00:00 2001 From: "Karsten A. M. Guenther" Date: Wed, 18 Sep 2024 23:22:39 +0200 Subject: [PATCH] chore: switch to bootstrap for windows --- .github/workflows/windows.yml | 4 +- .gitignore | 167 ++++++++++++++++++++++++++++++++-- .vscode/settings.json | 15 +-- build.bat | 1 + build.ps1 | 136 ++++++++++++++------------- install-mandatory.list | 5 - pytest.ini | 7 ++ scoopfile.json | 27 ++++++ 8 files changed, 267 insertions(+), 95 deletions(-) create mode 100644 build.bat delete mode 100644 install-mandatory.list create mode 100644 pytest.ini create mode 100644 scoopfile.json diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 67864fa..0f523bd 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -17,8 +17,8 @@ jobs: steps: - name: Check out repository code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: install tools, run selftests and create package (w/o deploying) - run: .\build.ps1 -installMandatory + run: .\build.ps1 -install shell: powershell diff --git a/.gitignore b/.gitignore index 9b019a5..7f7e2d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,162 @@ -# What: Python: byte-compiled / optimized / DLL files -# Why: automatically created by Python during script execution +# Output directory of tests +/out + +# Any log directory +**/[Ll][Oo][Gg]/* + +# Any backup file of text editors +*.bak + +# Backup files of KConfig +*.old + +# Generated IDEA project files +.idea + +# bootstrap files are downloaded during installation +/.bootstrap + +# Byte-compiled / optimized / DLL files __pycache__/ +/.pytest_cache *.py[cod] *$py.class -# What: CMake build output folder -# Why: automatically created by CMake -/build -/dist -/*.egg-info/ -/.eggs/ +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +# Images generated by sphinx-traceability-extension (e.g. pie-charts) +docs/_images + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder {{package_name}} settings +.spyderproject +.spyproject + +# Rope {{package_name}} settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ -# PyCharm generated project folder -.idea \ No newline at end of file +# Draw.io backup files +*.drawio.bkp diff --git a/.vscode/settings.json b/.vscode/settings.json index ac449b5..16f874c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,5 @@ { - "python.testing.pytestArgs": [ - "tests", - "--capture=tee-sys" - ], + "files.insertFinalNewline": true, "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "python.formatting.provider": "black", @@ -29,13 +26,5 @@ "titleBar.inactiveBackground": "#f9e64f99", "titleBar.inactiveForeground": "#15202b99", "commandCenter.border": "#15202b99" - }, - "peacock.color": "#f9e64f", - "cmake.sourceDirectory": "${workspaceFolder}/tests/data/mini_c_test", - "cmake.environment": { - "poetry_MAX_DEPTH" : "10" - }, - "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", - "esbonio.sphinx.confDir": "", - "cmake.configureOnOpen": false + } } diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..b159d6a --- /dev/null +++ b/build.bat @@ -0,0 +1 @@ +powershell -ExecutionPolicy Bypass -File %~dp0build.ps1 %* || exit /b 1 diff --git a/build.ps1 b/build.ps1 index a520adc..382e3af 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,93 +1,99 @@ <# .DESCRIPTION Wrapper for installing dependencies, running and testing the project - -.Notes -On Windows, it may be required to enable this script by setting the execution -policy for the user. You can do this by issuing the following PowerShell command: - -PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser - -For more information on Execution Policies: -https://go.microsoft.com/fwlink/?LinkID=135170 #> param( - [switch]$installMandatory ## install mandatory packages (e.g., CMake, Ninja, ...) + [switch]$clean ## clean build, wipe out all build artifacts + , [switch]$install ## install mandatory packages ) -$ErrorActionPreference = "Stop" - -# Needed on Jenkins, somehow the env var PATH is not updated automatically -# after tool installations by scoop -Function ReloadEnvVars () { - $Env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine") -} - -Function ScoopInstall ([string[]]$Packages) { - Invoke-CommandLine -CommandLine "scoop install $Packages" - ReloadEnvVars -} - -Function Invoke-CommandLine { +function Invoke-CommandLine { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression', '', Justification = 'Usually this statement must be avoided (https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/avoid-using-invoke-expression?view=powershell-7.3), here it is OK as it does not execute unknown code.')] param ( + [Parameter(Mandatory = $true, Position = 0)] [string]$CommandLine, + [Parameter(Mandatory = $false, Position = 1)] [bool]$StopAtError = $true, + [Parameter(Mandatory = $false, Position = 2)] + [bool]$PrintCommand = $true, + [Parameter(Mandatory = $false, Position = 3)] [bool]$Silent = $false ) - if (-Not $Silent) { - Write-Host "Executing: $CommandLine" + if ($PrintCommand) { + Write-Output "Executing: $CommandLine" + } + $global:LASTEXITCODE = 0 + if ($Silent) { + # Omit information stream (6) and stdout (1) + Invoke-Expression $CommandLine 6>&1 | Out-Null } - Invoke-Expression $CommandLine - if ($LASTEXITCODE -ne 0) { + else { + Invoke-Expression $CommandLine + } + if ($global:LASTEXITCODE -ne 0) { if ($StopAtError) { - Write-Error "Command line call `"$CommandLine`" failed with exit code $LASTEXITCODE" - exit 1 + Write-Error "Command line call `"$CommandLine`" failed with exit code $global:LASTEXITCODE" } else { - if (-Not $Silent) { - Write-Host "Command line call `"$CommandLine`" failed with exit code $LASTEXITCODE, continuing ..." - } + Write-Output "Command line call `"$CommandLine`" failed with exit code $global:LASTEXITCODE, continuing ..." } } } -Push-Location $PSScriptRoot +function Invoke-Bootstrap { + # Download bootstrap scripts from external repository + Invoke-RestMethod https://raw.githubusercontent.com/avengineers/bootstrap-installer/v1.13.0/install.ps1 | Invoke-Expression + # Execute bootstrap script + . .\.bootstrap\bootstrap.ps1 +} + +function Remove-Path { + param ( + [Parameter(Mandatory = $true, Position = 0)] + [string]$path + ) + if (Test-Path -Path $path -PathType Container) { + Write-Output "Deleting directory '$path' ..." + Remove-Item $path -Force -Recurse + } + elseif (Test-Path -Path $path -PathType Leaf) { + Write-Output "Deleting file '$path' ..." + Remove-Item $path -Force + } +} +## start of script +# Always set the $InformationPreference variable to "Continue" globally, +# this way it gets printed on execution and continues execution afterwards. +$InformationPreference = "Continue" + +# Stop on first error +$ErrorActionPreference = "Stop" + +Push-Location $PSScriptRoot Write-Output "Running in ${pwd}" -if ($installMandatory) { - if (-Not (Get-Command scoop -errorAction SilentlyContinue)) { - # Initial Scoop installation - iwr get.scoop.sh -outfile 'install.ps1' - if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { - & .\install.ps1 -RunAsAdmin - } else { - & .\install.ps1 +try { + + if ($install) { + if ($clean) { + Remove-Path ".venv" } - ReloadEnvVars - } - # Necessary for 7zip installation, failed on Jenkins for unknown reason. See those issues: - # https://github.com/ScoopInstaller/Scoop/issues/460 - # https://github.com/ScoopInstaller/Scoop/issues/4024 - ScoopInstall('lessmsi') - Invoke-CommandLine -CommandLine "scoop config MSIEXTRACT_USE_LESSMSI $true" - # Default installer tools, e.g., dark is required for python - ScoopInstall('7zip', 'innounp', 'dark') - Invoke-CommandLine -CommandLine "scoop bucket add extras" -StopAtError $false - Invoke-CommandLine -CommandLine "scoop bucket add versions" -StopAtError $false + # bootstrap environment + Invoke-Bootstrap + } - Invoke-CommandLine -CommandLine "scoop update" - ScoopInstall(Get-Content 'install-mandatory.list') - $PipInstaller = "python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org" - Invoke-CommandLine -CommandLine "$PipInstaller poetry" - ReloadEnvVars + if ($clean) { + Remove-Path "build" + } + + Invoke-CommandLine ".venv\Scripts\poetry run python -m pytest" + Invoke-CommandLine ".venv\Scripts\poetry build" + Invoke-CommandLine ".venv\Scripts\poetry run make --directory doc html" } - -Invoke-CommandLine -CommandLine "poetry install" -Invoke-CommandLine -CommandLine "poetry run python -m pytest --verbose --capture=tee-sys" -Invoke-CommandLine -CommandLine "poetry build" -Invoke-CommandLine -CommandLine "poetry run make --directory doc html" - -Pop-Location +finally { + Pop-Location +} +## end of script diff --git a/install-mandatory.list b/install-mandatory.list deleted file mode 100644 index fd15828..0000000 --- a/install-mandatory.list +++ /dev/null @@ -1,5 +0,0 @@ -cmake -python311 -mingw-winlibs-llvm-ucrt -plantuml -umlet diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..26df868 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,7 @@ +[pytest] +testpaths = + "tests" +junit_logging = all +addopts = + --capture=tee-sys + --verbose diff --git a/scoopfile.json b/scoopfile.json new file mode 100644 index 0000000..d7344cf --- /dev/null +++ b/scoopfile.json @@ -0,0 +1,27 @@ +{ + "buckets": [ + { + "Name": "spl", + "Source": "https://github.com/avengineers/spl-bucket" + }, + { + "Name": "extras", + "Source": "https://github.com/ScoopInstaller/Extras" + } + ], + "apps": [ + { + "Source": "spl", + "Name": "mingw-winlibs-llvm-ucrt", + "Version": "13.2.0-16.0.6-11.0.0-ucrt-r1" + }, + { + "Source": "extras", + "Name": "plantuml" + }, + { + "Source": "extras", + "Name": "umlet" + } + ] +}