Add pep8/flake8 checks, fix flake8 errors
We're starting to accumulate a number of python scripts in various parts of the tree, and probably will continue to do so. To make maintenance easier over time, we should have basic pep8/flake8 checks in place for python code, as is best practice elsewhere in the OpenStack project. This patch adds basic checks and corrects existing errors in our python scripts so that going forward we can opt to gate on clean python code. Change-Id: Ie32ee7a14ee608e12f42288e137a0849555b5ed8
This commit is contained in:
parent
19ac374a52
commit
c8138d4fa5
@ -1,13 +1,12 @@
|
||||
import json
|
||||
import urllib
|
||||
|
||||
capabilities_file = open('../2015.04.json','r')
|
||||
capabilities_file = open('../2015.04.json', 'r')
|
||||
defcore = json.loads(capabilities_file.read())
|
||||
capabilities = defcore['capabilities']
|
||||
required_tests = []
|
||||
flagged_tests = []
|
||||
|
||||
required_tests_file = open('2015.04.required.txt','w')
|
||||
required_tests_file = open('2015.04.required.txt', 'w')
|
||||
flagged_tests_file = open('2015.04.flagged.txt', 'w')
|
||||
|
||||
for capability_name in capabilities:
|
||||
|
@ -1,13 +1,12 @@
|
||||
import json
|
||||
import urllib
|
||||
|
||||
capabilities_file = open('../2015.05.json','r')
|
||||
capabilities_file = open('../2015.05.json', 'r')
|
||||
defcore = json.loads(capabilities_file.read())
|
||||
capabilities = defcore['capabilities']
|
||||
required_tests = []
|
||||
flagged_tests = []
|
||||
|
||||
required_tests_file = open('2015.05.required.txt','w')
|
||||
required_tests_file = open('2015.05.required.txt', 'w')
|
||||
flagged_tests_file = open('2015.05.flagged.txt', 'w')
|
||||
|
||||
for capability_name in capabilities:
|
||||
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
|
||||
defcore = json.loads(open('2015.next.json','r').read())
|
||||
new_caps = json.loads(open('newcaps.json','r').read())
|
||||
defcore = json.loads(open('2015.next.json', 'r').read())
|
||||
new_caps = json.loads(open('newcaps.json', 'r').read())
|
||||
|
||||
capabilities = {}
|
||||
|
||||
@ -56,4 +56,5 @@ for capability in capabilities:
|
||||
cap["required-since"] = ", ".join(cap["required-since"])
|
||||
cap["description"] = ", ".join(cap["description"])
|
||||
cap["project"] = ", ".join(cap["project"])
|
||||
print json.dumps(capabilities, sort_keys=True, indent=2, separators=(',', ': '))
|
||||
print json.dumps(capabilities, sort_keys=True, indent=2,
|
||||
separators=(',', ': '))
|
||||
|
21
tools/flake8wrap.sh
Executable file
21
tools/flake8wrap.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# A simple wrapper around flake8 which makes it possible
|
||||
# to ask it to only verify files changed in the current
|
||||
# git HEAD patch.
|
||||
#
|
||||
# Intended to be invoked via tox:
|
||||
#
|
||||
# tox -epep8 -- -HEAD
|
||||
#
|
||||
# Lovingly borrowed from openstack/nova.
|
||||
|
||||
if test "x$1" = "x-HEAD" ; then
|
||||
shift
|
||||
files=$(git diff --name-only HEAD~1 | tr '\n' ' ')
|
||||
echo "Running flake8 on ${files}"
|
||||
diff -u --from-file /dev/null ${files} | flake8 --diff "$@"
|
||||
else
|
||||
echo "Running flake8 on all files"
|
||||
exec flake8 "$@"
|
||||
fi
|
@ -66,9 +66,9 @@ with open(outFileName, "w") as outFile:
|
||||
|
||||
line01 = "OpenStack DefCore %s" % data["id"]
|
||||
|
||||
outFile.write('='*len(line01) + '\n')
|
||||
outFile.write('=' * len(line01) + '\n')
|
||||
outFile.write(line01 + '\n')
|
||||
outFile.write('='*len(line01) + '\n')
|
||||
outFile.write('=' * len(line01) + '\n')
|
||||
|
||||
# Nonlooping
|
||||
if data.get('platform') is None:
|
||||
@ -76,7 +76,8 @@ with open(outFileName, "w") as outFile:
|
||||
sys.exit(1)
|
||||
|
||||
# Correct Source
|
||||
if data.get('source') != 'http://git.openstack.org/cgit/openstack/defcore/':
|
||||
if data.get('source') != \
|
||||
'http://git.openstack.org/cgit/openstack/defcore/':
|
||||
print "The expected DefCore source not found"
|
||||
sys.exit(1)
|
||||
|
||||
@ -128,7 +129,7 @@ Platform Components
|
||||
|
||||
{component} Component Capabilities
|
||||
""".format(component=component.capitalize()))
|
||||
outFile.write('='*(len(component) + 23)) # footer
|
||||
outFile.write('=' * (len(component) + 23)) # footer
|
||||
|
||||
for event in order:
|
||||
|
||||
@ -142,7 +143,8 @@ Platform Components
|
||||
for req in data['components'][component][event]:
|
||||
outFile.write("* {name} ({project})\n".format(
|
||||
name=req,
|
||||
project=data["capabilities"][req].get("project").capitalize()))
|
||||
project=data["capabilities"][req].get(
|
||||
"project").capitalize()))
|
||||
|
||||
# Designated -Sections
|
||||
|
||||
@ -164,7 +166,7 @@ this specification.""")
|
||||
outFile.write('\n\n{event} Designated Sections\n'.format(
|
||||
event=event.capitalize()))
|
||||
# +20 is for length of header
|
||||
outFile.write('-'*(len(event) + 20) + '\n\n')
|
||||
outFile.write('-' * (len(event) + 20) + '\n\n')
|
||||
|
||||
names = sorted(desig[event].keys())
|
||||
if len(names) is 0:
|
||||
|
18
tox.ini
18
tox.ini
@ -1,4 +1,5 @@
|
||||
[tox]
|
||||
envlist = docs,doc8,pep8
|
||||
minversion = 1.6
|
||||
skipsdist = True
|
||||
|
||||
@ -18,3 +19,20 @@ commands =
|
||||
[testenv:docs]
|
||||
commands=
|
||||
python setup.py build_sphinx
|
||||
|
||||
[testenv:pep8]
|
||||
basepython = python2.7
|
||||
deps =
|
||||
{[testenv]deps}
|
||||
commands=
|
||||
bash tools/flake8wrap.sh
|
||||
whitelist_externals =
|
||||
sh
|
||||
bash
|
||||
|
||||
[flake8]
|
||||
# E125 is deliberately excluded.
|
||||
# See https://github.com/jcrocholl/pep8/issues/126
|
||||
|
||||
ignore = E125
|
||||
exclude = .venv,.git,.tox,doc,conf.py
|
||||
|
Loading…
Reference in New Issue
Block a user