Created
March 27, 2019 20:19
-
-
Save stek29/f1f24c4def689628ff67fa30c4d83ab2 to your computer and use it in GitHub Desktop.
Fix Cellar versioned links in virtualenvs
This file contains 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 characters
#!/usr/bin/env bash | |
# Python virtualenvs contain references to base python | |
# For brew installed python they reference versioned Cellar | |
# Which breaks even on minor update | |
# This hacky script rewrites all those references to opt based, | |
# unversioned ones. | |
# | |
# Example usage: fixvenvopt.sh ~/.virtualenvs/jupyter | |
set -euo pipefail | |
noversion() { | |
# Yup, sed spawned on each invokation. I'm not proud of this either. | |
printf "%s" "$1" | sed 's#Cellar/python/[^/]*/#opt/python/#' | |
} | |
if [[ "$#" != 1 ]]; then | |
echo "Usage: $0 virtualenv_path" | |
exit 1 | |
fi | |
cd "$1" | |
for f in $(find . -type l); do | |
lnk="$(readlink "$f")" | |
if [[ $lnk = *Cellar* ]]; then | |
rm "$f" | |
ln -s "$(noversion $lnk)" "$f" | |
fi | |
done | |
orig_prefix_v="$(cat lib/python*/orig-prefix.txt)" | |
# tee is needed to force glob expansion | |
echo "$(noversion "$orig_prefix_v")" | tee lib/python*/orig-prefix.txt >/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment