From e7d7c1f4b76e112ed7e5d32cf4e053fb69cbc121 Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Tue, 5 Nov 2019 12:59:51 +0000 Subject: Add configuration to run Black Introduce two new tox environments - `format` and `format-check`. The `format` environment will reformat the code using `black` whereas the `format-check` envrionment will simply print the diff without modifying any files. Configure Black to use the same line lengths that we use currently, i.e. 119. --- pyproject.toml | 18 ++++++++++++++++++ tox.ini | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 4dd02d1e5..29f5589b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,3 +7,21 @@ requires = [ "Cython" ] build-backend = "setuptools.build_meta" + +[tool.black] +line-length = 119 +exclude = ''' +( + /( + \.eggs + | \.git + | \.mypy_cache + | \.tox + | _build + | build + | dist + )/ + | src/buildstream/_fuse + | src/buildstream/_protos +) +''' diff --git a/tox.ini b/tox.ini index 4c18f2c14..d8fa3e984 100644 --- a/tox.ini +++ b/tox.ini @@ -102,6 +102,26 @@ deps = setenv = COVERAGE_FILE = {toxinidir}/.coverage-reports/.coverage +# +# Code formatters +# +[testenv:format] +skip_install = True +deps = + black==19.10b0 +commands = + black {posargs: src tests} + +# +# Code format checkers +# +[testenv:format-check] +skip_install = True +deps = + black==19.10b0 +commands = + black --check --diff {posargs: src tests} + # # Running linters # -- cgit v1.2.1