Skip to content

Commit 74162d1

Browse files
pcmoritzrobertnishihara
authored andcommitted
Lint Python files with Yapf (ray-project#1872)
1 parent a3ddde3 commit 74162d1

File tree

97 files changed

+3911
-3123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+3911
-3123
lines changed

.style.yapf

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ blank_line_before_nested_class_or_def=False
4242
# 'key1': 'value1',
4343
# 'key2': 'value2',
4444
# })
45-
coalesce_brackets=False
45+
coalesce_brackets=True
4646

4747
# The column limit.
4848
column_limit=79
@@ -90,7 +90,7 @@ i18n_function_call=
9090
# 'key2': value1 +
9191
# value2,
9292
# }
93-
indent_dictionary_value=False
93+
indent_dictionary_value=True
9494

9595
# The number of columns to use for indentation.
9696
indent_width=4
@@ -187,4 +187,3 @@ split_penalty_logical_operator=300
187187

188188
# Use the Tab character for indentation.
189189
use_tabs=False
190-

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ matrix:
3838
- export PATH="$HOME/miniconda/bin:$PATH"
3939
- cd doc
4040
- pip install -q -r requirements-doc.txt
41+
- pip install yapf
4142
- sphinx-build -W -b html -d _build/doctrees source _build/html
4243
- cd ..
4344
# Run Python linting.
4445
- flake8 --exclude=python/ray/core/src/common/flatbuffers_ep-prefix/,python/ray/core/generated/,src/common/format/,doc/source/conf.py,python/ray/cloudpickle/
46+
- .travis/yapf.sh
4547

4648
- os: linux
4749
dist: trusty

.travis/yapf.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# Cause the script to exit if a single command fails
4+
set -e
5+
6+
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)
7+
8+
pushd $ROOT_DIR/../test
9+
find . -name '*.py' -type f -exec yapf --style=pep8 -i -r {} \;
10+
popd
11+
12+
pushd $ROOT_DIR/../python
13+
find . -name '*.py' -type f -not -path './ray/dataframe/*' -not -path './ray/rllib/*' -not -path './ray/cloudpickle/*' -exec yapf --style=pep8 -i -r {} \;
14+
popd
15+
16+
CHANGED_FILES=(`git diff --name-only`)
17+
if [ "$CHANGED_FILES" ]; then
18+
echo 'Reformatted staged files. Please review and stage the changes.'
19+
echo
20+
echo 'Files updated:'
21+
for file in ${CHANGED_FILES[@]}; do
22+
echo " $file"
23+
done
24+
exit 1
25+
else
26+
exit 0
27+
fi

python/ray/__init__.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
# Add the directory containing pyarrow to the Python path so that we find the
1414
# pyarrow version packaged with ray and not a pre-existing pyarrow.
15-
pyarrow_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
16-
"pyarrow_files")
15+
pyarrow_path = os.path.join(
16+
os.path.abspath(os.path.dirname(__file__)), "pyarrow_files")
1717
sys.path.insert(0, pyarrow_path)
1818

1919
# See https://github.com/ray-project/ray/issues/131.
@@ -27,29 +27,29 @@
2727
try:
2828
import pyarrow # noqa: F401
2929
except ImportError as e:
30-
if ((hasattr(e, "msg") and isinstance(e.msg, str) and
31-
("libstdc++" in e.msg or "CXX" in e.msg))):
30+
if ((hasattr(e, "msg") and isinstance(e.msg, str)
31+
and ("libstdc++" in e.msg or "CXX" in e.msg))):
3232
# This code path should be taken with Python 3.
3333
e.msg += helpful_message
34-
elif (hasattr(e, "message") and isinstance(e.message, str) and
35-
("libstdc++" in e.message or "CXX" in e.message)):
34+
elif (hasattr(e, "message") and isinstance(e.message, str)
35+
and ("libstdc++" in e.message or "CXX" in e.message)):
3636
# This code path should be taken with Python 2.
37-
condition = (hasattr(e, "args") and isinstance(e.args, tuple) and
38-
len(e.args) == 1 and isinstance(e.args[0], str))
37+
condition = (hasattr(e, "args") and isinstance(e.args, tuple)
38+
and len(e.args) == 1 and isinstance(e.args[0], str))
3939
if condition:
40-
e.args = (e.args[0] + helpful_message,)
40+
e.args = (e.args[0] + helpful_message, )
4141
else:
4242
if not hasattr(e, "args"):
4343
e.args = ()
4444
elif not isinstance(e.args, tuple):
45-
e.args = (e.args,)
46-
e.args += (helpful_message,)
45+
e.args = (e.args, )
46+
e.args += (helpful_message, )
4747
raise
4848

4949
from ray.local_scheduler import _config # noqa: E402
50-
from ray.worker import (error_info, init, connect, disconnect,
51-
get, put, wait, remote, log_event, log_span,
52-
flush_log, get_gpu_ids, get_webui_url,
50+
from ray.worker import (error_info, init, connect, disconnect, get, put, wait,
51+
remote, log_event, log_span, flush_log, get_gpu_ids,
52+
get_webui_url,
5353
register_custom_serializer) # noqa: E402
5454
from ray.worker import (SCRIPT_MODE, WORKER_MODE, PYTHON_MODE,
5555
SILENT_MODE) # noqa: E402
@@ -63,11 +63,13 @@
6363
# Fix this.
6464
__version__ = "0.4.0"
6565

66-
__all__ = ["error_info", "init", "connect", "disconnect", "get", "put", "wait",
67-
"remote", "log_event", "log_span", "flush_log", "actor", "method",
68-
"get_gpu_ids", "get_webui_url", "register_custom_serializer",
69-
"SCRIPT_MODE", "WORKER_MODE", "PYTHON_MODE", "SILENT_MODE",
70-
"global_state", "_config", "__version__"]
66+
__all__ = [
67+
"error_info", "init", "connect", "disconnect", "get", "put", "wait",
68+
"remote", "log_event", "log_span", "flush_log", "actor", "method",
69+
"get_gpu_ids", "get_webui_url", "register_custom_serializer",
70+
"SCRIPT_MODE", "WORKER_MODE", "PYTHON_MODE", "SILENT_MODE", "global_state",
71+
"_config", "__version__"
72+
]
7173

7274
import ctypes # noqa: E402
7375
# Windows only

0 commit comments

Comments
 (0)