<commit_before>MY_VIRTUALENV_NAMES=${MY_VIRTUALENV_NAMES:-.venv}

function find_dir_in_parents() {
    local needle=$1
    test -z "$needle" && return
    local look=$( readlink --canonicalize ${2:-.} )
    local old_look
    while [ "$look" != "$old_look" ]
    do
        old_look=$look
        look=$( dirname "$look" )
        local candidate=$old_look/${needle#$old_look/}
        test -d "$candidate" && echo $candidate && break
    done
}

function switch_virtualenvs() {
    local new="$( readlink --canonicalize "$1/bin/activate" )"
    test -x "$new" || return
    [ -n "${VIRTUAL_ENV+virtualenv active}" ] && deactivate
    source "$new"
}

function detect_virtualenv() {
    local dirs=${1:-$MY_VIRTUALENV_NAMES}
    local -a venvs<commit_msg>when needle is abs path, only look for it in its immediate parent<commit_after>MY_VIRTUALENV_NAMES=${MY_VIRTUALENV_NAMES:-.venv}

function find_dir_in_parents() {
    local needle=$1
    test -z "$needle" && return
    local look=$( readlink --canonicalize ${2:-.} )
    local old_look
    local only_in=$( dirname "$needle" )
    while [ "$look" != "$old_look" ]
    do
        old_look=$look
        look=$( dirname "$look" )
        test "$( readlink --canonicalize $only_in )" != "$old_look" && continue
        local candidate=$old_look/${needle#$old_look/}
        test -d "$candidate" && echo $candidate && break
    done
}

function switch_virtualenvs() {
    local new="$( readlink --canonicalize "$1/bin/activate" )"
    test -x "$new" || return
    [ -n "${VIRTUAL_ENV+virtualenv active}" ] && deactivate
    source "$new"
}

function detect_virtualenv() {
    local dirs=${1:-$MY_VIRTUALENV_NAMES}
    local -a venvs
{'fraction_non_alphanumeric': 0.15508021390374332, 'fraction_numerical': 0.004753416518122401, 'mean_word_length': 3.21, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1821938', 'n_tokens_mistral': 583, 'n_tokens_neox': 565, 'n_words': 135}