From 10f4ea8a0ddea9ed4b8a838a4f27b1b2fc8bbb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Thu, 10 Sep 2020 15:56:48 +0200 Subject: [PATCH] build script for linux, acre as submodule --- .gitmodules | 4 ++ README.md | 2 + build.ps1 | 9 ++- build.sh | 170 ++++++++++++++++++++++++++++++++++++++++++++++- repos/acre | 1 + requirements.txt | 1 + 6 files changed, 185 insertions(+), 2 deletions(-) create mode 160000 repos/acre diff --git a/.gitmodules b/.gitmodules index ddb694b181..1209b475e4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,7 @@ [submodule "repos/pype-config"] path = repos/pype-config url = git@github.com:pypeclub/pype-config.git +[submodule "repos/acre"] + path = repos/acre + url = git@github.com:antirotor/acre.git + branch = fix/unformatted-tokens diff --git a/README.md b/README.md index e8c47d8b04..4ad52c7e36 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,7 @@ Run PowerShell script `build.ps1`. It will create *venv*, install all required dependencies and build Pype. After it is finished, you will find Pype in `build` folder. +You might need more tools for installing dependencies (for example for **OpenTimelineIO**) - mostly +development tools like [CMake](https://cmake.org/) and [Visual Studio](https://visualstudio.microsoft.com/cs/downloads/) Pype is build using [CX_Freeze](https://cx-freeze.readthedocs.io/en/latest) to freeze itself and all dependencies. diff --git a/build.ps1 b/build.ps1 index 89f19c29b4..9b65dae896 100644 --- a/build.ps1 +++ b/build.ps1 @@ -79,7 +79,7 @@ Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Creating virtual env ..." & python -m venv venv Write-Host ">>> " -NoNewline -ForegroundColor green -Write-Host "Entering venv..." +Write-Host "Entering venv ..." try { . (".\venv\Scripts\Activate.ps1") } @@ -91,6 +91,13 @@ catch { Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Installing packages to new venv ..." & 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 +Write-Host "OK" -ForegroundColor green + Write-Host ">>> " -NoNewline -ForegroundColor green Write-Host "Building Pype ..." & python setup.py build diff --git a/build.sh b/build.sh index 55205ca287..61f8943931 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,173 @@ #!/usr/bin/env bash -virtualenv venv +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 diff --git a/repos/acre b/repos/acre new file mode 160000 index 0000000000..3d06232bd4 --- /dev/null +++ b/repos/acre @@ -0,0 +1 @@ +Subproject commit 3d06232bd424df4350efe64ab459944b4096ca74 diff --git a/requirements.txt b/requirements.txt index bb1cfc2f1e..3cdc32aa3d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +wheel certifi Click clique==1.5.0