|
7 | 7 |
|
8 | 8 | set -e
|
9 | 9 |
|
10 |
| -if [ ! "$(black --version)" ] |
| 10 | +if [ ! "$(lintrunner --version)" ] |
11 | 11 | then
|
12 |
| - echo "Please install black." |
| 12 | + echo "Please install lintrunner." |
13 | 13 | exit 1
|
14 | 14 | fi
|
15 |
| -if [ ! "$(usort --version)" ] |
16 |
| -then |
17 |
| - echo "Please install usort." |
18 |
| - exit 1 |
19 |
| -fi |
20 |
| -if [ ! "$(flake8 --version)" ] |
21 |
| -then |
22 |
| - echo "Please install flake8." |
23 |
| - exit 1 |
24 |
| -fi |
25 |
| - |
26 |
| -# cd to the project directory |
27 |
| -cd "$(dirname "$0")/.." || exit 1 |
28 |
| - |
29 |
| -GIT_URL_1="https://github.com/pytorch/torchx.git" |
30 |
| -GIT_URL_2= "[email protected]:pytorch/torchx.git" |
31 |
| - |
32 |
| -UPSTREAM_URL="$(git config remote.upstream.url)" || true |
33 |
| - |
34 |
| -if [ -z "$UPSTREAM_URL" ] |
35 |
| -then |
36 |
| - echo "Setting upstream remote to $GIT_URL_1" |
37 |
| - git remote add upstream "$GIT_URL_1" |
38 |
| -elif [ "$UPSTREAM_URL" != "$GIT_URL_1" ] && \ |
39 |
| - [ "$UPSTREAM_URL" != "$GIT_URL_2" ] |
40 |
| -then |
41 |
| - echo "upstream remote set to $UPSTREAM_URL." |
42 |
| - echo "Please delete the upstream remote or set it to $GIT_URL_1 to use this script." |
43 |
| - exit 1 |
44 |
| -fi |
45 |
| - |
46 |
| -git fetch upstream |
47 | 15 |
|
48 |
| -CHANGED_FILES="$(git diff --diff-filter=ACMRT --name-only upstream/main | grep '\.py$' | tr '\n' ' ')" |
49 |
| - |
50 |
| -if [ "$CHANGED_FILES" != "" ] |
51 |
| -then |
52 |
| - # Processing files one by one since passing directly $CHANGED_FILES will |
53 |
| - # treat the whole variable as a single file. |
54 |
| - echo "Running linters ..." |
55 |
| - for file in $CHANGED_FILES |
56 |
| - do |
57 |
| - echo "Checking $file" |
58 |
| - usort format "$file" |
59 |
| - black "$file" -q |
60 |
| - flake8 "$file" || LINT_ERRORS=1 |
61 |
| - done |
62 |
| -else |
63 |
| - echo "No changes made to any Python files. Nothing to do." |
64 |
| - exit 0 |
65 |
| -fi |
66 |
| - |
67 |
| -if [ "$LINT_ERRORS" != "" ] |
68 |
| -then |
69 |
| - echo "One of the linters returned an error. See above output." |
70 |
| - # need this so that CI fails |
71 |
| - exit 1 |
72 |
| -fi |
73 |
| - |
74 |
| -# Check if any files were modified by running usort + black |
75 |
| -# If so, then the files were formatted incorrectly (e.g. did not pass lint) |
76 |
| -CHANGED_FILES="$(git diff --name-only | grep '\.py$' | tr '\n' ' ')" |
77 |
| -if [ "$CHANGED_FILES" != "" ] |
78 |
| -then |
79 |
| - RED="\e[31m" |
80 |
| - ENDCOLOR="\e[0m" |
81 |
| - echo "------------------------------------------" |
82 |
| - echo -e "${RED}[format] These files are not well-formatted:${ENDCOLOR}" |
83 |
| - git diff --name-only |
84 |
| - echo "------------------------------------------" |
85 |
| - echo -e "${RED}[format] Suggested format by lint:${ENDCOLOR}" |
86 |
| - git diff |
87 |
| - echo "------------------------------------------" |
88 |
| - echo "To apply the suggested format, run:" |
89 |
| - echo "usort format <file_name>" |
90 |
| - echo "black <file_name> -q" |
91 |
| - echo "flake8 <file_name>" |
92 |
| - echo -e "${RED}You must fix them before merging the pull request.${ENDCOLOR}" |
93 |
| - # need this so that CI fails |
94 |
| - exit 1 |
95 |
| -else |
96 |
| - echo "All files are well-formatted." |
97 |
| - exit 0 |
98 |
| -fi |
| 16 | +lintrunner --force-color |
0 commit comments