From 3063b3a8132d6f75dd0625d80bd985e48ab0dda7 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Fri, 15 Nov 2019 12:21:09 -0500 Subject: [PATCH] Move pep8 to pre-commit This final patch removes our dependency on coala which hasn't had a release in quite some time. Change-Id: Idf43965822f7ece83143fb7fa8c3ddda1175355a Signed-off-by: Thanh Ha --- .coafile | 5 ----- .flake8 | 18 ++++++++++++++++++ .pre-commit-config.yaml | 12 ++++++++++++ tools/fastbgp/play.py | 15 +++++++++------ tox.ini | 38 +------------------------------------- 5 files changed, 40 insertions(+), 48 deletions(-) delete mode 100644 .coafile create mode 100644 .flake8 diff --git a/.coafile b/.coafile deleted file mode 100644 index 5b849f5614..0000000000 --- a/.coafile +++ /dev/null @@ -1,5 +0,0 @@ -[Python] -bears = PEP8Bear -files = **/*.py -ignore = .*/** -max_line_length = 120 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..5dca78bc9b --- /dev/null +++ b/.flake8 @@ -0,0 +1,18 @@ +[flake8] +show-source = True +max-line-length = 120 + +# # - Select E121, E123, E126, E226, E241, E242 and E704 which are turned OFF +# # by default but represent guidelines accepted by us. +# # - Do not select E133 because it is incompatible with E123 which was +# # selected instead. +# - It turns out that now all checks except E133 are enabled so the select +# can be simplified to be just "E,W". However a new version could change +# that (select E133 instead of E123) but that should be caught by the +# verify job. +select = E,W +ignore = E722,W503 # as of aprox 10/25 some update/change has caused existing code to fail on E722 +exclude = + .git, + .tox, + docs/conf.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b726c5a881..2598d437f6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,16 @@ --- +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 # Use the ref you want to point at + hooks: + - id: flake8 + language_version: python2 + additional_dependencies: ['flake8~=3.5.0'] + +- repo: https://github.com/pre-commit/mirrors-autopep8 + rev: v1.4.4 + hooks: + - id: autopep8 + - repo: git://github.com/guykisel/pre-commit-robotframework-tidy rev: 'master' hooks: diff --git a/tools/fastbgp/play.py b/tools/fastbgp/play.py index d04e2e75e7..d82cbab007 100755 --- a/tools/fastbgp/play.py +++ b/tools/fastbgp/play.py @@ -407,9 +407,11 @@ class MessageGenerator(object): s1_slots = ((self.total_prefix_amount - self.remaining_prefixes_threshold - 1) / self.prefix_count_to_add_default + 1) - s2_slots = ((self.remaining_prefixes_threshold - 1) / - (self.prefix_count_to_add_default - - self.prefix_count_to_del_default) + 1) + s2_slots = ( + (self.remaining_prefixes_threshold - 1) + / (self.prefix_count_to_add_default - self.prefix_count_to_del_default) + + 1 + ) # S1_First_Index = 0 # S1_Last_Index = s1_slots * self.prefix_count_to_add_default - 1 s2_first_index = s1_slots * self.prefix_count_to_add_default @@ -715,9 +717,10 @@ class MessageGenerator(object): if not self.phase2_start_time: self.phase2_start_time = time.time() # tailor the number of prefixes if needed - prefix_count_to_add = (prefix_count_to_del + - min(prefix_count_to_add - prefix_count_to_del, - self.remaining_prefixes)) + prefix_count_to_add = ( + prefix_count_to_del + + min(prefix_count_to_add - prefix_count_to_del, self.remaining_prefixes) + ) # prefix slots selection for insertion and withdrawal slot_index_to_add = self.iteration slot_index_to_del = slot_index_to_add - self.slot_gap_default diff --git a/tox.ini b/tox.ini index 6a44828918..d2f1dbcfd7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,20 +1,9 @@ [tox] minversion = 1.6.0 -envlist = coala,pep8,pre-commit +envlist = docs,pre-commit # TODO: Include docs when it starts performing strict checks. skipsdist = true -[testenv:coala] -basepython = python3 -deps = - coala==0.11.0 - coala-bears==0.11.0 - pygments~=2.3.1 - requests==2.15.1 -commands = - python3 -m nltk.downloader punkt maxent_treebank_pos_tagger averaged_perceptron_tagger - coala --non-interactive - [testenv:docs] basepython = python3 deps = -rdocs/requirements.txt @@ -27,28 +16,3 @@ deps = pre-commit commands = pre-commit install pre-commit run --all-files - -[testenv:pep8] -basepython = python2 -deps = - flake8~=3.5.0 -commands = flake8 - -[flake8] -show-source = True -max-line-length = 120 - -# # - Select E121, E123, E126, E226, E241, E242 and E704 which are turned OFF -# # by default but represent guidelines accepted by us. -# # - Do not select E133 because it is incompatible with E123 which was -# # selected instead. -# - It turns out that now all checks except E133 are enabled so the select -# can be simplified to be just "E,W". However a new version could change -# that (select E133 instead of E123) but that should be caught by the -# verify job. -select = E,W -ignore = E722 # as of aprox 10/25 some update/change has caused existing code to fail on E722 -exclude = - .git, - .tox, - docs/conf.py -- 2.36.6