scripts : switch to PascalCase for functions
This looks a little odd at first, but I find it very useful as a convention to know if a command is part of our code vs a builtin.
This commit is contained in:
parent
04fee216d3
commit
a34648d35e
4 changed files with 58 additions and 57 deletions
|
@ -33,9 +33,9 @@ source 'lib.sh'
|
||||||
# finally imports the python script to check for `ImportError`.
|
# finally imports the python script to check for `ImportError`.
|
||||||
#
|
#
|
||||||
|
|
||||||
cleanup() {
|
Cleanup() {
|
||||||
if _isset workdir && [[ -d $workdir && -w $workdir ]]; then
|
if _IsSet workdir && [[ -d $workdir && -w $workdir ]]; then
|
||||||
_log_info "Removing $workdir"
|
_LogInfo "Removing $workdir"
|
||||||
local count=0
|
local count=0
|
||||||
rm -rfv -- "$workdir" | while read -r; do
|
rm -rfv -- "$workdir" | while read -r; do
|
||||||
if (( count++ > 750 )); then
|
if (( count++ > 750 )); then
|
||||||
|
@ -44,7 +44,7 @@ cleanup() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf '\n'
|
printf '\n'
|
||||||
_log_info "Removed $workdir"
|
_LogInfo "Removed $workdir"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ fi
|
||||||
|
|
||||||
if (( do_cleanup )); then
|
if (( do_cleanup )); then
|
||||||
trap exit INT TERM
|
trap exit INT TERM
|
||||||
trap cleanup EXIT
|
trap Cleanup EXIT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd .. # PWD should be llama.cpp project directory
|
cd .. # PWD should be llama.cpp project directory
|
||||||
|
@ -65,33 +65,33 @@ readonly reqs_dir=requirements
|
||||||
if [[ ${1+x} ]]; then
|
if [[ ${1+x} ]]; then
|
||||||
tmp_dir=$(realpath -- "$1")
|
tmp_dir=$(realpath -- "$1")
|
||||||
if [[ ! ( -d $tmp_dir && -w $tmp_dir ) ]]; then
|
if [[ ! ( -d $tmp_dir && -w $tmp_dir ) ]]; then
|
||||||
_log_fatal "$tmp_dir is not a writable directory"
|
_LogFatal "$tmp_dir is not a writable directory"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
tmp_dir=/tmp
|
tmp_dir=/tmp
|
||||||
fi
|
fi
|
||||||
|
|
||||||
workdir=$(mktemp -d "$tmp_dir/check-requirements.XXXX"); readonly workdir
|
workdir=$(mktemp -d "$tmp_dir/check-requirements.XXXX"); readonly workdir
|
||||||
_log_info "Working directory: $workdir"
|
_LogInfo "Working directory: $workdir"
|
||||||
|
|
||||||
check_requirements() {
|
CheckRequirements() {
|
||||||
local reqs=$1
|
local reqs=$1
|
||||||
|
|
||||||
_log_info "$reqs: beginning check"
|
_LogInfo "$reqs: beginning check"
|
||||||
pip --disable-pip-version-check install -qr "$reqs"
|
pip --disable-pip-version-check install -qr "$reqs"
|
||||||
_log_info "$reqs: OK"
|
_LogInfo "$reqs: OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_convert_script() {
|
CheckConvertScript() {
|
||||||
local py=$1 # e.g. ./convert-hf-to-gguf.py
|
local py=$1 # e.g. ./convert-hf-to-gguf.py
|
||||||
local pyname=${py##*/} # e.g. convert-hf-to-gguf.py
|
local pyname=${py##*/} # e.g. convert-hf-to-gguf.py
|
||||||
pyname=${pyname%.py} # e.g. convert-hf-to-gguf
|
pyname=${pyname%.py} # e.g. convert-hf-to-gguf
|
||||||
|
|
||||||
_log_info "$py: beginning check"
|
_LogInfo "$py: beginning check"
|
||||||
|
|
||||||
local reqs="$reqs_dir/requirements-$pyname.txt"
|
local reqs="$reqs_dir/requirements-$pyname.txt"
|
||||||
if [[ ! -r $reqs ]]; then
|
if [[ ! -r $reqs ]]; then
|
||||||
_log_fatal "$py missing requirements. Expected: $reqs"
|
_LogFatal "$py missing requirements. Expected: $reqs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local venv="$workdir/$pyname-venv"
|
local venv="$workdir/$pyname-venv"
|
||||||
|
@ -101,7 +101,7 @@ check_convert_script() {
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source "$venv/bin/activate"
|
source "$venv/bin/activate"
|
||||||
|
|
||||||
check_requirements "$reqs"
|
CheckRequirements "$reqs"
|
||||||
|
|
||||||
python - "$py" "$pyname" <<'EOF'
|
python - "$py" "$pyname" <<'EOF'
|
||||||
import sys
|
import sys
|
||||||
|
@ -115,7 +115,7 @@ EOF
|
||||||
rm -rf -- "$venv"
|
rm -rf -- "$venv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_log_info "$py: imports OK"
|
_LogInfo "$py: imports OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly ignore_eq_eq='check_requirements: ignore "=="'
|
readonly ignore_eq_eq='check_requirements: ignore "=="'
|
||||||
|
@ -123,7 +123,7 @@ readonly ignore_eq_eq='check_requirements: ignore "=="'
|
||||||
for req in "$reqs_dir"/*; do
|
for req in "$reqs_dir"/*; do
|
||||||
# Check that all sub-requirements are added to top-level requirements.txt
|
# Check that all sub-requirements are added to top-level requirements.txt
|
||||||
if ! grep -qF "$req" requirements.txt; then
|
if ! grep -qF "$req" requirements.txt; then
|
||||||
_log_fatal "$req needs to be added to requirements.txt"
|
_LogFatal "$req needs to be added to requirements.txt"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make sure exact release versions aren't being pinned in the requirements
|
# Make sure exact release versions aren't being pinned in the requirements
|
||||||
|
@ -145,16 +145,16 @@ python3 -m venv "$all_venv"
|
||||||
(
|
(
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source "$all_venv/bin/activate"
|
source "$all_venv/bin/activate"
|
||||||
check_requirements requirements.txt
|
CheckRequirements requirements.txt
|
||||||
)
|
)
|
||||||
|
|
||||||
if (( do_cleanup )); then
|
if (( do_cleanup )); then
|
||||||
rm -rf -- "$all_venv"
|
rm -rf -- "$all_venv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
check_convert_script convert.py
|
CheckConvertScript convert.py
|
||||||
for py in convert-*.py; do
|
for py in convert-*.py; do
|
||||||
check_convert_script "$py"
|
CheckConvertScript "$py"
|
||||||
done
|
done
|
||||||
|
|
||||||
_log_info 'Done! No issues found.'
|
_LogInfo 'Done! No issues found.'
|
||||||
|
|
|
@ -11,7 +11,7 @@ source 'lib.sh'
|
||||||
# TODO: send model to ctest_model tests using env variable
|
# TODO: send model to ctest_model tests using env variable
|
||||||
# GG_TEST_CTEST_MODEL_MODELFILE=<snip>
|
# GG_TEST_CTEST_MODEL_MODELFILE=<snip>
|
||||||
|
|
||||||
is_valid_test_target() {
|
IsValidTestTarget() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
cmake | ctest_main | model_3b | model_7b | test_cpu | test_cuda | test_metal | ctest_model)
|
cmake | ctest_main | model_3b | model_7b | test_cpu | test_cuda | test_metal | ctest_model)
|
||||||
return 0;;
|
return 0;;
|
||||||
|
@ -23,7 +23,7 @@ is_valid_test_target() {
|
||||||
declare -a test_targets
|
declare -a test_targets
|
||||||
if (( $# > 0 )); then
|
if (( $# > 0 )); then
|
||||||
test_targets=("$@")
|
test_targets=("$@")
|
||||||
elif _isset GG_TEST_TARGETS; then
|
elif _IsSet GG_TEST_TARGETS; then
|
||||||
read -r -a test_targets <<< "$GG_TEST_TARGETS"
|
read -r -a test_targets <<< "$GG_TEST_TARGETS"
|
||||||
else
|
else
|
||||||
cat >&2 <<'EOF'
|
cat >&2 <<'EOF'
|
||||||
|
@ -54,6 +54,7 @@ test targets:
|
||||||
test_cuda : test CUDA ...
|
test_cuda : test CUDA ...
|
||||||
(requires: model_3b or model_7b)
|
(requires: model_3b or model_7b)
|
||||||
test_metal : test Metal ...
|
test_metal : test Metal ...
|
||||||
|
(requires: model_3b or model_7b)
|
||||||
ctest_model : run ctest tests that require the openllama model
|
ctest_model : run ctest tests that require the openllama model
|
||||||
(requires: model_3b or model_7b)
|
(requires: model_3b or model_7b)
|
||||||
EOF
|
EOF
|
||||||
|
@ -61,9 +62,9 @@ EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for target in "${test_targets[@]}"; do
|
for target in "${test_targets[@]}"; do
|
||||||
if is_valid_test_target "$target"; then
|
if IsValidTestTarget "$target"; then
|
||||||
_log_info "Received test target: $target"
|
_LogInfo "Received test target: $target"
|
||||||
else
|
else
|
||||||
_log_fatal "Invalid test target: $target"
|
_LogFatal "Invalid test target: $target"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
@ -5,26 +5,26 @@ if [[ ${BASH_SOURCE[0]} -ef $0 ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_log() {
|
_Log() {
|
||||||
local level=$1 msg=$2
|
local level=$1 msg=$2
|
||||||
printf >&2 '%s: %s\n' "$level" "$msg"
|
printf >&2 '%s: %s\n' "$level" "$msg"
|
||||||
}
|
}
|
||||||
|
|
||||||
_log_debug() {
|
_LogDebug() {
|
||||||
_log DEBUG "$@"
|
_Log DEBUG "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_log_info() {
|
_LogInfo() {
|
||||||
_log INFO "$@"
|
_Log INFO "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_log_fatal() {
|
_LogFatal() {
|
||||||
_log FATAL "$@"
|
_Log FATAL "$@"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return true if the variable with name $1 is set
|
# Return true if the variable with name $1 is set
|
||||||
_isset() {
|
_IsSet() {
|
||||||
(( $# != 1 )) && return false
|
(( $# != 1 )) && return false
|
||||||
if [[ -n ${!1+x} ]]; then
|
if [[ -n ${!1+x} ]]; then
|
||||||
return 0
|
return 0
|
||||||
|
@ -33,6 +33,6 @@ _isset() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_isnotset() {
|
_IsNotSet() {
|
||||||
! _isset "$@"
|
! _IsSet "$@"
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,38 +12,38 @@ shellcheck --external-sources "$this"
|
||||||
source 'lib.sh'
|
source 'lib.sh'
|
||||||
#### END SETUP ####
|
#### END SETUP ####
|
||||||
|
|
||||||
pass() {
|
Pass() {
|
||||||
local test_func="${FUNCNAME[1]}"
|
local test_func="${FUNCNAME[1]}"
|
||||||
_log 'PASSED' "$test_func"
|
_Log 'PASSED' "$test_func"
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
Fail() {
|
||||||
local test_func="${FUNCNAME[1]}"
|
local test_func="${FUNCNAME[1]}"
|
||||||
_log 'FAILED' "$test_func: $1"
|
_Log 'FAILED' "$test_func: $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_lib_sh_execution() {
|
TestLibShExecution() {
|
||||||
if bash lib.sh 2>/dev/null; then
|
if bash lib.sh 2>/dev/null; then
|
||||||
fail 'lib.sh should fail execution, but did not'
|
Fail 'lib.sh should fail execution, but did not'
|
||||||
else pass; fi
|
else Pass; fi
|
||||||
}; test_lib_sh_execution
|
}; TestLibShExecution
|
||||||
|
|
||||||
test_isset() {
|
TestIsSet() {
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local foo=1
|
local foo=1
|
||||||
if ! _isset 'foo'; then
|
if ! _IsSet 'foo'; then
|
||||||
fail 'foo was not detecting as set'
|
Fail 'foo was not detecting as set'
|
||||||
elif _isset 'bar'; then
|
elif _IsSet 'bar'; then
|
||||||
fail 'bar was detected as set'
|
Fail 'bar was detected as set'
|
||||||
else pass; fi
|
else Pass; fi
|
||||||
}; test_isset
|
}; TestIsSet
|
||||||
|
|
||||||
test_isnotset() {
|
TestIsNotSet() {
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local foo=1
|
local foo=1
|
||||||
if _isnotset 'foo'; then
|
if _IsNotSet 'foo'; then
|
||||||
fail 'foo was detected as not set'
|
Fail 'foo was detected as not set'
|
||||||
elif ! _isnotset 'bar'; then
|
elif ! _IsNotSet 'bar'; then
|
||||||
fail 'bar was detected as set'
|
Fail 'bar was detected as set'
|
||||||
else pass; fi
|
else Pass; fi
|
||||||
}; test_isnotset
|
}; TestIsNotSet
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue