<commit_before>#!/usr/bin/env bash
#set -x

ORIG_PREFIX_FILE="lib/python2.7/orig-prefix.txt"
ORIG_PREFIX=$(cat ${ORIG_PREFIX_FILE})

#OLD_VERSION=$(echo $ORIG_PREFIX | awk -F/ '{ print $6 }')
#PY_VERSION="$(/usr/local/bin/python -c 'import sys; print sys.version.split(" ")[0]')_2"
#PY_VERSION=$(basename $(greadlink -f `brew --prefix python`))
#NEW_PREFIX=$(echo $ORIG_PREFIX | sed "s#${OLD_VERSION}#${PY_VERSION}#g")

NEW_PREFIX=$(/usr/local/bin/python -c 'import sys; print sys.prefix')

echo "OLD PREFIX: ${ORIG_PREFIX}"
echo "NEW PREFIX: ${NEW_PREFIX}"

if [[ $ORIG_PREFIX == $NEW_PREFIX ]]; then
    echo "- Prefixes are the same, not relinking"
    exit 127
fi

function relink () {
    file=$1
    dir=`dirname $file`
    bs=`basename $file`
    printf "\tTarget: \t${file}\n"
    if [ ! -e `readlink -n $file` ]; then
        [[ $dir = "." ]] && newfile="${NEW_PREFIX}/$(echo $bs | sed 's#.##')" || newfile="${NEW_PREFIX}/$(echo $dir | sed 's#./##')/${bs}"
        printf "\tSource: \t${newfile}\n"
        if [ -e $newfile ]; then
            rm $file && ln -s $newfile $file
        fi
    fi
}

cd $VIRTUAL_ENV

bad_links=$(/usr/local/bin/gfind . -type l -exec test ! -e {} \; -print)
how_bad=${#bad_links[@]}

echo "+ Relinking ${how_bad} bad links:"
for bad_link in $bad_links; do
    echo $bad_link
done

echo ""
for bad_link in $bad_links; do
    relink $bad_link
    echo ""
done

echo $NEW_PREFIX > $ORIG_PREFIX_FILE<commit_msg>Mangled function name to '__relink__'<commit_after>#!/usr/bin/env bash
#set -x

ORIG_PREFIX_FILE="lib/python2.7/orig-prefix.txt"
ORIG_PREFIX=$(cat ${ORIG_PREFIX_FILE})

#OLD_VERSION=$(echo $ORIG_PREFIX | awk -F/ '{ print $6 }')
#PY_VERSION="$(/usr/local/bin/python -c 'import sys; print sys.version.split(" ")[0]')_2"
#PY_VERSION=$(basename $(greadlink -f `brew --prefix python`))
#NEW_PREFIX=$(echo $ORIG_PREFIX | sed "s#${OLD_VERSION}#${PY_VERSION}#g")

NEW_PREFIX=$(/usr/local/bin/python -c 'import sys; print sys.prefix')

echo "OLD PREFIX: ${ORIG_PREFIX}"
echo "NEW PREFIX: ${NEW_PREFIX}"

if [[ $ORIG_PREFIX == $NEW_PREFIX ]]; then
    echo "- Prefixes are the same, not relinking"
    exit 127
fi

function __relink__ () {
    file=$1
    dir=`dirname $file`
    bs=`basename $file`
    printf "\tTarget: \t${file}\n"
    if [ ! -e `readlink -n $file` ]; then
        [[ $dir = "." ]] && newfile="${NEW_PREFIX}/$(echo $bs | sed 's#.##')" || newfile="${NEW_PREFIX}/$(echo $dir | sed 's#./##')/${bs}"
        printf "\tSource: \t${newfile}\n"
        if [ -e $newfile ]; then
            rm $file && ln -s $newfile $file
        fi
    fi
}

cd $VIRTUAL_ENV

bad_links=$(/usr/local/bin/gfind . -type l -exec test ! -e {} \; -print)
how_bad=${#bad_links[@]}

echo "+ Relinking ${how_bad} bad links:"
for bad_link in $bad_links; do
    echo $bad_link
done

echo ""
for bad_link in $bad_links; do
    __relink__ $bad_link
    echo ""
done

echo $NEW_PREFIX > $ORIG_PREFIX_FILE
{'fraction_non_alphanumeric': 0.19493844049247605, 'fraction_numerical': 0.006155950752393981, 'mean_word_length': 3.5348837209302326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '659299', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1112, 'n_words': 271}