2018-04-11 10:11:35 -07:00
#!/usr/bin/env bash
2022-02-07 16:05:27 -08:00
# Black + Clang formatter (if installed). This script formats all changed files from the last mergebase.
2018-10-18 21:56:22 -07:00
# You are encouraged to run this locally before pushing changes for review.
2018-04-11 10:11:35 -07:00
# Cause the script to exit if a single command fails
2020-07-30 16:39:28 -07:00
set -euo pipefail
2018-04-11 10:11:35 -07:00
2021-05-03 14:23:28 -07:00
FLAKE8_VERSION_REQUIRED = "3.9.1"
2022-01-03 12:06:41 -06:00
BLACK_VERSION_REQUIRED = "21.12b0"
2020-07-30 16:39:28 -07:00
SHELLCHECK_VERSION_REQUIRED = "0.7.1"
2020-10-05 14:20:45 -04:00
MYPY_VERSION_REQUIRED = "0.782"
2022-06-13 14:08:51 -07:00
ISORT_VERSION_REQUIRED = "5.10.1"
2020-01-31 10:42:09 -08:00
2022-02-24 09:53:03 -08:00
check_python_command_exist( ) {
2020-01-31 10:42:09 -08:00
VERSION = ""
case " $1 " in
2022-01-03 12:06:41 -06:00
black)
VERSION = $BLACK_VERSION_REQUIRED
; ;
2020-01-31 10:42:09 -08:00
flake8)
VERSION = $FLAKE8_VERSION_REQUIRED
; ;
2020-10-05 14:20:45 -04:00
mypy)
VERSION = $MYPY_VERSION_REQUIRED
; ;
2022-06-13 14:08:51 -07:00
isort)
VERSION = $ISORT_VERSION_REQUIRED
; ;
2020-01-31 10:42:09 -08:00
*)
2021-10-05 16:33:12 -07:00
echo " $1 is not a required dependency "
2020-01-31 10:42:09 -08:00
exit 1
esac
2020-07-21 19:56:41 -07:00
if ! [ -x " $( command -v " $1 " ) " ] ; then
2022-02-24 09:53:03 -08:00
echo " $1 not installed. Install the python package with: pip install $1 == $VERSION "
2020-01-31 10:42:09 -08:00
exit 1
2020-07-29 21:15:09 +02:00
fi
2020-01-31 10:42:09 -08:00
}
2022-06-01 11:27:54 -07:00
check_docstyle( ) {
echo "Checking docstyle..."
2022-07-27 22:24:20 -07:00
violations = $( git ls-files | grep '.py$' | xargs grep -E '^[ ]+[a-z_]+ ?\([a-zA-Z]+\): ' | grep -v 'str(' | grep -v noqa || true )
2022-06-01 11:27:54 -07:00
if [ [ -n " $violations " ] ] ; then
echo
echo "=== Found Ray docstyle violations ==="
echo " $violations "
echo
echo "Per the Google pydoc style, omit types from pydoc args as they are redundant: https://docs.ray.io/en/latest/ray-contribute/getting-involved.html#code-style "
2022-07-27 22:24:20 -07:00
echo "If this is a false positive, you can add a '# noqa' comment to the line to ignore."
2022-06-01 11:27:54 -07:00
exit 1
fi
return 0
}
2022-02-24 09:53:03 -08:00
check_python_command_exist black
check_python_command_exist flake8
check_python_command_exist mypy
2022-06-13 14:08:51 -07:00
check_python_command_exist isort
2020-01-31 10:42:09 -08:00
2018-05-19 16:07:28 -07:00
# this stops git rev-parse from failing if we run this from the .git directory
builtin cd " $( dirname " ${ BASH_SOURCE :- $0 } " ) "
2018-04-11 10:11:35 -07:00
2018-05-19 16:07:28 -07:00
ROOT = " $( git rev-parse --show-toplevel) "
2018-06-05 20:22:11 -07:00
builtin cd " $ROOT " || exit 1
2022-05-16 16:40:21 -05:00
# NOTE(edoakes): black version differs based on installation method:
# Option 1) 'black, 21.12b0 (compiled: no)'
# Option 2) 'black, version 21.12b0'
BLACK_VERSION_STR = $( black --version)
if [ [ " $BLACK_VERSION_STR " = = *"compiled" * ] ]
then
BLACK_VERSION = $( echo " $BLACK_VERSION_STR " | awk '{print $2}' )
else
BLACK_VERSION = $( echo " $BLACK_VERSION_STR " | awk '{print $3}' )
fi
2020-10-05 14:20:45 -04:00
FLAKE8_VERSION = $( flake8 --version | head -n 1 | awk '{print $1}' )
MYPY_VERSION = $( mypy --version | awk '{print $2}' )
2022-06-13 14:08:51 -07:00
ISORT_VERSION = $( isort --version | grep VERSION | awk '{print $2}' )
2020-12-29 10:36:16 +08:00
GOOGLE_JAVA_FORMAT_JAR = /tmp/google-java-format-1.7-all-deps.jar
2019-07-04 23:22:01 -07:00
2019-07-08 17:15:09 +08:00
# params: tool name, tool version, required version
tool_version_check( ) {
2020-07-21 19:56:41 -07:00
if [ " $2 " != " $3 " ] ; then
2021-10-05 16:33:12 -07:00
echo " WARNING: Ray uses $1 $3 , You currently are using $2 . This might generate different results. "
2019-07-08 17:15:09 +08:00
fi
}
2020-07-24 15:24:19 -07:00
tool_version_check "flake8" " $FLAKE8_VERSION " " $FLAKE8_VERSION_REQUIRED "
2022-02-07 16:05:27 -08:00
tool_version_check "black" " $BLACK_VERSION " " $BLACK_VERSION_REQUIRED "
2020-10-05 14:20:45 -04:00
tool_version_check "mypy" " $MYPY_VERSION " " $MYPY_VERSION_REQUIRED "
2022-06-13 14:08:51 -07:00
tool_version_check "isort" " $ISORT_VERSION " " $ISORT_VERSION_REQUIRED "
2019-07-04 23:22:01 -07:00
2022-02-24 12:04:05 -08:00
if command -v shellcheck >/dev/null; then
SHELLCHECK_VERSION = $( shellcheck --version | awk '/^version:/ {print $2}' )
tool_version_check "shellcheck" " $SHELLCHECK_VERSION " " $SHELLCHECK_VERSION_REQUIRED "
else
echo " INFO: Ray uses shellcheck for shell scripts, which is not installed. You may install shellcheck= $SHELLCHECK_VERSION_REQUIRED with your system package manager. "
fi
if command -v clang-format >/dev/null; then
2021-10-05 16:33:12 -07:00
CLANG_FORMAT_VERSION = $( clang-format --version | awk '{print $3}' )
tool_version_check "clang-format" " $CLANG_FORMAT_VERSION " "12.0.0"
2019-07-04 23:22:01 -07:00
else
2021-10-05 16:33:12 -07:00
echo "WARNING: clang-format is not installed!"
2019-07-04 23:22:01 -07:00
fi
2020-12-29 10:36:16 +08:00
if command -v java >/dev/null; then
if [ ! -f " $GOOGLE_JAVA_FORMAT_JAR " ] ; then
2021-10-05 16:33:12 -07:00
echo "Java code format tool google-java-format.jar is not installed, start to install it."
2020-12-29 10:36:16 +08:00
wget https://github.com/google/google-java-format/releases/download/google-java-format-1.7/google-java-format-1.7-all-deps.jar -O " $GOOGLE_JAVA_FORMAT_JAR "
fi
else
2021-10-05 16:33:12 -07:00
echo "WARNING:java is not installed, skip format java files!"
2020-12-29 10:36:16 +08:00
fi
2020-08-15 10:09:02 +03:00
if [ [ $( flake8 --version) != *"flake8_quotes" * ] ] ; then
2021-10-05 16:33:12 -07:00
echo "WARNING: Ray uses flake8 with flake8_quotes. Might error without it. Install with: pip install flake8-quotes"
2020-08-15 10:09:02 +03:00
fi
2021-10-03 23:24:11 -07:00
if [ [ $( flake8 --version) != *"flake8-bugbear" * ] ] ; then
echo "WARNING: Ray uses flake8 with flake8-bugbear. Might error without it. Install with: pip install flake8-bugbear"
fi
2020-07-30 16:39:28 -07:00
SHELLCHECK_FLAGS = (
2021-10-05 16:33:12 -07:00
--exclude= 1090 # "Can't follow non-constant source. Use a directive to specify location."
--exclude= 1091 # "Not following {file} due to some error"
--exclude= 2207 # "Prefer mapfile or read -a to split command output (or quote to avoid splitting)." -- these aren't compatible with macOS's old Bash
2020-07-30 16:39:28 -07:00
)
2020-10-05 14:20:45 -04:00
# TODO(dmitri): When more of the codebase is typed properly, the mypy flags
2021-04-26 14:06:03 -07:00
# should be set to do a more stringent check.
2020-10-05 14:20:45 -04:00
MYPY_FLAGS = (
'--follow-imports=skip'
2020-10-16 16:45:36 -04:00
'--ignore-missing-imports'
2020-10-05 14:20:45 -04:00
)
MYPY_FILES = (
2020-10-16 16:45:36 -04:00
# Relative to python/ray
'autoscaler/node_provider.py'
2022-01-25 14:43:24 -08:00
'autoscaler/sdk/__init__.py'
'autoscaler/sdk/sdk.py'
2020-10-16 16:45:36 -04:00
'autoscaler/_private/commands.py'
2022-07-18 13:27:19 -07:00
'autoscaler/_private/autoscaler.py'
2021-06-01 12:00:55 -07:00
# TODO(dmitri) Fails with meaningless error, maybe due to a bug in the mypy version
# in the CI. Type check once we get serious about type checking:
#'ray_operator/operator.py'
2021-01-26 10:29:07 -08:00
'ray_operator/operator_utils.py'
2022-05-31 10:45:42 -07:00
'_private/gcs_utils.py'
2020-10-05 14:20:45 -04:00
)
2022-06-15 11:34:45 -07:00
2022-01-03 12:06:41 -06:00
BLACK_EXCLUDES = (
2022-04-21 10:21:35 +08:00
'--force-exclude' 'python/ray/cloudpickle/*'
'--force-exclude' 'python/build/*'
'--force-exclude' 'python/ray/core/src/ray/gcs/*'
'--force-exclude' 'python/ray/thirdparty_files/*'
'--force-exclude' 'python/ray/_private/thirdparty/*'
2022-01-03 12:06:41 -06:00
)
2020-08-07 16:49:49 -07:00
GIT_LS_EXCLUDES = (
':(exclude)python/ray/cloudpickle/'
2022-02-16 02:51:01 +08:00
':(exclude)python/ray/_private/runtime_env/_clonevirtualenv.py'
2020-08-07 16:49:49 -07:00
)
2020-12-29 10:36:16 +08:00
JAVA_EXCLUDES = (
'java/api/src/main/java/io/ray/api/ActorCall.java'
2022-06-29 14:33:32 +08:00
'java/api/src/main/java/io/ray/api/CppActorCall.java'
2020-12-29 10:36:16 +08:00
'java/api/src/main/java/io/ray/api/PyActorCall.java'
'java/api/src/main/java/io/ray/api/RayCall.java'
)
JAVA_EXCLUDES_REGEX = ""
for f in " ${ JAVA_EXCLUDES [@] } " ; do
JAVA_EXCLUDES_REGEX = " $JAVA_EXCLUDES_REGEX |( ${ f // \/ / \/ } ) "
done
JAVA_EXCLUDES_REGEX = ${ JAVA_EXCLUDES_REGEX #| }
2020-08-07 16:49:49 -07:00
# TODO(barakmich): This should be cleaned up. I've at least excised the copies
# of these arguments to this location, but the long-term answer is to actually
# make a flake8 config file
FLAKE8_PYX_IGNORES = "--ignore=C408,E121,E123,E126,E211,E225,E226,E227,E24,E704,E999,W503,W504,W605"
2020-08-06 10:44:37 +02:00
2020-07-30 16:39:28 -07:00
shellcheck_scripts( ) {
shellcheck " ${ SHELLCHECK_FLAGS [@] } " " $@ "
}
2021-04-26 14:06:03 -07:00
# Runs mypy on each argument in sequence. This is different than running mypy
2020-10-05 14:20:45 -04:00
# once on the list of arguments.
mypy_on_each( ) {
2020-10-16 16:45:36 -04:00
pushd python/ray
2020-10-05 14:20:45 -04:00
for file in " $@ " ; do
2021-10-05 16:33:12 -07:00
echo " Running mypy on $file "
2020-10-05 14:20:45 -04:00
mypy ${ MYPY_FLAGS [@]+ " ${ MYPY_FLAGS [@] } " } " $file "
done
2020-10-16 16:45:36 -04:00
popd
2020-10-05 14:20:45 -04:00
}
2022-06-13 14:08:51 -07:00
2018-06-05 20:22:11 -07:00
# Format specified files
2020-08-07 16:49:49 -07:00
format_files( ) {
2020-07-30 16:39:28 -07:00
local shell_files = ( ) python_files = ( ) bazel_files = ( )
local name
for name in " $@ " ; do
local base = " ${ name %.* } "
2022-06-13 14:08:51 -07:00
local suffix = " ${ name # " ${ base } " } "
2020-07-30 16:39:28 -07:00
local shebang = ""
read -r shebang < " ${ name } " || true
case " ${ shebang } " in
'#!' *)
shebang = " ${ shebang #/usr/bin/env } "
shebang = " ${ shebang %% * } "
shebang = " ${ shebang ##*/ } "
; ;
esac
if [ " ${ base } " = "WORKSPACE" ] || [ " ${ base } " = "BUILD" ] || [ " ${ suffix } " = ".BUILD" ] || [ " ${ suffix } " = ".bazel" ] || [ " ${ suffix } " = ".bzl" ] ; then
bazel_files += ( " ${ name } " )
elif [ -z " ${ suffix } " ] && [ " ${ shebang } " != " ${ shebang #python } " ] || [ " ${ suffix } " != " ${ suffix #.py } " ] ; then
python_files += ( " ${ name } " )
elif [ -z " ${ suffix } " ] && [ " ${ shebang } " != " ${ shebang %sh } " ] || [ " ${ suffix } " != " ${ suffix #.sh } " ] ; then
shell_files += ( " ${ name } " )
else
2021-10-05 16:33:12 -07:00
echo " error: failed to determine file type: ${ name } " 1>& 2
2020-07-30 16:39:28 -07:00
return 1
fi
done
if [ 0 -lt " ${# python_files [@] } " ] ; then
2022-06-13 14:08:51 -07:00
isort " ${ python_files [@] } "
2022-02-07 16:05:27 -08:00
black " ${ python_files [@] } "
2020-07-30 16:39:28 -07:00
fi
2022-02-24 12:04:05 -08:00
if command -v shellcheck >/dev/null; then
if shellcheck --shell= sh --format= diff - < /dev/null; then
if [ 0 -lt " ${# shell_files [@] } " ] ; then
local difference
difference = " $( shellcheck_scripts --format= diff " ${ shell_files [@] } " || true && printf "-" ) "
difference = " ${ difference %- } "
printf "%s" " ${ difference } " | patch -p1
fi
else
echo "error: this version of shellcheck does not support diffs"
2020-07-30 16:39:28 -07:00
fi
fi
2018-06-05 20:22:11 -07:00
}
2021-09-24 17:59:05 -07:00
format_all_scripts( ) {
2020-08-07 16:49:49 -07:00
command -v flake8 & > /dev/null;
HAS_FLAKE8 = $?
2022-06-13 14:08:51 -07:00
# Run isort before black to fix imports and let black deal with file format.
echo " $( date) " "isort...."
2022-06-17 13:40:32 -07:00
git ls-files -- '*.py' " ${ GIT_LS_EXCLUDES [@] } " | xargs -P 10 \
isort
2022-02-07 16:05:27 -08:00
echo " $( date) " "Black...."
git ls-files -- '*.py' " ${ GIT_LS_EXCLUDES [@] } " | xargs -P 10 \
black " ${ BLACK_EXCLUDES [@] } "
2021-10-05 16:33:12 -07:00
echo " $( date) " "MYPY...."
2020-10-05 14:20:45 -04:00
mypy_on_each " ${ MYPY_FILES [@] } "
2020-08-07 16:49:49 -07:00
if [ $HAS_FLAKE8 ] ; then
2021-10-05 16:33:12 -07:00
echo " $( date) " "Flake8...."
2020-08-07 16:49:49 -07:00
git ls-files -- '*.py' " ${ GIT_LS_EXCLUDES [@] } " | xargs -P 5 \
2020-12-12 11:34:30 -08:00
flake8 --config= .flake8
2020-08-07 16:49:49 -07:00
git ls-files -- '*.pyx' '*.pxd' '*.pxi' " ${ GIT_LS_EXCLUDES [@] } " | xargs -P 5 \
2020-12-12 11:34:30 -08:00
flake8 --config= .flake8 " $FLAKE8_PYX_IGNORES "
2020-08-07 16:49:49 -07:00
fi
if command -v shellcheck >/dev/null; then
local shell_files non_shell_files
non_shell_files = ( $( git ls-files -- ':(exclude)*.sh' ) )
shell_files = ( $( git ls-files -- '*.sh' ) )
if [ 0 -lt " ${# non_shell_files [@] } " ] ; then
shell_files += ( $( git --no-pager grep -l -- '^#!\(/usr\)\?/bin/\(env \+\)\?\(ba\)\?sh' " ${ non_shell_files [@] } " || true ) )
fi
if [ 0 -lt " ${# shell_files [@] } " ] ; then
2021-10-05 16:33:12 -07:00
echo " $( date) " "shellcheck scripts...."
2020-08-07 16:49:49 -07:00
shellcheck_scripts " ${ shell_files [@] } "
fi
fi
2021-09-24 17:59:05 -07:00
}
# Format all files, and print the diff to stdout for travis.
# Mypy is run only on files specified in the array MYPY_FILES.
format_all( ) {
format_all_scripts " ${ @ } "
2021-10-05 16:33:12 -07:00
echo " $( date) " "clang-format...."
2021-09-24 17:59:05 -07:00
if command -v clang-format >/dev/null; then
git ls-files -- '*.cc' '*.h' '*.proto' " ${ GIT_LS_EXCLUDES [@] } " | xargs -P 5 clang-format -i
fi
2021-10-05 16:33:12 -07:00
echo " $( date) " "format java...."
2021-09-24 17:59:05 -07:00
if command -v java >/dev/null & [ -f " $GOOGLE_JAVA_FORMAT_JAR " ] ; then
git ls-files -- '*.java' " ${ GIT_LS_EXCLUDES [@] } " | sed -E " \: $JAVA_EXCLUDES_REGEX :d " | xargs -P 5 java -jar " $GOOGLE_JAVA_FORMAT_JAR " -i
fi
2021-10-05 16:33:12 -07:00
echo " $( date) " "done!"
2020-08-07 16:49:49 -07:00
}
2018-06-05 20:22:11 -07:00
# Format files that differ from main branch. Ignores dirs that are not slated
# for autoformat yet.
format_changed( ) {
# The `if` guard ensures that the list of filenames is not empty, which
2022-01-03 12:06:41 -06:00
# could cause the formatter to receive 0 positional arguments, making
2022-02-07 16:05:27 -08:00
# Black error.
2018-06-05 20:22:11 -07:00
#
2019-11-12 11:45:28 -08:00
# `diff-filter=ACRM` and $MERGEBASE is to ensure we only format files that
2018-06-05 20:22:11 -07:00
# exist on both branches.
MERGEBASE = " $( git merge-base upstream/master HEAD) "
2022-06-17 13:40:32 -07:00
if ! git diff --diff-filter= ACRM --quiet --exit-code " $MERGEBASE " -- '*.py' & >/dev/null; then
git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- '*.py' | xargs -P 5 \
2022-06-13 14:08:51 -07:00
isort
fi
2019-11-12 11:45:28 -08:00
if ! git diff --diff-filter= ACRM --quiet --exit-code " $MERGEBASE " -- '*.py' & >/dev/null; then
2022-02-07 16:05:27 -08:00
git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- '*.py' | xargs -P 5 \
black " ${ BLACK_EXCLUDES [@] } "
2021-10-05 16:33:12 -07:00
if which flake8 >/dev/null; then
2019-11-12 11:45:28 -08:00
git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- '*.py' | xargs -P 5 \
2020-12-12 11:34:30 -08:00
flake8 --config= .flake8
2019-02-22 17:33:08 -08:00
fi
fi
2019-11-12 11:45:28 -08:00
if ! git diff --diff-filter= ACRM --quiet --exit-code " $MERGEBASE " -- '*.pyx' '*.pxd' '*.pxi' & >/dev/null; then
2021-10-05 16:33:12 -07:00
if which flake8 >/dev/null; then
2019-11-12 11:45:28 -08:00
git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- '*.pyx' '*.pxd' '*.pxi' | xargs -P 5 \
2020-12-12 11:34:30 -08:00
flake8 --config= .flake8 " $FLAKE8_PYX_IGNORES "
2018-11-06 14:59:22 -08:00
fi
2018-06-05 20:22:11 -07:00
fi
2018-10-18 21:56:22 -07:00
2021-10-05 16:33:12 -07:00
if which clang-format >/dev/null; then
if ! git diff --diff-filter= ACRM --quiet --exit-code " $MERGEBASE " -- '*.cc' '*.h' & >/dev/null; then
git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- '*.cc' '*.h' | xargs -P 5 \
clang-format -i
fi
2018-10-18 21:56:22 -07:00
fi
2020-07-30 16:39:28 -07:00
2020-12-29 10:36:16 +08:00
if command -v java >/dev/null & [ -f " $GOOGLE_JAVA_FORMAT_JAR " ] ; then
if ! git diff --diff-filter= ACRM --quiet --exit-code " $MERGEBASE " -- '*.java' & >/dev/null; then
git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- '*.java' | sed -E " \: $JAVA_EXCLUDES_REGEX :d " | xargs -P 5 java -jar " $GOOGLE_JAVA_FORMAT_JAR " -i
fi
fi
2020-07-30 16:39:28 -07:00
if command -v shellcheck >/dev/null; then
2020-07-31 09:25:55 -07:00
local shell_files non_shell_files
non_shell_files = ( $( git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- ':(exclude)*.sh' ) )
shell_files = ( $( git diff --name-only --diff-filter= ACRM " $MERGEBASE " -- '*.sh' ) )
if [ 0 -lt " ${# non_shell_files [@] } " ] ; then
2020-08-02 00:59:05 -07:00
shell_files += ( $( git --no-pager grep -l -- '^#!\(/usr\)\?/bin/\(env \+\)\?\(ba\)\?sh' " ${ non_shell_files [@] } " || true ) )
2020-07-31 09:25:55 -07:00
fi
2020-07-30 16:39:28 -07:00
if [ 0 -lt " ${# shell_files [@] } " ] ; then
shellcheck_scripts " ${ shell_files [@] } "
fi
fi
2018-06-05 20:22:11 -07:00
}
# This flag formats individual files. --files *must* be the first command line
# arg to use this option.
2020-07-30 16:39:28 -07:00
if [ " ${ 1 - } " = = '--files' ] ; then
2020-08-07 16:49:49 -07:00
format_files " ${ @ : 2 } "
2021-09-24 17:59:05 -07:00
# If `--all` or `--scripts` are passed, then any further arguments are ignored.
# Format the entire python directory and other scripts.
elif [ " ${ 1 - } " = = '--all-scripts' ] ; then
format_all_scripts " ${ @ } "
if [ -n " ${ FORMAT_SH_PRINT_DIFF - } " ] ; then git --no-pager diff; fi
# Format the all Python, C++, Java and other script files.
2020-07-30 16:39:28 -07:00
elif [ " ${ 1 - } " = = '--all' ] ; then
2020-08-07 16:49:49 -07:00
format_all " ${ @ } "
if [ -n " ${ FORMAT_SH_PRINT_DIFF - } " ] ; then git --no-pager diff; fi
2018-06-05 20:22:11 -07:00
else
2020-08-07 16:49:49 -07:00
# 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
# Only fetch master since that's the branch we're diffing against.
2021-10-05 16:33:12 -07:00
git fetch upstream master || true
2020-08-07 16:49:49 -07:00
2018-06-05 20:22:11 -07:00
# Format only the files that changed in last commit.
format_changed
fi
2022-06-01 11:27:54 -07:00
check_docstyle
2020-02-05 14:16:58 -08:00
# Ensure import ordering
2020-10-01 14:52:04 -07:00
# Make sure that for every import psutil; import setproctitle
2020-02-05 14:16:58 -08:00
# There's a import ray above it.
2020-03-15 03:27:41 +08:00
PYTHON_EXECUTABLE = ${ PYTHON_EXECUTABLE :- python }
2022-04-13 18:11:30 +01:00
$PYTHON_EXECUTABLE ci/lint/check_import_order.py . -s ci -s python/ray/thirdparty_files -s python/build -s lib
2020-02-05 14:16:58 -08:00
2018-06-05 20:22:11 -07:00
if ! git diff --quiet & >/dev/null; then
2021-10-05 16:33:12 -07:00
echo 'Reformatted changed files. Please review and stage the changes.'
echo 'Files updated:'
echo
2018-05-19 16:07:28 -07:00
git --no-pager diff --name-only
exit 1
2018-04-11 10:11:35 -07:00
fi