Skip to content

Commit 6562b0c

Browse files
committed
feat: Enhance virtual environment setup to handle paths with ':' and use a safe cache directory
1 parent 0f8f886 commit 6562b0c

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

run.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,27 @@
55
set -euo pipefail
66

77
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8-
VENV_DIR="$SCRIPT_DIR/.venv"
8+
9+
# Allow override from env, otherwise default to project-local .venv
10+
DEFAULT_VENV_DIR="$SCRIPT_DIR/.venv"
11+
VENV_DIR="${VENV_DIR:-$DEFAULT_VENV_DIR}"
12+
13+
# If the project path contains ':' (GVFS sftp:host=...), venv creation will fail.
14+
# In that case, place venv in a local cache directory with a safe path.
15+
if [[ "$SCRIPT_DIR" == *:* ]]; then
16+
SAFE_BASE="${XDG_CACHE_HOME:-$HOME/.cache}/venvs"
17+
mkdir -p "$SAFE_BASE"
18+
19+
# Use a stable name; add a short hash to avoid collisions across different paths.
20+
if command -v sha1sum >/dev/null 2>&1; then
21+
PATH_HASH="$(printf "%s" "$SCRIPT_DIR" | sha1sum | awk '{print substr($1,1,10)}')"
22+
else
23+
PATH_HASH="nohash"
24+
fi
25+
26+
VENV_DIR="$SAFE_BASE/$(basename "$SCRIPT_DIR")-$PATH_HASH"
27+
echo "⚠️ Detected ':' in path ($SCRIPT_DIR). Using venv at: $VENV_DIR"
28+
fi
929

1030
# 1) Create venv if it doesn't exist
1131
if [ ! -d "$VENV_DIR" ]; then
@@ -21,3 +41,4 @@ echo "📦 Installing dependencies…"
2141
# 3) Run the exporter, forwarding all CLI arguments
2242
echo "🚀 Starting exporter…"
2343
"$VENV_DIR/bin/python" "$SCRIPT_DIR/binance_ohlcv_exporter.py" "$@"
44+

0 commit comments

Comments
 (0)