Merge branch '3.0/build-improvements' into feature/drop-zip-repository

This commit is contained in:
Ondrej Samohel 2021-01-12 15:36:17 +01:00
commit ade80265e7
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
10 changed files with 331 additions and 10 deletions

118
tools/build.ps1 Normal file
View file

@ -0,0 +1,118 @@
<#
.SYNOPSIS
Helper script to build Pype.
.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
}
$art = @'
____________
/\ ___ \
\ \ \/_\ \
\ \ _____/ ______ ___ ___ ___
\ \ \___/ /\ \ \ \\ \\ \
\ \____\ \ \_____\ \__\\__\\__\
\/____/ \/_____/ . PYPE Club .
'@
Write-Host $art -ForegroundColor DarkGreen
$current_dir = Get-Location
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$pype_root = (Get-Item $script_dir).parent.FullName
Set-Location -Path $pype_root
$version_file = Get-Content -Path "$($pype_root)\pype\version.py"
$result = [regex]::Matches($version_file, '__version__ = "(?<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 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 ">>> " -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 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 ..."
& python -m pip install -U pip
& 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
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Building Pype ..."
Set-Location -Path $pype_root
& python setup.py build
deactivate
Set-Location -Path $current_dir

173
tools/build.sh Normal file
View file

@ -0,0 +1,173 @@
#!/usr/bin/env bash
art () {
cat <<-EOF
____________
/\\ \\
\\ \\ --- \\
\\ \\ _____/ ______
\\ \\ \\___/ /\\ \\
\\ \\____\\ \\ \\_____\\
\\/____/ \\/_____/ PYPE Club .
EOF
}
# Colors for terminal
RST='\033[0m' # Text Reset
# Regular Colors
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
White='\033[0;37m' # White
# Bold
BBlack='\033[1;30m' # Black
BRed='\033[1;31m' # Red
BGreen='\033[1;32m' # Green
BYellow='\033[1;33m' # Yellow
BBlue='\033[1;34m' # Blue
BPurple='\033[1;35m' # Purple
BCyan='\033[1;36m' # Cyan
BWhite='\033[1;37m' # White
# Bold High Intensity
BIBlack='\033[1;90m' # Black
BIRed='\033[1;91m' # Red
BIGreen='\033[1;92m' # Green
BIYellow='\033[1;93m' # Yellow
BIBlue='\033[1;94m' # Blue
BIPurple='\033[1;95m' # Purple
BICyan='\033[1;96m' # Cyan
BIWhite='\033[1;97m' # White
###############################################################################
# Test if Xcode Command Line tools are installed in MacOS
###############################################################################
have_command_line_tools() {
[[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
}
###############################################################################
# Get command any key from user
###############################################################################
getc() {
local save_state
save_state=$(/bin/stty -g)
/bin/stty raw -echo
IFS= read -r -n 1 -d '' "$@"
/bin/stty "$save_state"
}
###############################################################################
# Test if we have access via sudo
# Used in MacOS
###############################################################################
have_sudo_access() {
if [[ -z "${HAVE_SUDO_ACCESS-}" ]]; then
/usr/bin/sudo -l mkdir &>/dev/null
HAVE_SUDO_ACCESS="$?"
fi
if [[ "$HAVE_SUDO_ACCESS" -ne 0 ]]; then
echo -e "${BIRed}!!!${RST} Need sudo access on MacOS"
return 1
fi
return "$HAVE_SUDO_ACCESS"
}
###############################################################################
# Execute command and report failure
###############################################################################
execute() {
if ! "$@"; then
echo -e "${BIRed}!!!${RST} Failed execution of ${BIWhite}[ $@ ]${RST}"
fi
}
###############################################################################
# Execute command using sudo
# This is used on MacOS to handle Xcode command line tools installation
###############################################################################
execute_sudo() {
local -a args=("$@")
if [[ -n "${SUDO_ASKPASS-}" ]]; then
args=("-A" "${args[@]}")
fi
if have_sudo_access; then
echo -e "${BIGreen}>->${RST} sudo: [${BIWhite} ${args[@]} ${RST}]"
execute "/usr/bin/sudo" "${args[@]}"
else
echo -e "${BIGreen}>->${RST} [${BIWhite} ${args[@]} ${RST}]"
execute "${args[@]}"
fi
}
##############################################################################
# Detect required version of python
# Globals:
# colors
# PYTHON
# Arguments:
# None
# Returns:
# None
###############################################################################
detect_python () {
echo -e "${BIYellow}>>>${RST} Forced using python at [ ${BIWhite}[ $PYPE_PYTHON_EXE ]${RST} ... \c"
local version_command="import sys;print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))"
local python_version="$(python3 <<< ${version_command})"
oIFS="$IFS"
IFS=.
set -- $python_version
IFS="$oIFS"
if [ "$1" -ge "3" ] && [ "$2" -ge "6" ] ; then
echo -e "${BIGreen}$1.$2${RST}"
PYTHON="python3"
else
command -v python3 >/dev/null 2>&1 || { echo -e "${BIRed}FAILED${RST} ${BIYellow} Version [${RST}${BICyan}$1.$2${RST}]${BIYellow} is old and unsupported${RST}"; return 1; }
fi
}
##############################################################################
# Clean pyc files in specified directory
# Globals:
# None
# Arguments:
# Optional path to clean
# Returns:
# None
###############################################################################
clean_pyc () {
path=${1:-$PYPE_SETUP_PATH}
echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c"
find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete
echo -e "${BIGreen}DONE${RST}"
}
# Main
art
detect_python || return 1
version_command="import version;print(version.__version__)"
pype_version="$(python3 <<< ${version_command})"
echo -e "${IGreen}>>>${RST} Building Pype [${IGreen} v$pype_version ${RST}]"
echo -e "${IGreen}>>>${RST} Creating virtual env ..."
python3 -m venv venv
echo -e "${IGreen}>>>${RST} Entering venv ..."
source venv/bin/activate
echo -e "${IGreen}>>>${RST} Installing packages to new venv ..."
pip install -r requirements.txt
echo -e "${IGreen}>>>${RST} Cleaning cache files ..."
clean_pyc
echo -e "${IGreen}>>>${RST} Building ..."
python setup.py build
deactivate

148
tools/create_env.ps1 Normal file
View file

@ -0,0 +1,148 @@
<#
.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
if ($PSVersionTable.PSVersion.Major -lt 7) {
Write-Host "!!! " -NoNewline -ForegroundColor Red
Write-Host "You are using old version of PowerShell. $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)"
Write-Host "Please update to at least 7.0 - https://github.com/PowerShell/PowerShell/releases"
Exit-WithCode 1
}
$arguments=$ARGS
if($arguments -eq "--skip-venv") {
$skip_venv=$true
}
$art = @'
____________
/\ ___ \
\ \ \/_\ \
\ \ _____/ ______ ___ ___ ___
\ \ \___/ /\ \ \ \\ \\ \
\ \____\ \ \_____\ \__\\__\\__\
\/____/ \/_____/ . PYPE Club .
'@
Write-Host $art -ForegroundColor DarkGreen
$version_file = Get-Content -Path "$($pype_root)\pype\version.py"
$result = [regex]::Matches($version_file, '__version__ = "(?<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
if ($skip_venv -ne $true) {
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Creating virtual env ..."
& python -m venv venv
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Entering venv ..."
try {
. (".\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 "Updating pip ..."
& python -m pip install --upgrade pip
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Installing packages to new venv ..."
& pip install -r .\requirements.txt
} else {
Write-Host "*** " -NoNewline -ForegroundColor yellow
Write-Host "Skipping creaton of venv ..."
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Entering venv ..."
try {
. (".\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 "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
# store original PYTHONPATH
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Storing original PYTHONPATH ... " -NoNewline
$original_pythonpath = $env:PYTHONPATH
Write-Host "OK" -ForegroundColor green
$new_pythonpath = Get-ChildItem -Directory -Path .\ | Microsoft.PowerShell.Utility\Join-String -Property FullName -DoubleQuote -Separator ';'
$env:PYTHONPATH = $env:PYTHONPATH + ";" + $new_pythonpath
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Adding repos to PYTHONPATH ..."
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Building Pype ..."
& python setup.py build
Write-Host ">>> " -NoNewline -ForegroundColor green
Write-Host "Restoring original PYTHONPATH ... " -NoNewline
$env:PYTHONPATH = $original_pythonpath
Write-Host "OK" -ForegroundColor green
deactivate

View file

@ -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
deactivate
Set-Location -Path $current_dir

6
tools/run_mongo.ps1 Normal file
View file

@ -0,0 +1,6 @@
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$pype_root = (Get-Item $script_dir).parent.FullName
& "$($pype_root)\venv\Scripts\Activate.ps1"
python "$($pype_root)\pype.py" mongodb

6
tools/run_settings.ps1 Normal file
View file

@ -0,0 +1,6 @@
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$pype_root = (Get-Item $script_dir).parent.FullName
& "$($pype_root)\venv\Scripts\Activate.ps1"
python "$($pype_root)\pype.py" settings --dev

6
tools/run_tray.ps1 Normal file
View file

@ -0,0 +1,6 @@
$script_dir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$pype_root = (Get-Item $script_dir).parent.FullName
& "$($pype_root)\venv\Scripts\Activate.ps1"
python "$($pype_root)\pype.py" tray --debug