summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2023-03-11 04:35:22 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-20 20:37:24 +0000
commit1604cf255f8c1786a23388db6d5277ac7949a24a (patch)
tree4bb894bb16fb4a6c65c21335ba14c6ab2a27887a
parent75eb8ea9354cfcecfaf185a37a10ad2c8b4cd0d2 (diff)
downloadgit-repo-1604cf255f8c1786a23388db6d5277ac7949a24a.tar.gz
Make black with line length 80 repo's code style
Provide a consistent formatting style and tox commands to lint and format. Bug: b/267675342 Change-Id: I33ddfe07af8473f4334c347d156246bfb66d4cfe Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/362954 Reviewed-by: Josip Sokcevic <sokcevic@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
-rw-r--r--.flake815
-rw-r--r--SUBMITTING_PATCHES.md24
-rw-r--r--pyproject.toml18
-rw-r--r--tox.ini20
4 files changed, 58 insertions, 19 deletions
diff --git a/.flake8 b/.flake8
index 6b824e97..82453b56 100644
--- a/.flake8
+++ b/.flake8
@@ -1,15 +1,10 @@
1[flake8] 1[flake8]
2max-line-length=100 2max-line-length = 80
3ignore= 3extend-ignore =
4 # E111: Indentation is not a multiple of four 4 # E203: Whitespace before ':'
5 E111, 5 # See https://github.com/PyCQA/pycodestyle/issues/373
6 # E114: Indentation is not a multiple of four (comment) 6 E203,
7 E114,
8 # E402: Module level import not at top of file 7 # E402: Module level import not at top of file
9 E402, 8 E402,
10 # E731: do not assign a lambda expression, use a def 9 # E731: do not assign a lambda expression, use a def
11 E731, 10 E731,
12 # W503: Line break before binary operator
13 W503,
14 # W504: Line break after binary operator
15 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 @@
4 4
5 - Make small logical changes. 5 - Make small logical changes.
6 - [Provide a meaningful commit message][commit-message-style]. 6 - [Provide a meaningful commit message][commit-message-style].
7 - Check for coding errors and style nits with flake8.
8 - Make sure all code is under the Apache License, 2.0. 7 - Make sure all code is under the Apache License, 2.0.
9 - Publish your changes for review. 8 - Publish your changes for review.
10 - Make corrections if requested. 9 - Make corrections if requested.
@@ -39,17 +38,26 @@ If your description starts to get too long, that's a sign that you
39probably need to split up your commit to finer grained pieces. 38probably need to split up your commit to finer grained pieces.
40 39
41 40
42## Check for coding errors and style violations with flake8 41## Linting and formatting code
43 42
44Run `flake8` on changed modules: 43Lint any changes by running:
44```sh
45$ tox -e lint -- file.py
46```
45 47
46 flake8 file.py 48And format with:
49```sh
50$ tox -e format -- file.py
51```
47 52
48Note that repo generally follows [Google's Python Style Guide] rather than 53Or format everything:
49[PEP 8], with a couple of notable exceptions: 54```sh
55$ tox -e format
56```
50 57
51* Indentation is at 2 columns rather than 4 58Repo uses [black](https://black.readthedocs.io/) with line length of 80 as its
52* The maximum line length is 100 columns rather than 80 59formatter and flake8 as its linter. Repo also follows
60[Google's Python Style Guide].
53 61
54There should be no new errors or warnings introduced. 62There should be no new errors or warnings introduced.
55 63
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 00000000..8ff3570f
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,18 @@
1# Copyright 2023 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15[tool.black]
16line-length = 80
17# NB: Keep in sync with tox.ini.
18target-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 @@
15# https://tox.readthedocs.io/ 15# https://tox.readthedocs.io/
16 16
17[tox] 17[tox]
18envlist = py36, py37, py38, py39, py310 18envlist = lint, py36, py37, py38, py39, py310
19 19
20[gh-actions] 20[gh-actions]
21python = 21python =
@@ -35,5 +35,23 @@ setenv =
35 GIT_COMMITTER_NAME = Repo test committer 35 GIT_COMMITTER_NAME = Repo test committer
36 EMAIL = repo@gerrit.nodomain 36 EMAIL = repo@gerrit.nodomain
37 37
38[testenv:lint]
39skip_install = true
40deps =
41 black
42 flake8
43commands =
44 black --check {posargs:.}
45 flake8
46
47[testenv:format]
48skip_install = true
49deps =
50 black
51 flake8
52commands =
53 black {posargs:.}
54 flake8
55
38[pytest] 56[pytest]
39timeout = 300 57timeout = 300