81 lines
1.4 KiB
Bash
Executable File
81 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
set -euC
|
|
|
|
_venv() {
|
|
_py_version=${1:-3.12.0}
|
|
|
|
pyenv install $_py_version
|
|
pyenv shell $_py_version
|
|
|
|
if [ -d .venv ]; then
|
|
rm -rf .venv
|
|
fi
|
|
|
|
python -m venv ".venv"
|
|
}
|
|
VENV_match=venv
|
|
|
|
_init() {
|
|
if [ -d .venv ]; then
|
|
source .venv/bin/activate
|
|
pip install --upgrade pip
|
|
pip install -r requirements.txt
|
|
else
|
|
echo "Please run 'bin/configure venv' first"
|
|
fi
|
|
}
|
|
INIT_match=init
|
|
|
|
_freeze() {
|
|
if [ -d .venv ]; then
|
|
source .venv/bin/activate
|
|
mv requirements.txt requirements.txt.bak
|
|
pip freeze >requirements.txt
|
|
else
|
|
echo "Please run 'bin/configure init' first"
|
|
fi
|
|
}
|
|
FREEZE_match=freeze
|
|
|
|
_help() {
|
|
echo -e "Usage: $0 [help, -h | init {python_version} | venv {python_version} | freeze]\n"
|
|
echo " help, -h: Show this help message"
|
|
echo " init: Initialize virtual environment with {python_version} and install dependencies"
|
|
echo " venv: Create virtual environment with {python_version}"
|
|
echo " freeze: Freeze dependencies"
|
|
}
|
|
|
|
_check_cmds() {
|
|
if ! command -v pyenv >/dev/null; then
|
|
echo "Please install pyenv"
|
|
_fail=true
|
|
fi
|
|
}
|
|
|
|
_main() {
|
|
export _fail=false
|
|
_check_cmds
|
|
|
|
if $_fail; then
|
|
exit 1
|
|
fi
|
|
|
|
_cmd="${1:-help}"
|
|
if ! [ -z "$_cmd" ]; then
|
|
shift
|
|
fi
|
|
|
|
case "$_cmd" in
|
|
--*) ;;
|
|
help | -h) _help ;;
|
|
"$VENV_match") _venv "$@" ;;
|
|
"$INIT_match")
|
|
_venv "$@"
|
|
_init
|
|
;;
|
|
"$FREEZE_match") _freeze ;;
|
|
esac
|
|
}
|
|
|
|
_main "$@"
|