diff --git a/contrib/zoneextractor.py b/contrib/zoneextractor.py index 5684a648b..461101005 100644 --- a/contrib/zoneextractor.py +++ b/contrib/zoneextractor.py @@ -15,6 +15,7 @@ # under the License. import argparse +import io import logging import os import re @@ -39,7 +40,7 @@ class Zone: self.to_file(sys.stdout) def to_file(self, f): - if type(f) == 'file': + if isinstance(f, io.IOBase): fd = f elif type(f) is str: if os.path.isdir(f): diff --git a/designate/hacking/checks.py b/designate/hacking/checks.py index c840a03d3..4bdd18f16 100644 --- a/designate/hacking/checks.py +++ b/designate/hacking/checks.py @@ -15,7 +15,6 @@ import re from hacking import core -import pycodestyle # D701: Default parameter value is a mutable type # D702: Log messages require translation @@ -49,8 +48,8 @@ no_line_continuation_backslash_re = re.compile(r'.*(\\)\n') @core.flake8ext -def mutable_default_arguments(physical_line, logical_line, filename): - if pycodestyle.noqa(physical_line): +def mutable_default_arguments(logical_line, filename, noqa): + if noqa: return if mutable_default_argument_check.match(logical_line): @@ -69,7 +68,7 @@ def no_translate_debug_logs(logical_line, filename): N319 """ if logical_line.startswith("LOG.debug(_("): - yield(0, "D706: Don't translate debug level logs") + yield (0, "D706: Don't translate debug level logs") @core.flake8ext @@ -90,7 +89,7 @@ def check_explicit_underscore_import(logical_line, filename): UNDERSCORE_IMPORT_FILES.append(filename) elif (translated_log.match(logical_line) or string_translation.match(logical_line)): - yield(0, "D703: Found use of _() without explicit import of _!") + yield (0, "D703: Found use of _() without explicit import of _!") @core.flake8ext @@ -109,8 +108,8 @@ def no_import_graduated_oslo_libraries(logical_line, filename): matches = graduated_oslo_libraries_import_re.match(logical_line) if matches: - yield(0, "D704: Found import of %s. This oslo library has been " - "graduated!" % matches.group(1)) + yield (0, "D704: Found import of %s. This oslo library has been " + "graduated!" % matches.group(1)) @core.flake8ext @@ -133,14 +132,14 @@ def check_no_basestring(logical_line): if re.search(r"\bbasestring\b", logical_line): msg = ("D707: basestring is not Python3-compatible, use " "str instead.") - yield(0, msg) + yield (0, msg) @core.flake8ext def check_python3_xrange(logical_line): if re.search(r"\bxrange\s*\(", logical_line): - yield(0, "D708: Do not use xrange. Use range for " - "large loops.") + yield (0, "D708: Do not use xrange. Use range for " + "large loops.") @core.flake8ext @@ -152,7 +151,7 @@ def check_no_log_audit(logical_line): for OpenStack we can enforce not using it. """ if "LOG.audit(" in logical_line: - yield(0, "D709: LOG.audit is deprecated, please use LOG.info!") + yield (0, "D709: LOG.audit is deprecated, please use LOG.info!") @core.flake8ext @@ -162,7 +161,7 @@ def check_no_log_warn(logical_line): D710 """ if logical_line.startswith('LOG.warn('): - yield(0, "D710:Use LOG.warning() rather than LOG.warn()") + yield (0, "D710:Use LOG.warning() rather than LOG.warn()") @core.flake8ext diff --git a/designate/storage/sqlalchemy/utils.py b/designate/storage/sqlalchemy/utils.py index cfea166b9..17e563177 100644 --- a/designate/storage/sqlalchemy/utils.py +++ b/designate/storage/sqlalchemy/utils.py @@ -88,7 +88,7 @@ def sort_query(query, table, sort_keys, sort_dir=None, sort_dirs=None): # the actual primary key, rather than assuming its id LOG.warning('Id not in sort_keys; is sort_keys unique?') - assert(not (sort_dir and sort_dirs)) + assert (not (sort_dir and sort_dirs)) # Default the sort direction to ascending if sort_dirs is None and sort_dir is None: @@ -98,7 +98,7 @@ def sort_query(query, table, sort_keys, sort_dir=None, sort_dirs=None): if sort_dirs is None: sort_dirs = [sort_dir for _sort_key in sort_keys] - assert(len(sort_dirs) == len(sort_keys)) + assert (len(sort_dirs) == len(sort_keys)) for current_sort_key, current_sort_dir in zip(sort_keys, sort_dirs): try: diff --git a/requirements.txt b/requirements.txt index d26721f30..0442618b4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,6 @@ # Requirements lower bounds listed here are our best effort to keep them up to # date but we do not test them so no guarantee of having them all correct. If # you find any incorrect lower bounds, let us know or propose a fix. - -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. alembic>=1.8.0 # MIT eventlet>=0.26.1 # MIT Flask!=0.11,>=0.10 # BSD diff --git a/test-requirements.txt b/test-requirements.txt index 673ad81b2..99173e7ae 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,9 +1,5 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. - # Hacking already pins down pep8, pyflakes and flake8 -hacking>=4.1.0,<4.2.0 # Apache-2.0 +hacking>=6.1.0,<6.2.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD stestr>=2.0.0 # Apache-2.0 diff --git a/tools/pretty_flake8.py b/tools/pretty_flake8.py deleted file mode 100755 index ccf600a82..000000000 --- a/tools/pretty_flake8.py +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright 2015 Hewlett-Packard Development Company, L.P. -# -# 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. - -import re -import sys -import linecache - -from prettytable import PrettyTable - -PEP8_LINE = r'^((?P.*):(?P\d*):(?P\d*):) ' \ - r'(?P(?P\w\d{1,3})(?P.*$))' - -HTML = True - - -def main(): - - raw_errors = [] - - max_filename_len = 0 - for line in sys.stdin: - m = re.match(PEP8_LINE, line) - if m: - m = m.groupdict() - raw_errors.append(m) - if len(m['file']) > max_filename_len: - max_filename_len = len(m['file']) - else: - print(line) - - if len(raw_errors) > 0: - - print('Flake8 Results') - - ct = PrettyTable([ - "File", - "Line", - "Column", - "Error Code", - "Error Message", - "Code" - ]) - - ct.align["File"] = "l" - ct.align["Error Message"] = "l" - ct.align["Code"] = "l" - - for line in raw_errors: - ct.add_row(format_dict(line)) - - print(ct) - - with open('flake8_results.html', 'w') as f: - f.write('%s' % ct.get_html_string(attributes = {"cellspacing": 0})) # noqa - - -def format_dict(raw): - output = [] - if raw['file'].startswith('./'): - output.append(raw['file'][2:]) - else: - output.append(raw['file']) - - output.append(raw['line']) - output.append(raw['col']) - output.append(raw['error_code']) - - output.append(raw['error_desc'].lstrip()) - - code_string = linecache.getline( - output[0], - int(raw['line'])).lstrip().rstrip() - - output.append(code_string) - - return output - -if __name__ == '__main__': - sys.exit(main()) diff --git a/tools/pretty_flake8.sh b/tools/pretty_flake8.sh deleted file mode 100755 index b552383a3..000000000 --- a/tools/pretty_flake8.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -TESTARGS=$1 - -exec 3>&1 -status=$(exec 4>&1 >&3; ( flake8 ; echo $? >&4 ) | python tools/pretty_flake8.py) && exit $status diff --git a/tox.ini b/tox.ini index 394af8f84..cbc7ac7b2 100644 --- a/tox.ini +++ b/tox.ini @@ -82,12 +82,14 @@ commands = oslo_debug_helper -t designate/tests {posargs} [testenv:flake8] deps = -r{toxinidir}/test-requirements.txt -commands = sh tools/pretty_flake8.sh +commands = + flake8 {[testenv:bandit]commands} [testenv:pep8] deps = -r{toxinidir}/test-requirements.txt -commands = sh tools/pretty_flake8.sh +commands = + flake8 {[testenv:bandit]commands} doc8 {posargs}