From be860f92df6a8234fcb2d656a995202daf42cd1e Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Wed, 17 Feb 2021 16:53:56 +0100 Subject: [PATCH] cosmetic fixes in shell scripts --- pyproject.toml | 2 +- tools/build.sh | 54 ++++++++++++++++++++----------------- tools/create_env.sh | 5 ++-- tools/create_zip.sh | 27 +++++++++++-------- tools/make_docs.sh | 26 ++++++++++-------- tools/run_mongo.sh | 26 +++++++++--------- tools/run_settings.sh | 27 +++++++++++-------- tools/run_tests.sh | 32 ++++++++++++---------- tools/run_tray.sh | 27 +++++++++++-------- tools/update_submodules.sh | 55 -------------------------------------- 10 files changed, 129 insertions(+), 152 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 047a9176d1..279cf1ac27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ jinxed = [ flake8 = "^3.7" autopep8 = "^1.4" coverage = "*" -cx_freeze = "~6.2" +cx_freeze = "~6.5" jedi = "^0.13" Jinja2 = "^2.11" pycodestyle = "^2.5.0" diff --git a/tools/build.sh b/tools/build.sh index 5a54a6c004..43f341e6c6 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -63,11 +63,13 @@ BIWhite='\033[1;97m' # White ############################################################################### detect_python () { echo -e "${BIGreen}>>>${RST} Using python \c" - local version_command="import sys;print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))" - local python_version="$(python3 <<< ${version_command})" + local version_command + version_command="import sys;print('{0}.{1}'.format(sys.version_info[0], sys.version_info[1]))" + local python_version + python_version="$(python3 <<< ${version_command})" oIFS="$IFS" IFS=. - set -- $python_version + set -- "$python_version" IFS="$oIFS" if [ "$1" -ge "3" ] && [ "$2" -ge "6" ] ; then if [ "$2" -gt "7" ] ; then @@ -75,7 +77,6 @@ detect_python () { else echo -e "${BIWhite}[${RST} ${BIGreen}$1.$2${RST} ${BIWhite}]${RST}" fi - PYTHON="python3" else command -v python3 >/dev/null 2>&1 || { echo -e "${BIRed}$1.$2$ - ${BIRed}FAILED${RST} ${BIYellow}Version is old and unsupported${RST}"; return 1; } fi @@ -91,7 +92,8 @@ detect_python () { # None ############################################################################### clean_pyc () { - path=${1:-$pype_root} + local path + path=$pype_root echo -e "${BIGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete echo -e "${BIGreen}DONE${RST}" @@ -111,27 +113,31 @@ realpath () { } # Main -echo -e "${BGreen}" -art -echo -e "${RST}" -detect_python || return 1 +main () { + echo -e "${BGreen}" + art + echo -e "${RST}" + detect_python || return 1 -# Directories -pype_root=$(dirname $(dirname "$(realpath ${BASH_SOURCE[0]})")) -pushd "$pype_root" > /dev/null || return > /dev/null + # Directories + pype_root=$(dirname $(dirname "$(realpath ${BASH_SOURCE[0]})")) + pushd "$pype_root" > /dev/null || return > /dev/null -version_command="import os;exec(open(os.path.join('$pype_root', 'pype', 'version.py')).read());print(__version__);" -pype_version="$(python3 <<< ${version_command})" + version_command="import os;exec(open(os.path.join('$pype_root', 'pype', 'version.py')).read());print(__version__);" + pype_version="$(python3 <<< ${version_command})" -echo -e "${BIYellow}---${RST} Cleaning build directory ..." -rm -rf "$pype_root/build" && mkdir "$pype_root/build" > /dev/null + echo -e "${BIYellow}---${RST} Cleaning build directory ..." + rm -rf "$pype_root/build" && mkdir "$pype_root/build" > /dev/null -echo -e "${BIGreen}>>>${RST} Building Pype ${BIWhite}[${RST} ${BIGreen}$pype_version${RST} ${BIWhite}]${RST}" -echo -e "${BIGreen}>>>${RST} Cleaning cache files ..." -clean_pyc -echo -e "${BIGreen}>>>${RST} Building ..." -poetry run python3 "$pype_root/setup.py" build > "$pype_root/build/build.log" -poetry run python3 "$pype_root/tools/build_dependencies.py" + echo -e "${BIGreen}>>>${RST} Building Pype ${BIWhite}[${RST} ${BIGreen}$pype_version${RST} ${BIWhite}]${RST}" + echo -e "${BIGreen}>>>${RST} Cleaning cache files ..." + clean_pyc + echo -e "${BIGreen}>>>${RST} Building ..." + poetry run python3 "$pype_root/setup.py" build > "$pype_root/build/build.log" + poetry run python3 "$pype_root/tools/build_dependencies.py" -echo -e "${BICyan}>>>${RST} All done. You will find Pype and build log in \c" -echo -e "${BIWhite}$pype_root/build${RST} directory." + echo -e "${BICyan}>>>${RST} All done. You will find Pype and build log in \c" + echo -e "${BIWhite}$pype_root/build${RST} directory." +} + +main diff --git a/tools/create_env.sh b/tools/create_env.sh index cc841f1cb0..81ee5dd68a 100755 --- a/tools/create_env.sh +++ b/tools/create_env.sh @@ -99,8 +99,9 @@ install_poetry () { # None ############################################################################### clean_pyc () { - path=${1:-$pype_root} - echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" + local path + path=$pype_root + echo -e "${BIGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete echo -e "${BIGreen}DONE${RST}" } diff --git a/tools/create_zip.sh b/tools/create_zip.sh index 1d985c0a6b..633f874921 100755 --- a/tools/create_zip.sh +++ b/tools/create_zip.sh @@ -91,8 +91,9 @@ detect_python () { # None ############################################################################### clean_pyc () { - path=${1:-$pype_root} - echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" + local path + path=$pype_root + echo -e "${BIGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete echo -e "${BIGreen}DONE${RST}" } @@ -111,14 +112,18 @@ realpath () { } # Main -echo -e "${BGreen}" -art -echo -e "${RST}" -detect_python || return 1 +main () { + echo -e "${BGreen}" + art + echo -e "${RST}" + detect_python || return 1 -# Directories -pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) -pushd "$pype_root" > /dev/null || return > /dev/null + # Directories + pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) + pushd "$pype_root" > /dev/null || return > /dev/null -echo -e "${BIGreen}>>>${RST} Generating zip from current sources ..." -poetry run python3 "$pype_root/start.py" generate-zip "$@" + echo -e "${BIGreen}>>>${RST} Generating zip from current sources ..." + poetry run python3 "$pype_root/start.py" generate-zip "$@" +} + +main "$@" diff --git a/tools/make_docs.sh b/tools/make_docs.sh index 1b4159c61f..ed5c72b055 100755 --- a/tools/make_docs.sh +++ b/tools/make_docs.sh @@ -65,17 +65,21 @@ realpath () { } # Main -echo -e "${BGreen}" -art -echo -e "${RST}" +main () { + echo -e "${BGreen}" + art + echo -e "${RST}" -# Directories -pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) -pushd "$pype_root" > /dev/null || return > /dev/null + # Directories + pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) + pushd "$pype_root" > /dev/null || return > /dev/null -echo -e "${BIGreen}>>>${RST} Running apidoc ..." -poetry run sphinx-apidoc -M -e -d 10 --ext-intersphinx --ext-todo --ext-coverage --ext-viewcode -o "$pype_root/docs/source" igniter -poetry run sphinx-apidoc -M -e -d 10 --ext-intersphinx --ext-todo --ext-coverage --ext-viewcode -o "$pype_root/docs/source" pype vendor, pype\vendor + echo -e "${BIGreen}>>>${RST} Running apidoc ..." + poetry run sphinx-apidoc -M -e -d 10 --ext-intersphinx --ext-todo --ext-coverage --ext-viewcode -o "$pype_root/docs/source" igniter + poetry run sphinx-apidoc -M -e -d 10 --ext-intersphinx --ext-todo --ext-coverage --ext-viewcode -o "$pype_root/docs/source" pype vendor, pype\vendor -echo -e "${BIGreen}>>>${RST} Building html ..." -poetry run python3 "$pype_root/setup.py" build_sphinx + echo -e "${BIGreen}>>>${RST} Building html ..." + poetry run python3 "$pype_root/setup.py" build_sphinx +} + +main diff --git a/tools/run_mongo.sh b/tools/run_mongo.sh index 6f9e0f5411..209e80ac5b 100755 --- a/tools/run_mongo.sh +++ b/tools/run_mongo.sh @@ -66,18 +66,20 @@ realpath () { } # Main -echo -e "${BGreen}" -art -echo -e "${RST}" +main () { + echo -e "${BGreen}" + art + echo -e "${RST}" -# Directories -pype_root=$(dirname $(realpath $(dirname $(dirname "${BASH_SOURCE[0]}")))) -pushd "$pype_root" > /dev/null + # Directories + pype_root=$(dirname $(realpath $(dirname $(dirname "${BASH_SOURCE[0]}")))) + pushd "$pype_root" > /dev/null || return > /dev/null -mongo_port=2707 -echo $pype_root -dbpath="$(dirname $pype_root)/mongo_db_data" + mongo_port=2707 + dbpath="$(dirname $pype_root)/mongo_db_data" + + echo -e "${BIGreen}>>>${RST} Running mongodb ..." + mongod --dbpath "$dbpath" --port $mongo_port + echo -e "${BIGreen}>>>${RST} Detached to background." +} -echo -e "${BIGreen}>>>${RST} Running mongodb ..." -mongod --dbpath "$dbpath" --port $mongo_port -echo -e "${BIGreen}>>>${RST} Detached to background." diff --git a/tools/run_settings.sh b/tools/run_settings.sh index b8096e69ff..23a98cdd91 100755 --- a/tools/run_settings.sh +++ b/tools/run_settings.sh @@ -91,8 +91,9 @@ detect_python () { # None ############################################################################### clean_pyc () { - path=${1:-$pype_root} - echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" + local path + path=$pype_root + echo -e "${BIGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete echo -e "${BIGreen}DONE${RST}" } @@ -111,14 +112,18 @@ realpath () { } # Main -echo -e "${BGreen}" -art -echo -e "${RST}" -detect_python || return 1 +main () { + echo -e "${BGreen}" + art + echo -e "${RST}" + detect_python || return 1 -# Directories -pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) -pushd "$pype_root" > /dev/null || return > /dev/null + # Directories + pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) + pushd "$pype_root" > /dev/null || return > /dev/null -echo -e "${BIGreen}>>>${RST} Generating zip from current sources ..." -poetry run python3 "$pype_root/start.py" settings --dev + echo -e "${BIGreen}>>>${RST} Generating zip from current sources ..." + poetry run python3 "$pype_root/start.py" settings --dev +} + +main diff --git a/tools/run_tests.sh b/tools/run_tests.sh index 5ba5505919..81fa28b5f7 100755 --- a/tools/run_tests.sh +++ b/tools/run_tests.sh @@ -87,8 +87,9 @@ detect_python () { # None ############################################################################### clean_pyc () { - path=${1:-$pype_root} - echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" + local path + path=$pype_root + echo -e "${BIGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete echo -e "${BIGreen}DONE${RST}" } @@ -107,19 +108,22 @@ realpath () { } # Main -echo -e "${BGreen}" -art -echo -e "${RST}" -detect_python || return 1 +main () { + echo -e "${BGreen}" + art + echo -e "${RST}" + detect_python || return 1 -# Directories -pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) -pushd "$pype_root" || return > /dev/null + # Directories + pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) + pushd "$pype_root" || return > /dev/null + + echo -e "${BIGreen}>>>${RST} Testing Pype ..." + original_pythonpath=$PYTHONPATH + export PYTHONPATH="$pype_root:$PYTHONPATH" + poetry run pytest -x --capture=sys --print -W ignore::DeprecationWarning "$pype_root/tests" + PYTHONPATH=$original_pythonpath +} -echo -e "${BIGreen}>>>${RST} Testing Pype ..." -original_pythonpath=$PYTHONPATH -export PYTHONPATH="$pype_root:$PYTHONPATH" -poetry run pytest -x --capture=sys --print -W ignore::DeprecationWarning "$pype_root/tests" -PYTHONPATH=$original_pythonpath diff --git a/tools/run_tray.sh b/tools/run_tray.sh index 80af89acb2..3c63d0babe 100755 --- a/tools/run_tray.sh +++ b/tools/run_tray.sh @@ -91,8 +91,9 @@ detect_python () { # None ############################################################################### clean_pyc () { - path=${1:-$pype_root} - echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" + local path + path=$pype_root + echo -e "${BIGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete echo -e "${BIGreen}DONE${RST}" } @@ -111,14 +112,18 @@ realpath () { } # Main -echo -e "${BGreen}" -art -echo -e "${RST}" -detect_python || return 1 +main () { + echo -e "${BGreen}" + art + echo -e "${RST}" + detect_python || return 1 -# Directories -pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) -pushd "$pype_root" > /dev/null || return > /dev/null + # Directories + pype_root=$(realpath $(dirname $(dirname "${BASH_SOURCE[0]}"))) + pushd "$pype_root" > /dev/null || return > /dev/null -echo -e "${BIGreen}>>>${RST} Running Pype Tray with debug option ..." -poetry run python3 "$pype_root/start.py" tray --debug + echo -e "${BIGreen}>>>${RST} Running Pype Tray with debug option ..." + poetry run python3 "$pype_root/start.py" tray --debug +} + +main \ No newline at end of file diff --git a/tools/update_submodules.sh b/tools/update_submodules.sh index c0b98f2c5e..35d943dea5 100644 --- a/tools/update_submodules.sh +++ b/tools/update_submodules.sh @@ -51,61 +51,6 @@ BICyan='\033[1;96m' # Cyan BIWhite='\033[1;97m' # White -############################################################################## -# Detect required version of python -# Globals: -# colors -# PYTHON -# Arguments: -# None -# Returns: -# None -############################################################################### -detect_python () { - echo -e "${BIGreen}>>>${RST} Using python \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 "${BIWhite}[${RST} ${BIGreen}$1.$2${RST} ${BIWhite}]${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_root} - echo -e "${IGreen}>>>${RST} Cleaning pyc at [ ${BIWhite}$path${RST} ] ... \c" - find "$path" -regex '^.*\(__pycache__\|\.py[co]\)$' -delete - echo -e "${BIGreen}DONE${RST}" -} - -############################################################################## -# Return absolute path -# Globals: -# None -# Arguments: -# Path to resolve -# Returns: -# None -############################################################################### -realpath () { - echo $(cd $(dirname "$1"); pwd)/$(basename "$1") -} - # Main echo -e "${BGreen}" art