File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Get absolute path of the current directory
4+ VENV_DIR=" ./py313-mac"
5+ NEW_VENV_PATH=" $( cd " $VENV_DIR " && pwd) "
6+ PYTHON_BIN=" $NEW_VENV_PATH /bin/python3"
7+
8+ echo " 🔧 Updating venv paths to: $NEW_VENV_PATH "
9+
10+ # 1. Patch pyvenv.cfg
11+ if [ -f " $VENV_DIR /pyvenv.cfg" ]; then
12+ echo " ✅ Patching pyvenv.cfg"
13+ sed -i ' ' " s|^home = .*|home = $NEW_VENV_PATH /bin/python3|" " $VENV_DIR /pyvenv.cfg"
14+ fi
15+
16+ # 2. Patch activate scripts
17+ for f in " $VENV_DIR " /bin/activate* ; do
18+ if [[ -f " $f " ]]; then
19+ echo " ✅ Patching $f "
20+ sed -i ' ' " s|^VIRTUAL_ENV=.*|VIRTUAL_ENV=\" $NEW_VENV_PATH \" |" " $f "
21+ fi
22+ done
23+
24+ # 3. Patch shebangs in bin scripts (e.g., pip, flask)
25+ echo " ✅ Patching shebangs in venv/bin/*"
26+ for f in " $VENV_DIR " /bin/* ; do
27+ if head -1 " $f " | grep -q " ^#\!.*python" ; then
28+ sed -i ' ' " 1 s|^#!.*python.*|#!$PYTHON_BIN |" " $f "
29+ fi
30+ done
31+
32+ # 4. Optional: clean .pyc files (they sometimes cache paths)
33+ echo " 🧹 Deleting stale .pyc files"
34+ find " $VENV_DIR " -name " *.pyc" -delete
35+
36+ echo " 🎉 Done. Your venv is now patched for: $NEW_VENV_PATH "
You can’t perform that action at this time.
0 commit comments