From 1c98c456b5b147aebc65bd9bd8ed87797cac4e3a Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 15 Mar 2017 17:08:53 -0400 Subject: [PATCH] add flake8 to the linter job Turn on flake8 for code style checks, like in our other repos. Fix or explicitly ignore various issues to allow the linter job to pass. Change-Id: I7bfd8cf5e9c00dfa83c0393a4307fd54d2113047 Signed-off-by: Doug Hellmann --- doc/source/_exts/atcs.py | 6 ++---- doc/source/_exts/badges.py | 21 ++++++++++--------- doc/source/_exts/members.py | 7 ++++--- doc/source/conf.py | 2 ++ .../extract.py | 1 - setup.cfg | 5 ++++- test-requirements.txt | 1 + tools/build_team_section_for_goal.py | 2 +- tools/teamstats.py | 3 ++- tools/validate_tags.py | 2 +- tox.ini | 4 +++- 11 files changed, 31 insertions(+), 23 deletions(-) diff --git a/doc/source/_exts/atcs.py b/doc/source/_exts/atcs.py index 77fcaf96b..29443418a 100644 --- a/doc/source/_exts/atcs.py +++ b/doc/source/_exts/atcs.py @@ -19,6 +19,7 @@ import re from docutils import nodes from docutils.parsers.rst import directives from docutils.parsers.rst.directives import tables +from docutils.utils import SystemMessagePropagation import projects @@ -40,9 +41,6 @@ class ExtraATCsTable(tables.Table): } def run(self): - env = self.state.document.settings.env - app = env.app - project = self.options.get('project') if not project: error = self.state_machine.reporter.error( @@ -62,7 +60,7 @@ class ExtraATCsTable(tables.Table): 'Error processing memberstable directive:\n%s' % err, nodes.literal_block(self.block_text, self.block_text), line=self.lineno, - ) + ) return [error] all_teams = projects.get_project_data() diff --git a/doc/source/_exts/badges.py b/doc/source/_exts/badges.py index bb44451fe..a3e18830b 100644 --- a/doc/source/_exts/badges.py +++ b/doc/source/_exts/badges.py @@ -14,9 +14,9 @@ Generate badges for the projects """ -import os from itertools import chain from itertools import zip_longest +import os from PIL import ImageFont @@ -26,15 +26,15 @@ import projects PADDING = 8 BASE_TAGS_URL = 'https://governance.openstack.org/tc/reference/tags/' COLOR_SCHEME = { - "brightgreen": "#4c1", - "green": "#97CA00", - "yellow": "#dfb317", - "yellowgreen": "#a4a61d", - "orange": "#fe7d37", - "red": "#e05d44", - "blue": "#007ec6", - "grey": "#555", - "lightgrey": "#9f9f9f", + "brightgreen": "#4c1", + "green": "#97CA00", + "yellow": "#dfb317", + "yellowgreen": "#a4a61d", + "orange": "#fe7d37", + "red": "#e05d44", + "blue": "#007ec6", + "grey": "#555", + "lightgrey": "#9f9f9f", } SVG_ROOT = """ @@ -155,6 +155,7 @@ def _organize_badges(badges): result[y].append(badge) return result + def _to_svg(badges): for badge in badges: yield FLAT_BADGE_TEMPLATE.format(**badge) diff --git a/doc/source/_exts/members.py b/doc/source/_exts/members.py index f6fd04272..d4662665b 100644 --- a/doc/source/_exts/members.py +++ b/doc/source/_exts/members.py @@ -16,8 +16,9 @@ import re from docutils import nodes -from docutils.parsers.rst.directives import tables from docutils.parsers.rst import directives +from docutils.parsers.rst.directives import tables +from docutils.utils import SystemMessagePropagation # Full name (IRC nickname) [expires in] {role} _PATTERN = re.compile('(?P.*)\s+\((?P.*)\)\s+\[(?P.*)\](\s+\{(?P.*)\})?') @@ -61,7 +62,6 @@ class MembersTable(tables.Table): def run(self): env = self.state.document.settings.env app = env.app - config = app.config # The required argument to the directive is the name of the # file to parse. @@ -84,7 +84,7 @@ class MembersTable(tables.Table): 'Error processing memberstable directive:\n%s' % err, nodes.literal_block(self.block_text, self.block_text), line=self.lineno, - ) + ) return [error] # Now find the real path to the file, relative to where we are. @@ -146,6 +146,7 @@ class MembersTable(tables.Table): return table + def setup(app): app.info('loading members extension') app.add_directive('memberstable', MembersTable) diff --git a/doc/source/conf.py b/doc/source/conf.py index 342c3e17d..ec02345ff 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -11,6 +11,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. +# flake8: noqa + import sys import os diff --git a/resolutions/20140617-defcore-capabilities-scoring/extract.py b/resolutions/20140617-defcore-capabilities-scoring/extract.py index c90a6a4dd..108dfaad2 100644 --- a/resolutions/20140617-defcore-capabilities-scoring/extract.py +++ b/resolutions/20140617-defcore-capabilities-scoring/extract.py @@ -3,7 +3,6 @@ """ import csv -import sys with open('defcore.csv', 'r') as infile: reader = csv.reader(infile) diff --git a/setup.cfg b/setup.cfg index a972bd66f..06313a4cb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,4 +14,7 @@ build-dir = doc/build source-dir = doc/source [pbr] -warnerrors = True \ No newline at end of file +warnerrors = True + +[flake8] +ignore = E501,E226,H405 \ No newline at end of file diff --git a/test-requirements.txt b/test-requirements.txt index 0fad50ff3..d04d10835 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,3 +5,4 @@ PyYAML>=3.1.0 yamllint>=0.5.2 requests-cache Pillow>=2.4.0 # PIL License +hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 diff --git a/tools/build_team_section_for_goal.py b/tools/build_team_section_for_goal.py index 9165c7322..6bf4c522f 100755 --- a/tools/build_team_section_for_goal.py +++ b/tools/build_team_section_for_goal.py @@ -29,7 +29,7 @@ def main(): parser = argparse.ArgumentParser( 'build the "Project Teams" section of a goal document', ) - args = parser.parse_args() + parser.parse_args() print('Paste this output to the end of the goals file:\n') diff --git a/tools/teamstats.py b/tools/teamstats.py index 669d6fa59..09cbf3a9a 100644 --- a/tools/teamstats.py +++ b/tools/teamstats.py @@ -120,6 +120,7 @@ def get_core_reviews_by_company(group): return companies + @_memoize def get_diversity_stats(project): team_stats = {} @@ -177,7 +178,7 @@ def get_diversity_stats(project): if core_reviewers_total else 0) team_stats['core_reviewers_top2'] = ( ((float(core_reviewers_values[0]) + float(core_reviewers_values[1])) / - core_reviewers_total * 100) if core_reviewers_total else 0) + core_reviewers_total * 100) if core_reviewers_total else 0) return team_stats diff --git a/tools/validate_tags.py b/tools/validate_tags.py index f553bf6da..5749098fb 100755 --- a/tools/validate_tags.py +++ b/tools/validate_tags.py @@ -37,7 +37,7 @@ team_validators = [ ] # List of modules to validate repository based tags -repo_validators = [ ] +repo_validators = [] def main(): diff --git a/tox.ini b/tox.ini index ebcea5918..3505bcfd9 100644 --- a/tox.ini +++ b/tox.ini @@ -12,11 +12,13 @@ deps = -r{toxinidir}/test-requirements.txt [testenv:linters] whitelist_externals = bash -commands = bash -c "find {toxinidir} \ +commands = + bash -c "find {toxinidir} \ \( -name .tox -prune \) \ -o -type f -name '*.yaml' \ -print0 | xargs -0 yamllint" {toxinidir}/tools/check_projects_yaml_alphabetized.sh + flake8 [testenv:venv] commands = {posargs}