From 32ee682168e5093f3a70f206b3fc3e99f510e7f2 Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Mon, 21 Dec 2020 19:46:30 +0100 Subject: [PATCH] move scripts to tools, make them path independent, clean build dir --- build.ps1 => tools/build.ps1 | 23 +++++--- build.sh => tools/build.sh | 0 tools/create_env.ps1 | 102 +++++++++++++++++++++++++++++++++++ tools/make_docs.ps1 | 51 ++++++++++++++++-- 4 files changed, 166 insertions(+), 10 deletions(-) rename build.ps1 => tools/build.ps1 (79%) rename build.sh => tools/build.sh (100%) create mode 100644 tools/create_env.ps1 diff --git a/build.ps1 b/tools/build.ps1 similarity index 79% rename from build.ps1 rename to tools/build.ps1 index 39ce90e36a..795b9b74ef 100644 --- a/build.ps1 +++ b/tools/build.ps1 @@ -38,7 +38,11 @@ $art = @' Write-Host $art -ForegroundColor DarkGreen -$version_file = Get-Content -Path ".\pype\version.py" +$current_dir = Get-Location +$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent +$pype_root = (Get-Item $script_dir).parent.FullName + +$version_file = Get-Content -Path "$($pype_root)\pype\version.py" $result = [regex]::Matches($version_file, '__version__ = "(?\d+\.\d+.\d+)"') $pype_version = $result[0].Groups['version'].Value if (-not $pype_version) { @@ -47,10 +51,14 @@ if (-not $pype_version) { Exit-WithCode 1 } +Write-Host "--- " -NoNewline -ForegroundColor yellow +Write-Host "Cleaning build directory ..." +Remove-Item -Recurse -Force "$($pype_root)\build\*" + Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Building Pype [ " -NoNewline -ForegroundColor white Write-host $pype_version -NoNewline -ForegroundColor green -Write-Host " ]..." -ForegroundColor white +Write-Host " ] ..." -ForegroundColor white Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Detecting host Python ... " -NoNewline @@ -78,11 +86,11 @@ if(($matches[1] -lt 3) -or ($matches[2] -lt 7)) { Write-Host "OK [ $p ]" -ForegroundColor green Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Creating virtual env ..." -& python -m venv venv +& python -m venv "$($pype_root)\venv" Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Entering venv ..." try { - . (".\venv\Scripts\Activate.ps1") + . ("$($pype_root)\venv\Scripts\Activate.ps1") } catch { Write-Host "!!! Failed to activate" -ForegroundColor red @@ -91,15 +99,18 @@ catch { } Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Installing packages to new venv ..." +& pip -m pip install -U pip & pip install -r .\requirements.txt Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Cleaning cache files ... " -NoNewline -Get-ChildItem . -Filter "*.pyc" -Force -Recurse | Remove-Item -Force -Get-ChildItem . -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse +Get-ChildItem $pype_root -Filter "*.pyc" -Force -Recurse | Remove-Item -Force +Get-ChildItem $pype_root -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse Write-Host "OK" -ForegroundColor green Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Building Pype ..." +Set-Location -Path $pype_root & python setup.py build deactivate +Set-Location -Path $current_dir diff --git a/build.sh b/tools/build.sh similarity index 100% rename from build.sh rename to tools/build.sh diff --git a/tools/create_env.ps1 b/tools/create_env.ps1 new file mode 100644 index 0000000000..ec9f8003b8 --- /dev/null +++ b/tools/create_env.ps1 @@ -0,0 +1,102 @@ +<# +.SYNOPSIS + Helper script create virtual env. + +.DESCRIPTION + This script will detect Python installation, create venv and install + all necessary packages from `requirements.txt` needed by Pype to be + included during application freeze on Windows. + +.EXAMPLE + +PS> .\build.ps1 + +#> + + +function Exit-WithCode($exitcode) { + # Only exit this host process if it's a child of another PowerShell parent process... + $parentPID = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$PID" | Select-Object -Property ParentProcessId).ParentProcessId + $parentProcName = (Get-CimInstance -ClassName Win32_Process -Filter "ProcessId=$parentPID" | Select-Object -Property Name).Name + if ('powershell.exe' -eq $parentProcName) { $host.SetShouldExit($exitcode) } + + exit $exitcode +} +$current_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent +$pype_root = (Get-Item $current_dir).parent.FullName + +$art = @' + + + ____________ + /\ ___ \ + \ \ \/_\ \ + \ \ _____/ ______ ___ ___ ___ + \ \ \___/ /\ \ \ \\ \\ \ + \ \____\ \ \_____\ \__\\__\\__\ + \/____/ \/_____/ . PYPE Club . + +'@ + +Write-Host $art -ForegroundColor DarkGreen + +$version_file = Get-Content -Path "$($pype_root)\pype\version.py" +$result = [regex]::Matches($version_file, '__version__ = "(?\d+\.\d+.\d+)"') +$pype_version = $result[0].Groups['version'].Value +if (-not $pype_version) { + Write-Host "!!! " -ForegroundColor yellow -NoNewline + Write-Host "Cannot determine Pype version." + Exit-WithCode 1 +} + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Detecting host Python ... " -NoNewline +if (-not (Get-Command "python" -ErrorAction SilentlyContinue)) { + Write-Host "!!! Python not detected" -ForegroundColor red + Exit-WithCode 1 +} +$version_command = @' +import sys +print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1])) +'@ + +$p = & python -c $version_command +$env:PYTHON_VERSION = $p +$m = $p -match '(\d+)\.(\d+)' +if(-not $m) { + Write-Host "!!! Cannot determine version" -ForegroundColor red + Exit-WithCode 1 +} +# We are supporting python 3.6 and up +if(($matches[1] -lt 3) -or ($matches[2] -lt 7)) { + Write-Host "FAILED Version [ $p ] is old and unsupported" -ForegroundColor red + Exit-WithCode 1 +} +Write-Host "OK [ $p ]" -ForegroundColor green + +Write-Host "--- " -NoNewline -ForegroundColor yellow +Write-Host "Cleaning virtual env directory ..." +Remove-Item -Recurse -Force "$($pype_root)/venv/*" + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Creating virtual env ..." +& python -m venv "$($pype_root)/venv" +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Entering venv ..." +try { + . ("$($pype_root)\venv\Scripts\Activate.ps1") +} +catch { + Write-Host "!!! Failed to activate" -ForegroundColor red + Write-Host $_.Exception.Message + Exit-WithCode 1 +} +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Installing packages to new venv ..." +& pip install -r "$pype_root\requirements.txt" + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Cleaning cache files ... " -NoNewline +Get-ChildItem "$($pype_root)" -Filter "*.pyc" -Force -Recurse | Remove-Item -Force +Get-ChildItem "$($pype_root)" -Filter "__pycache__" -Force -Recurse | Remove-Item -Force -Recurse +Write-Host "OK" -ForegroundColor green diff --git a/tools/make_docs.ps1 b/tools/make_docs.ps1 index 475448d05e..30032d41a6 100644 --- a/tools/make_docs.ps1 +++ b/tools/make_docs.ps1 @@ -1,5 +1,48 @@ -& .\venv\Scripts\Activate.ps1 -sphinx-apidoc.exe -M -e -d 10 -o .\docs\source igniter -sphinx-apidoc.exe -M -e -d 10 -o .\docs\source pype vendor, pype\vendor +<# +.SYNOPSIS + Helper script to update Pype Sphinx sources. + +.DESCRIPTION + This script will run apidoc over Pype sources and generate new source rst + files for documentation. Then it will run build_sphinx to create test html + documentation build. + +.EXAMPLE + +PS> .\make_docs.ps1 + +#> + +$current_dir = Get-Location +$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent +$pype_root = (Get-Item $script_dir).parent.FullName + +$art = @' + + + ____________ + /\ ___ \ + \ \ \/_\ \ + \ \ _____/ ______ ___ ___ ___ + \ \ \___/ /\ \ \ \\ \\ \ + \ \____\ \ \_____\ \__\\__\\__\ + \/____/ \/_____/ . PYPE Club . + +'@ + +Write-Host $art -ForegroundColor DarkGreen + + +& "$($pype_root)\venv\Scripts\Activate.ps1" +Write-Host "This will not overwrite existing source rst files, only scan and add new." +Set-Location -Path $pype_root +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Running apidoc ..." +sphinx-apidoc.exe -M -e -d 10 --ext-intersphinx --ext-todo --ext-coverage --ext-viewcode -o "$($pype_root)\docs\source" igniter +sphinx-apidoc.exe -M -e -d 10 --ext-intersphinx --ext-todo --ext-coverage --ext-viewcode -o "$($pype_root)\docs\source" pype vendor, pype\vendor + +Write-Host ">>> " -NoNewline -ForegroundColor green +Write-Host "Building html ..." python setup.py build_sphinx -deactivate \ No newline at end of file +deactivate +Set-Location -Path $current_dir