From 6a5500797ddec4aee89297b7b4e3e2bb91595fe8 Mon Sep 17 00:00:00 2001 From: Mark Bailey Date: Sat, 26 Oct 2024 19:39:07 -0400 Subject: [PATCH] feat: include bin/ --- .gitignore | 1 - bin/configure | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 bin/configure diff --git a/.gitignore b/.gitignore index 41ad793..f412fb8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ __pycache__/ data/ r.http *.bak -!bin/configure diff --git a/bin/configure b/bin/configure new file mode 100755 index 0000000..31422e3 --- /dev/null +++ b/bin/configure @@ -0,0 +1,79 @@ +#!/bin/sh +set -euC + +_venv() { + _py_version=${1:-3.12.0} + + if command -v pyenv >/dev/null 2>&1; then + pyenv install $_py_version + pyenv shell $_py_version + if [ -d .venv ]; then + rm -rf .venv + fi + python -m venv ".venv" + else + echo "Please install pyenv" + fi +} +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 2>&1; then + echo "Please install pyenv" + _fail=true + fi +} + +_main() { + _fail=false + _check_cmds + + if $_fail; then + exit 1 + fi + + _cmd="${1:-help}" + + case "$_cmd" in + --*) ;; + help | -h) _help ;; + "$VENV_match") _venv "${2:-}" ;; + "$INIT_match") + _venv "${2:-}" + _init + ;; + "$FREEZE_match") _freeze ;; + esac +} + +_main "$@"