Bumped flake8

- Upgraded hacking(flake8)
- Added more modern tox linters environment (pep8 alias)
- Temporary added skips for broken newer rules
- Fixed few basic rule violations
- Moved flake8 config to setup.cfg (tox.ini is not recommended)

Change-Id: I75b3ce5d2ce965a9dc5bdfaa49b2aacd8f0195ad
This commit is contained in:
Sorin Sbarnea 2020-05-19 17:59:26 +01:00
parent 6fc19ee5b9
commit f68a8719af
9 changed files with 41 additions and 25 deletions

View File

@ -15,8 +15,9 @@
# under the License.
# The configuration file should look like:
"""
The configuration file should look like:
```
[ircbot]
nick=NICKNAME
pass=PASSWORD
@ -31,16 +32,16 @@ user=gerrit2
[data_source[
es_url=URLofELASTICSEARCH
db_uri=SQLALCHEMY_URI_TO_SUBUNIT2SQL
"""
```
# The yaml channel config should look like:
"""
```
openstack-qa:
events:
- positive
- negative
```
"""
import argparse
import daemon
import os

View File

@ -12,9 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from six.moves import configparser
import os
import re
from six.moves import configparser
DEFAULT_INDEX_FORMAT = 'logstash-%Y.%m.%d'
@ -52,9 +52,9 @@ INCLUDED_PROJECTS_REGEX = "(^openstack/|devstack|grenade)"
# Let's value legibility over pep8 line width here...
ALL_FAILS_QUERY = (
'('
'(filename:"job-output.txt" AND message:"POST-RUN END" AND message:"playbooks/base/post.yaml")' # flake8: noqa
'(filename:"job-output.txt" AND message:"POST-RUN END" AND message:"playbooks/base/post.yaml")' # noqa E501
' OR '
'(filename:"console.html" AND (message:"[Zuul] Job complete" OR message:"[SCP] Copying console log" OR message:"Grabbing consoleLog"))' # flake8: noqa
'(filename:"console.html" AND (message:"[Zuul] Job complete" OR message:"[SCP] Copying console log" OR message:"Grabbing consoleLog"))' # noqa E501
')'
' AND build_status:"FAILURE"'
' AND build_queue:"gate"'
@ -130,7 +130,8 @@ class Config(object):
if config.has_section('gerrit'):
self.gerrit_user = config.get('gerrit', 'user')
self.gerrit_query_file = config.get('gerrit', 'query_file')
# workaround for python api change https://docs.python.org/3/library/configparser.html#fallback-values
# workaround for python api change:
# https://docs.python.org/3/library/configparser.html#fallback-values
try:
self.gerrit_host = config.get('gerrit',
'host',

View File

@ -227,7 +227,7 @@ class Stream(object):
# these items. It's orthoginal to non voting ES searching.
if " (non-voting)" in line:
continue
m = re.search("- ([\w-]+)\s*(http://\S+)\s*:\s*FAILURE", line)
m = re.search(r"- ([\w-]+)\s*(http://\S+)\s*:\s*FAILURE", line)
if m:
failed_tests.append(FailJob(m.group(1), m.group(2)))
return failed_tests

View File

@ -78,9 +78,9 @@ def result_ready(change, patchset, name, short_uuid):
# TODO(dmsimard): Revisit this query once Zuul v2 is no longer supported
# Let's value legibility over pep8 line width here...
query = (
'((filename:"job-output.txt" AND message:"POST-RUN END" AND message:"project-config/playbooks/base/post-ssh.yaml")' # flake8: noqa
'((filename:"job-output.txt" AND message:"POST-RUN END" AND message:"project-config/playbooks/base/post-ssh.yaml")' # noqa E501
' OR '
'(filename:"console.html" AND (message:"[Zuul] Job complete" OR message:"[SCP] Copying console log" OR message:"Grabbing consoleLog")))' # flake8: noqa
'(filename:"console.html" AND (message:"[Zuul] Job complete" OR message:"[SCP] Copying console log" OR message:"Grabbing consoleLog")))' # noqa E501
' AND build_status:"FAILURE"'
' AND build_change:"{change}"'
' AND build_patchset:"{patchset}"'

View File

@ -50,3 +50,16 @@ input_file = elastic_recheck/locale/elastic-recheck.pot
keywords = _ gettext ngettext l_ lazy_gettext
mapping_file = babel.cfg
output_file = elastic_recheck/locale/elastic-recheck.pot
[flake8]
ignore =
# These are ignored intentionally in infra projects;
# please don't submit patches that solely correct them or enable them.
E124,E125,E129,E252,E402,E741,H,W503,W504
# TODO(ssbarnea): Remove temporary added ignores during flake8 upgrade:
E123 # E123 closing bracket does not match indentation of opening bracket's line
F632 # F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)
N802 # N802 function name {} should be lowercase
N806 # N806 variable '{}' in function should be lowercase
N813 # N813 camelcase '{}' imported as lowercase '{}'
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build

View File

@ -1,4 +1,4 @@
hacking>=0.12.0,!=0.13.0,<0.14
hacking>=3.1.0,<3.2.0; python_version>='3.5'
coverage>=3.6
fixtures>=3.0.0
python-subunit

View File

@ -74,7 +74,7 @@ def collect_rechecks(gerrit, days="14"):
# bail early if the comment is outside the ER window
continue
m = re.search('recheck (no bug|bug (\#)?(?P<bugno>\d+))$',
m = re.search(r'recheck (no bug|bug (\#)?(?P<bugno>\d+))$',
comment['message'])
if m:
dev = None
@ -130,5 +130,6 @@ def main():
changes = cross_ref_with_er(changes, opts.dir)
summarize_changes(changes)
if __name__ == "__main__":
main()

23
tox.ini
View File

@ -1,6 +1,6 @@
[tox]
minversion = 1.6
envlist = pep8,py37,py36,py27,queries,docs
envlist = linters,py38,py37,py36,py27,queries,docs
skipsdist = True
[testenv]
@ -20,10 +20,6 @@ commands = python setup.py testr --slowest --testr-args='{posargs} tests.functio
basepython = python3
commands = python setup.py testr --slowest --testr-args='{posargs} tests.functional.test_queries'
[testenv:pep8]
basepython = python3
commands = flake8
[testenv:venv]
basepython = python3
commands = {posargs}
@ -37,13 +33,6 @@ basepython = python3
# test to run the bot as a non voting foreground process
commands = elastic-recheck -f -n --noirc elasticRecheck.conf
[flake8]
# E125 Skipped because it's an overreach (and anti-emacs)
# E123 Skipped because it decreases clarity in many cases
ignore = E123,E125
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build
[testenv:docs]
basepython = python3
deps = -r{toxinidir}/doc/requirements.txt
@ -57,3 +46,13 @@ basepython = python3
# separately, outside of the requirements files.
deps = bindep
commands = bindep test
[testenv:linters]
basepython = python3
commands = flake8
# deprecated, use linters instead
[testenv:pep8]
basepython = python3
envdir = {toxworkdir}/linters
commands = {[testenv:linters]commands}

View File

@ -97,6 +97,7 @@ def main():
while True:
httpd.handle_request()
if __name__ == '__main__':
try:
main()