diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000000..331c6700a53 --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +max-line-length = 79 +select = B,C,E,F,W,T4,B9,B950 +ignore = E402, W503, W504 diff --git a/.github/workflows/test_fast.yml b/.github/workflows/test_fast.yml index 53cb6348c0a..377a23997ad 100644 --- a/.github/workflows/test_fast.yml +++ b/.github/workflows/test_fast.yml @@ -29,7 +29,6 @@ jobs: - name: Style run: | - pycodestyle flake8 etc/bin/shellchecker diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000000..a8ee33b7a5d --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,7 @@ +[settings] +multi_line_output=3 +include_trailing_comma=true +force_grid_wrap=0 +use_parentheses=true +ensure_newline_before_comments=true +line_length=79 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..283ce36b433 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/timothycrosley/isort + rev: 5.6.4 + hooks: + - id: isort + files: .*.py + - repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + args: ["--line-length", "79", "-t", "py37"] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: check-ast + - id: check-case-conflict + - id: trailing-whitespace + - id: end-of-file-fixer + - id: debug-statements + - id: check-added-large-files + - id: check-docstring-first + - id: check-yaml + exclude: conda/meta.yaml + - repo: https://github.com/PyCQA/flake8 + rev: 3.8.4 + hooks: + - id: flake8 + - repo: https://github.com/PyCQA/bandit + rev: 1.6.2 + hooks: + - id: bandit diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e57c995428a..be93c06257f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,6 +24,13 @@ add their details to the [Code Contributors](#code-contributors) section of this file as part of their first Pull Request, and reviewers are responsible for checking this before merging the new branch into *master*. +To start modifying cylc-flow and test your changes, first call +`pip install -e .[all]` to install the package in development mode along with +all dependencies. Then call `pre-commit install` so that the git pre-commit +hooks will run on commit. [pre-commit ](https://pre-commit.com) is used for +code style consistency. It can also be run manually with the `pre-commit run` +command (use --files to run on a reduced set of files). + ## Code Contributors The following people have contributed to this code under the terms of diff --git a/setup.py b/setup.py index 9ffeb8841f4..638150f05fd 100644 --- a/setup.py +++ b/setup.py @@ -88,6 +88,9 @@ def find_version(*file_paths): 'main_loop-log_memory': [ 'pympler', 'matplotlib' + ], + "dev": [ + "pre-commit" ] } extra_requires['all'] = ( diff --git a/tests/functional/jinja2/filters/Jinja2Filters/truly.py b/tests/functional/jinja2/filters/Jinja2Filters/truly.py index bc71ec7f1ba..6b0359ec9d5 100644 --- a/tests/functional/jinja2/filters/Jinja2Filters/truly.py +++ b/tests/functional/jinja2/filters/Jinja2Filters/truly.py @@ -14,5 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + def truly(bar): return 'true' diff --git a/tests/functional/validate/68-trailing_whitespace.t b/tests/functional/validate/68-trailing_whitespace.t index 32e1201cab9..3ef9bf46d50 100644 --- a/tests/functional/validate/68-trailing_whitespace.t +++ b/tests/functional/validate/68-trailing_whitespace.t @@ -27,8 +27,8 @@ cat >'flow.cylc' <<'__FLOW_CONFIG__' final cycle point = 20010101T18 [[graph]] T00 = """ - # NOTE: don't let editor strip trailing space on next line - foo | bar \ + # pre-commit hook removes trailing space so add it with sed below + foo | bar BACKSLASH_TRAILING_WHITESPACE => baz & qux pub """ @@ -38,6 +38,8 @@ cat >'flow.cylc' <<'__FLOW_CONFIG__' """ __FLOW_CONFIG__ +sed -i 's/BACKSLASH_TRAILING_WHITESPACE/\\ /' 'flow.cylc' + run_fail "${TEST_NAME_BASE}-simple-fail" cylc validate 'flow.cylc' cmp_ok "${TEST_NAME_BASE}-simple-fail.stderr" <<'__ERR__' FileParseError: Syntax error line 7: Whitespace after the line continuation character (\). diff --git a/tox.ini b/tox.ini index 4172f0e826b..5836d9f6cbe 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,9 @@ [pycodestyle] +; E402 module level import not at top of file +; W503/4 line break before/after binary operator ignore= - ; module level import not at top of file E402, - ; line break before binary operator W503, - ; line break after binary operator W504 exclude= .git,