<commit_before>#!/usr/bin/env bash
# YAPF + Clang formatter (if installed). This script formats all changed files from the last mergebase.
# You are encouraged to run this locally before pushing changes for review.

# Cause the script to exit if a single command fails
set -eo pipefail

ver=$(yapf --version)
if ! echo $ver | grep -q 0.23.0; then
    echo "Wrong YAPF version installed: 0.23.0 is required, not $ver"
    exit 1
fi

# this stops git rev-parse from failing if we run this from the .git directory
builtin cd "$(dirname "${BASH_SOURCE:-$0}")"

ROOT="$(git rev-parse --show-toplevel)"
builtin cd "$ROOT" || exit 1

# Add the upstream remote if it doesn't exist
if ! git remote -v | grep -q upstream; then
    git remote add 'upstream' 'https://github.com/ray-project/ray.git'
fi

FLAKE8_VERSION=$(flake8 --version | awk '{print $1}')
YAPF_VERSION=$(yapf --version | awk '{print $2}')

# params: tool name, tool version, required version
tool_version_check() {
    if [[ $2 != $3 ]]; then
        echo "WARNING: Ray uses $1 $3, You currently are using $2. This might generate different results."
    fi
}

tool_version_check "flake8" $FLAKE8_VERSION "3.7.7"
tool_version_check "yapf" $YAPF_VERSION "0.23.0"

if which clang-format >/dev/null; then
  CLANG_FORMAT_VERSION=$(clang-format --version | awk '{print $3}')
  tool_version_check "clang-format" $CLANG_FORMAT_VERSION "7.0.0"
else
    echo "WARNING: clang-format is not installed!"
fi

# Only fetch master since that's the branch we're diffing against.
git fetch upstream master || true

YAPF_FLAGS=(
    '--style' "$ROOT/.style.yapf"
    '--recursive'
    '--parallel'
)

YAPF_EXCLUDES=(
    '--exclude' 'python/ray/cloudpickle/*'<commit_msg>Show lint download commands if tools not installed (#6984)<commit_after>#!/usr/bin/env bash
# YAPF + Clang formatter (if installed). This script formats all changed files from the last mergebase.
# You are encouraged to run this locally before pushing changes for review.

# Cause the script to exit if a single command fails
set -eo pipefail

FLAKE8_VERSION_REQUIRED="3.7.7"
YAPF_VERSION_REQUIRED="0.23.0"

check_command_exist() {
    VERSION=""
    case "$1" in
        yapf)
            VERSION=$YAPF_VERSION_REQUIRED
            ;;
        flake8)
            VERSION=$FLAKE8_VERSION_REQUIRED
            ;;
        *)
            echo "$1 is not a required dependency"
            exit 1
    esac
    if ! [ -x "$(command -v $1)" ]; then
        echo "$1 not installed. pip install $1==$VERSION"
        exit 1
    fi 
}

check_command_exist yapf
check_command_exist flake8

ver=$(yapf --version)
if ! echo $ver | grep -q 0.23.0; then
    echo "Wrong YAPF version installed: 0.23.0 is required, not $ver. $YAPF_DOWNLOAD_COMMAND_MSG"
    exit 1
fi

# this stops git rev-parse from failing if we run this from the .git directory
builtin cd "$(dirname "${BASH_SOURCE:-$0}")"

ROOT="$(git rev-parse --show-toplevel)"
builtin cd "$ROOT" || exit 1

# Add the upstream remote if it doesn't exist
if ! git remote -v | grep -q upstream; then
    git remote add 'upstream' 'https://github.com/ray-project/ray.git'
fi

FLAKE8_VERSION=$(flake8 --version | awk '{print $1}')
YAPF_VERSION=$(yapf --version | awk '{print $2}')

# params: tool name, tool version, required version
tool_version_check() {
    if [[ $2 != $3 ]]; then
        echo "WARNING: Ray uses $1 $3, You currently are using $2. This might generate different results."
    fi
}

tool_version_check "flake8" $FLAKE8_VERSION $FLAKE8_VERSION_REQUIRED
tool_version_check "yapf" $YAPF_VERSION $YAPF_VERSION_REQUIRED

if which clang-format >/dev/null; then
  CLANG_FORMAT_VERSION=$(clang-format --version | awk '{print $3}')
  tool_version_check "clang-format" $CLANG_FORMAT_VERSION "7.0.0"
else
    echo "WARNING: clang-format is not installed!"
fi

# Only fetch master since that's the branch we're diffing against.
git fetch upstream master || true

YAPF_FLAGS=(
    '--style' "$ROOT/.style.yapf"
    '--recursive'
    '--parallel'
)

YAPF_EXCLUDES=(
    '--exclude' 'python/ray/cloudpickle/*'
{'fraction_non_alphanumeric': 0.12272055199605716, 'fraction_numerical': 0.020206998521439132, 'mean_word_length': 3.4653465346534653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6157603', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1365, 'n_words': 457}