Skip to content

Commit a341d7e

Browse files
bojanserafimovobi1kenobi
authored andcommitted
* Write lint script * Just testing the diff flag of the lint script * Revert "Just testing the diff flag of the lint script" This reverts commit 8e3b842. * Implement proper pydocstyle config * Update CONTRIBUTING docs to include the lint script. * Add newlines at eof * Use git -C * Use lint script in travis
1 parent 8ce65a1 commit a341d7e

File tree

5 files changed

+94
-18
lines changed

5 files changed

+94
-18
lines changed

.pydocstyle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[pydocstyle]
22
ignore = D100,D101,D104,D203,D213,D406,D407,D408,D409,D413
3+
match = '(?!test_).*\.py'

.pydocstyle_test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pydocstyle]
2+
ignore = D100,D101,D102,D104,D203,D213,D406,D407,D408,D409,D413
3+
match = 'test_.*\.py'

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ matrix:
2121
python: "3.6"
2222
script:
2323
- pipenv run ./scripts/copyright_line_check.sh
24-
- pipenv run isort --check-only --verbose --recursive graphql_compiler/
25-
- pipenv run flake8 --config=setup.cfg graphql_compiler/
26-
- pipenv run pydocstyle graphql_compiler/
27-
- pipenv run pylint graphql_compiler/
28-
- pipenv run bandit -r graphql_compiler/
24+
- pipenv run ./scripts/lint.sh
2925
- name: "Python 2.7 unit tests"
3026
python: "2.7"
3127
script:

CONTRIBUTING.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,7 @@ of both the contributors and the project.
5858
This project follows the
5959
[Google Python style guide](https://google.github.io/styleguide/pyguide.html).
6060

61-
Additionally, any contributions must pass the following set of lint and style checks with no issues
62-
when executed from a pipenv shell (i.e. after running `pipenv shell`):
63-
```
64-
isort --check-only --verbose --recursive graphql_compiler/
65-
66-
flake8 graphql_compiler/
67-
68-
pydocstyle graphql_compiler/
69-
70-
pylint graphql_compiler/
71-
72-
bandit -r graphql_compiler/
73-
```
61+
Additionally, any contributions must pass the linter `scripts/lint.sh` when executed from a pipenv shell (i.e. after running `pipenv shell`). To run the linter on changed files only, commit your changes and run `scripts/lint.sh --diff`.
7462

7563
Finally, all python files in the repository must display the copyright of the project,
7664
to protect the terms of the license. Please make sure that your files start with a line like:

scripts/lint.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env bash
2+
3+
# Treat undefined variables and non-zero exits in pipes as errors.
4+
set -uo pipefail
5+
6+
# Ensure that the "**" glob operator is applied recursively.
7+
shopt -s globstar
8+
9+
# Break on first error.
10+
set -e
11+
12+
# Parse input arguments.
13+
diff_only=0
14+
for i in "$@"; do
15+
case $i in
16+
--diff )
17+
diff_only=1
18+
shift;;
19+
20+
*)
21+
echo "Unknown option: $i";
22+
exit 1;;
23+
esac
24+
done
25+
26+
# Make sure the current working directory for this script is the root directory.
27+
cd "$(git -C "$(dirname "${0}")" rev-parse --show-toplevel )"
28+
29+
# Get all python files or directories that need to be linted.
30+
lintable_locations="graphql_compiler/"
31+
# pylint doesn't support linting directories that aren't packages:
32+
# https://github.com/PyCQA/pylint/issues/352
33+
# Use **/*.py to supply all python files for individual linting.
34+
pylint_lintable_locations="graphql_compiler/**/*.py"
35+
if [ "$diff_only" -eq 1 ] ; then
36+
# Quotes don't need to be escaped because they nest with $( ).
37+
lintable_locations="$(git diff --name-only master... | grep "\.*\.py$")"
38+
pylint_lintable_locations="$lintable_locations"
39+
fi
40+
41+
# Continue on error to allow ignoring certain linters.
42+
# Errors are manually aggregated at the end.
43+
set +e
44+
45+
echo -e '*** Running isort... ***\n'
46+
isort --check-only --recursive graphql_compiler/
47+
isort_exit_code=$?
48+
echo -e "\n*** End of isort run; exit: $isort_exit_code ***\n"
49+
50+
echo -e '*** Running flake8... ***\n'
51+
flake8 $lintable_locations
52+
flake_exit_code=$?
53+
echo -e "\n*** End of flake8 run, exit: $flake_exit_code ***\n"
54+
55+
echo -e '\n*** Running pydocstyle... ***\n'
56+
pydocstyle --config=.pydocstyle $lintable_locations
57+
pydocstyle_exit_code=$?
58+
pydocstyle --config=.pydocstyle_test $lintable_locations
59+
pydocstyle_test_exit_code=$?
60+
echo -e "\n*** End of pydocstyle run, exit: $pydocstyle_exit_code ***\n"
61+
62+
echo -e '\n*** Running pylint... ***\n'
63+
pylint $pylint_lintable_locations
64+
pylint_exit_code=$?
65+
echo -e "\n*** End of pylint run, exit: $pylint_exit_code ***\n"
66+
67+
echo -e '\n*** Running bandit... ***\n'
68+
bandit -r $lintable_locations
69+
bandit_exit_code=$?
70+
echo -e "\n*** End of bandit run, exit: $bandit_exit_code ***\n"
71+
72+
if [[ ("$flake_exit_code" != "0") ||
73+
("$pydocstyle_exit_code" != "0") ||
74+
("$pydocstyle_test_exit_code" != "0") ||
75+
("$pylint_exit_code" != "0") ||
76+
("$bandit_exit_code" != "0") ||
77+
("$isort_exit_code" != "0") ]]; then
78+
echo -e "\n*** Lint failed. ***\n"
79+
echo -e "isort exit: $isort_exit_code"
80+
echo -e "flake8 exit: $flake_exit_code"
81+
echo -e "pydocstyle exit: $pydocstyle_exit_code"
82+
echo -e "pydocstyle test exit: $pydocstyle_test_exit_code"
83+
echo -e "pylint exit: $pylint_exit_code"
84+
echo -e "bandit exit: $bandit_exit_code"
85+
exit 1
86+
fi
87+
88+
echo -e "\n*** Lint successful. ***\n"

0 commit comments

Comments
 (0)