Last active
January 30, 2025 14:48
-
-
Save mccutchen/e9c0ba406d4b89147b97c2329d65d740 to your computer and use it in GitHub Desktop.
Revisions
-
mccutchen revised this gist
Jan 30, 2025 . 1 changed file with 15 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,30 @@ #!/bin/bash set -euo pipefail VIRTUAL_ENV=".venv" REQUIREMENTS_HASH_FILE="$VIRTUAL_ENV/requirements.shasum" REQUIREMENTS_HASH_FUNC="shasum" REQUIREMENTS_HASH_VAL=$($REQUIREMENTS_HASH_FUNC requirements.txt | cut -d ' ' -f 1) function reset_venv() { if ! has uv; then echo 'error: `uv` command not found. install with `brew install uv`' exit 1 fi rm -rf "$VIRTUAL_ENV" uv venv uv pip install -r requirements.txt printf '%s' "$REQUIREMENTS_HASH_VAL" >"$REQUIREMENTS_HASH_FILE" } if [ ! -f "$REQUIREMENTS_HASH_FILE" ]; then echo "setting up new python virtualenv in $VIRTUAL_ENV ..." reset_venv elif [ "$(cat $REQUIREMENTS_HASH_FILE)" != "$REQUIREMENTS_HASH_VAL" ]; then echo "python requirements changed, rebuilding virtualenv in $VIRTUAL_ENV ..." echo "(found hash $(cat $REQUIREMENTS_HASH_FILE), want hash $REQUIREMENTS_HASH_VAL)" reset_venv fi PATH_add "$VIRTUAL_ENV/bin" -
mccutchen created this gist
Nov 3, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ #!/bin/bash VENV_DIR=".venv" REQUIREMENTS_HASH_FILE="$VENV_DIR/requirements.shasum" REQUIREMENTS_HASH_FUNC="shasum" REQUIREMENTS_HASH_VAL=$($REQUIREMENTS_HASH_FUNC requirements.txt | cut -d ' ' -f 1) function reset_venv() { rm -rf "$VENV_DIR" python3 -m venv "$VENV_DIR" "$VENV_DIR/bin/pip" install -r "requirements.txt" echo -n "$REQUIREMENTS_HASH_VAL" > "$REQUIREMENTS_HASH_FILE" } if [ ! -f "$REQUIREMENTS_HASH_FILE" ]; then echo "setting up new python virtualenv ..." reset_venv elif [ "$(cat $REQUIREMENTS_HASH_FILE)" != "$REQUIREMENTS_HASH_VAL" ]; then echo "python requirements changed, rebuilding virtualenv ..." echo "(found hash $(cat $REQUIREMENTS_HASH_FILE), want hash $REQUIREMENTS_HASH_VAL)" reset_venv fi PATH_add "$VENV_DIR/bin"