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`.
|
||||
#
|
||||
|
||||
cleanup() {
|
||||
if _isset workdir && [[ -d $workdir && -w $workdir ]]; then
|
||||
_log_info "Removing $workdir"
|
||||
Cleanup() {
|
||||
if _IsSet workdir && [[ -d $workdir && -w $workdir ]]; then
|
||||
_LogInfo "Removing $workdir"
|
||||
local count=0
|
||||
rm -rfv -- "$workdir" | while read -r; do
|
||||
if (( count++ > 750 )); then
|
||||
|
@ -44,7 +44,7 @@ cleanup() {
|
|||
fi
|
||||
done
|
||||
printf '\n'
|
||||
_log_info "Removed $workdir"
|
||||
_LogInfo "Removed $workdir"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ fi
|
|||
|
||||
if (( do_cleanup )); then
|
||||
trap exit INT TERM
|
||||
trap cleanup EXIT
|
||||
trap Cleanup EXIT
|
||||
fi
|
||||
|
||||
cd .. # PWD should be llama.cpp project directory
|
||||
|
@ -65,33 +65,33 @@ readonly reqs_dir=requirements
|
|||
if [[ ${1+x} ]]; then
|
||||
tmp_dir=$(realpath -- "$1")
|
||||
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
|
||||
else
|
||||
tmp_dir=/tmp
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
_log_info "$reqs: beginning check"
|
||||
_LogInfo "$reqs: beginning check"
|
||||
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 pyname=${py##*/} # e.g. convert-hf-to-gguf.py
|
||||
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"
|
||||
if [[ ! -r $reqs ]]; then
|
||||
_log_fatal "$py missing requirements. Expected: $reqs"
|
||||
_LogFatal "$py missing requirements. Expected: $reqs"
|
||||
fi
|
||||
|
||||
local venv="$workdir/$pyname-venv"
|
||||
|
@ -101,7 +101,7 @@ check_convert_script() {
|
|||
# shellcheck source=/dev/null
|
||||
source "$venv/bin/activate"
|
||||
|
||||
check_requirements "$reqs"
|
||||
CheckRequirements "$reqs"
|
||||
|
||||
python - "$py" "$pyname" <<'EOF'
|
||||
import sys
|
||||
|
@ -115,7 +115,7 @@ EOF
|
|||
rm -rf -- "$venv"
|
||||
fi
|
||||
|
||||
_log_info "$py: imports OK"
|
||||
_LogInfo "$py: imports OK"
|
||||
}
|
||||
|
||||
readonly ignore_eq_eq='check_requirements: ignore "=="'
|
||||
|
@ -123,7 +123,7 @@ readonly ignore_eq_eq='check_requirements: ignore "=="'
|
|||
for req in "$reqs_dir"/*; do
|
||||
# Check that all sub-requirements are added to top-level requirements.txt
|
||||
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
|
||||
|
||||
# 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
|
||||
source "$all_venv/bin/activate"
|
||||
check_requirements requirements.txt
|
||||
CheckRequirements requirements.txt
|
||||
)
|
||||
|
||||
if (( do_cleanup )); then
|
||||
rm -rf -- "$all_venv"
|
||||
fi
|
||||
|
||||
check_convert_script convert.py
|
||||
CheckConvertScript convert.py
|
||||
for py in convert-*.py; do
|
||||
check_convert_script "$py"
|
||||
CheckConvertScript "$py"
|
||||
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
|
||||
# GG_TEST_CTEST_MODEL_MODELFILE=<snip>
|
||||
|
||||
is_valid_test_target() {
|
||||
IsValidTestTarget() {
|
||||
case "$1" in
|
||||
cmake | ctest_main | model_3b | model_7b | test_cpu | test_cuda | test_metal | ctest_model)
|
||||
return 0;;
|
||||
|
@ -23,7 +23,7 @@ is_valid_test_target() {
|
|||
declare -a test_targets
|
||||
if (( $# > 0 )); then
|
||||
test_targets=("$@")
|
||||
elif _isset GG_TEST_TARGETS; then
|
||||
elif _IsSet GG_TEST_TARGETS; then
|
||||
read -r -a test_targets <<< "$GG_TEST_TARGETS"
|
||||
else
|
||||
cat >&2 <<'EOF'
|
||||
|
@ -54,6 +54,7 @@ test targets:
|
|||
test_cuda : test CUDA ...
|
||||
(requires: model_3b or model_7b)
|
||||
test_metal : test Metal ...
|
||||
(requires: model_3b or model_7b)
|
||||
ctest_model : run ctest tests that require the openllama model
|
||||
(requires: model_3b or model_7b)
|
||||
EOF
|
||||
|
@ -61,9 +62,9 @@ EOF
|
|||
fi
|
||||
|
||||
for target in "${test_targets[@]}"; do
|
||||
if is_valid_test_target "$target"; then
|
||||
_log_info "Received test target: $target"
|
||||
if IsValidTestTarget "$target"; then
|
||||
_LogInfo "Received test target: $target"
|
||||
else
|
||||
_log_fatal "Invalid test target: $target"
|
||||
_LogFatal "Invalid test target: $target"
|
||||
fi
|
||||
done
|
||||
|
|
|
@ -5,26 +5,26 @@ if [[ ${BASH_SOURCE[0]} -ef $0 ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
_log() {
|
||||
_Log() {
|
||||
local level=$1 msg=$2
|
||||
printf >&2 '%s: %s\n' "$level" "$msg"
|
||||
}
|
||||
|
||||
_log_debug() {
|
||||
_log DEBUG "$@"
|
||||
_LogDebug() {
|
||||
_Log DEBUG "$@"
|
||||
}
|
||||
|
||||
_log_info() {
|
||||
_log INFO "$@"
|
||||
_LogInfo() {
|
||||
_Log INFO "$@"
|
||||
}
|
||||
|
||||
_log_fatal() {
|
||||
_log FATAL "$@"
|
||||
_LogFatal() {
|
||||
_Log FATAL "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Return true if the variable with name $1 is set
|
||||
_isset() {
|
||||
_IsSet() {
|
||||
(( $# != 1 )) && return false
|
||||
if [[ -n ${!1+x} ]]; then
|
||||
return 0
|
||||
|
@ -33,6 +33,6 @@ _isset() {
|
|||
fi
|
||||
}
|
||||
|
||||
_isnotset() {
|
||||
! _isset "$@"
|
||||
_IsNotSet() {
|
||||
! _IsSet "$@"
|
||||
}
|
||||
|
|
|
@ -12,38 +12,38 @@ shellcheck --external-sources "$this"
|
|||
source 'lib.sh'
|
||||
#### END SETUP ####
|
||||
|
||||
pass() {
|
||||
Pass() {
|
||||
local test_func="${FUNCNAME[1]}"
|
||||
_log 'PASSED' "$test_func"
|
||||
_Log 'PASSED' "$test_func"
|
||||
}
|
||||
|
||||
fail() {
|
||||
Fail() {
|
||||
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
|
||||
fail 'lib.sh should fail execution, but did not'
|
||||
else pass; fi
|
||||
}; test_lib_sh_execution
|
||||
Fail 'lib.sh should fail execution, but did not'
|
||||
else Pass; fi
|
||||
}; TestLibShExecution
|
||||
|
||||
test_isset() {
|
||||
TestIsSet() {
|
||||
# shellcheck disable=SC2034
|
||||
local foo=1
|
||||
if ! _isset 'foo'; then
|
||||
fail 'foo was not detecting as set'
|
||||
elif _isset 'bar'; then
|
||||
fail 'bar was detected as set'
|
||||
else pass; fi
|
||||
}; test_isset
|
||||
if ! _IsSet 'foo'; then
|
||||
Fail 'foo was not detecting as set'
|
||||
elif _IsSet 'bar'; then
|
||||
Fail 'bar was detected as set'
|
||||
else Pass; fi
|
||||
}; TestIsSet
|
||||
|
||||
test_isnotset() {
|
||||
TestIsNotSet() {
|
||||
# shellcheck disable=SC2034
|
||||
local foo=1
|
||||
if _isnotset 'foo'; then
|
||||
fail 'foo was detected as not set'
|
||||
elif ! _isnotset 'bar'; then
|
||||
fail 'bar was detected as set'
|
||||
else pass; fi
|
||||
}; test_isnotset
|
||||
if _IsNotSet 'foo'; then
|
||||
Fail 'foo was detected as not set'
|
||||
elif ! _IsNotSet 'bar'; then
|
||||
Fail 'bar was detected as set'
|
||||
else Pass; fi
|
||||
}; TestIsNotSet
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue