diff --git a/.flake8 b/.flake8 index 6b824e97..82453b56 100644 --- a/.flake8 +++ b/.flake8 @@ -1,15 +1,10 @@ [flake8] -max-line-length=100 -ignore= - # E111: Indentation is not a multiple of four - E111, - # E114: Indentation is not a multiple of four (comment) - E114, +max-line-length = 80 +extend-ignore = + # E203: Whitespace before ':' + # See https://github.com/PyCQA/pycodestyle/issues/373 + E203, # E402: Module level import not at top of file E402, # E731: do not assign a lambda expression, use a def E731, - # W503: Line break before binary operator - W503, - # W504: Line break after binary operator - W504 diff --git a/SUBMITTING_PATCHES.md b/SUBMITTING_PATCHES.md index 76c167c3..df245a52 100644 --- a/SUBMITTING_PATCHES.md +++ b/SUBMITTING_PATCHES.md @@ -4,7 +4,6 @@ - Make small logical changes. - [Provide a meaningful commit message][commit-message-style]. - - Check for coding errors and style nits with flake8. - Make sure all code is under the Apache License, 2.0. - Publish your changes for review. - Make corrections if requested. @@ -39,17 +38,26 @@ If your description starts to get too long, that's a sign that you probably need to split up your commit to finer grained pieces. -## Check for coding errors and style violations with flake8 +## Linting and formatting code -Run `flake8` on changed modules: +Lint any changes by running: +```sh +$ tox -e lint -- file.py +``` - flake8 file.py +And format with: +```sh +$ tox -e format -- file.py +``` -Note that repo generally follows [Google's Python Style Guide] rather than -[PEP 8], with a couple of notable exceptions: +Or format everything: +```sh +$ tox -e format +``` -* Indentation is at 2 columns rather than 4 -* The maximum line length is 100 columns rather than 80 +Repo uses [black](https://black.readthedocs.io/) with line length of 80 as its +formatter and flake8 as its linter. Repo also follows +[Google's Python Style Guide]. There should be no new errors or warnings introduced. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..8ff3570f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +# Copyright 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +[tool.black] +line-length = 80 +# NB: Keep in sync with tox.ini. +target-version = ['py36', 'py37', 'py38', 'py39', 'py310'] diff --git a/tox.ini b/tox.ini index 9a8b3fc9..8d3cc43c 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ # https://tox.readthedocs.io/ [tox] -envlist = py36, py37, py38, py39, py310 +envlist = lint, py36, py37, py38, py39, py310 [gh-actions] python = @@ -35,5 +35,23 @@ setenv = GIT_COMMITTER_NAME = Repo test committer EMAIL = repo@gerrit.nodomain +[testenv:lint] +skip_install = true +deps = + black + flake8 +commands = + black --check {posargs:.} + flake8 + +[testenv:format] +skip_install = true +deps = + black + flake8 +commands = + black {posargs:.} + flake8 + [pytest] timeout = 300