Convert pep8 to flake8 for stx-nfv

Flake8 and Hacking offer stricter style checks than pep8.

This submission fixes these codes:
 E305 expected 2 blank lines after class or function definition, found 1
 E722 do not use bare except'
 F841 local variable 'blah' is assigned to but never used
 H101: Use TODO(NAME)
 H201: no 'except:' at least use 'except Exception:'
 H237: module commands is removed in Python 3
 H238: old style class declaration, use new style(inherit from `object`)

This submission enables 2 additional checks that are off by default
 H106 vim config in files
 H203 Use assertIs(Not)None to check for None

8 hacking codes and 2 flake8 types were added to the ignore list
and will be fixed by later updates.

An optional hacking code H904 will be enabled and the code fixed
by a later commit

Story: 2003499
Task: 26195
Change-Id: I48f99fc0dd41addc574c81cee6662600faeb8e75
Signed-off-by: Al Bailey <Al.Bailey@windriver.com>
This commit is contained in:
Al Bailey 2018-09-05 15:51:12 -05:00
parent adb8214db0
commit 5539db9dcf
10 changed files with 35 additions and 14 deletions

View File

@ -57,7 +57,7 @@ call("cp nfv-vim.log nfv-vim.log.[0-9] nfv-vim.log.[0-9][0-9] nfv-vim.log.[0-9].
call("gunzip logs/nfv-vim.log.[0-9].gz logs/nfv-vim.log.[0-9][0-9].gz", shell=True) call("gunzip logs/nfv-vim.log.[0-9].gz logs/nfv-vim.log.[0-9][0-9].gz", shell=True)
class Parser: class Parser(object):
def __init__(self): def __init__(self):
self.proc="" # Name of process being read self.proc="" # Name of process being read
self.timestamp="" # Timestamp found on line stating process name self.timestamp="" # Timestamp found on line stating process name
@ -132,6 +132,7 @@ class Parser:
csvOut.write(line+"\n") csvOut.write(line+"\n")
csvOut.close() csvOut.close()
process=Parser() process=Parser()
process.main() process.main()
print("\nComplete\n") print("\nComplete\n")

View File

@ -48,7 +48,7 @@ import plotly.graph_objs as go
from plotly.graph_objs import Scatter, Layout from plotly.graph_objs import Scatter, Layout
from plotly import tools from plotly import tools
from glob import iglob from glob import iglob
import commands import subprocess
from builtins import input from builtins import input
dir = os.path.dirname(__file__) dir = os.path.dirname(__file__)
@ -195,7 +195,6 @@ def gCommand(groups):
liNum=i liNum=i
if str("GroupName="+g) == cfgLines[i].strip(): if str("GroupName="+g) == cfgLines[i].strip():
groupFound=True groupFound=True
linum=i
while not finishedGroup: while not finishedGroup:
liNum+=1 liNum+=1
if "GroupEND" in cfgLines[liNum]: if "GroupEND" in cfgLines[liNum]:
@ -366,7 +365,7 @@ def setFilename(graphName):
print("Welcome to plotter, type --help for information") print("Welcome to plotter, type --help for information")
# Checks that plotly is installed, otherwise graphs cannot be generated. # Checks that plotly is installed, otherwise graphs cannot be generated.
plotCheck=commands.getstatusoutput("pip list | grep plotly") plotCheck=subprocess.getstatusoutput("pip list | grep plotly")
if plotCheck[0]==0: if plotCheck[0]==0:
if "plotly" not in plotCheck[1]: if "plotly" not in plotCheck[1]:
print("\n\tWARNING: Plotly is not installed on your system.\n\tPlease install it with: sudo pip install plotly\n") print("\n\tWARNING: Plotly is not installed on your system.\n\tPlease install it with: sudo pip install plotly\n")

View File

@ -122,7 +122,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI):
@staticmethod @staticmethod
def _host_supports_kubernetes(personality): def _host_supports_kubernetes(personality):
# TODO: This check will disappear once kubernetes is the default # TODO(bwensley): This check will disappear once kubernetes is the default
if os.path.isfile('/etc/kubernetes/admin.conf'): if os.path.isfile('/etc/kubernetes/admin.conf'):
return ('compute' in personality or 'controller' in personality) return ('compute' in personality or 'controller' in personality)
else: else:

View File

@ -249,7 +249,7 @@ def fake_event_issue(a, b, c, d):
@mock.patch('nfv_vim.tables._instance_table._instance_table', _instance_table) @mock.patch('nfv_vim.tables._instance_table._instance_table', _instance_table)
@mock.patch('nfv_vim.tables._instance_type_table._instance_type_table', _instance_type_table) @mock.patch('nfv_vim.tables._instance_type_table._instance_type_table', _instance_type_table)
@mock.patch('nfv_vim.tables._image_table._image_table', _image_table) @mock.patch('nfv_vim.tables._image_table._image_table', _image_table)
class TestInstance: class TestInstance(object):
def setup(self): def setup(self):
""" """

View File

@ -297,7 +297,7 @@ def fake_event_issue(a, b, c, d):
@mock.patch('nfv_vim.tables._host_aggregate_table._host_aggregate_table', _host_aggregate_table) @mock.patch('nfv_vim.tables._host_aggregate_table._host_aggregate_table', _host_aggregate_table)
@mock.patch('nfv_vim.tables._instance_table._instance_table', _instance_table) @mock.patch('nfv_vim.tables._instance_table._instance_table', _instance_table)
@mock.patch('nfv_vim.strategy._strategy.get_local_host_name', fake_host_name) @mock.patch('nfv_vim.strategy._strategy.get_local_host_name', fake_host_name)
class TestSwPatchStrategy: class TestSwPatchStrategy(object):
def setup(self): def setup(self):
""" """

View File

@ -304,7 +304,7 @@ def fake_event_issue(a, b, c, d):
@mock.patch('nfv_vim.tables._host_group_table._host_group_table', _host_group_table) @mock.patch('nfv_vim.tables._host_group_table._host_group_table', _host_group_table)
@mock.patch('nfv_vim.tables._host_aggregate_table._host_aggregate_table', _host_aggregate_table) @mock.patch('nfv_vim.tables._host_aggregate_table._host_aggregate_table', _host_aggregate_table)
@mock.patch('nfv_vim.tables._instance_table._instance_table', _instance_table) @mock.patch('nfv_vim.tables._instance_table._instance_table', _instance_table)
class TestSwUpgradeStrategy: class TestSwUpgradeStrategy(object):
def setup(self): def setup(self):
""" """

View File

@ -105,6 +105,7 @@ class Histogram(object):
'*' * min(60, bucket_value))) '*' * min(60, bucket_value)))
LOG.info("%s" % '-' * 120) LOG.info("%s" % '-' * 120)
_histograms = list() _histograms = list()

View File

@ -35,6 +35,7 @@ class ProxySysLogHandler(SysLogHandler):
msg = logging.handlers.SysLogHandler.format(self, record) msg = logging.handlers.SysLogHandler.format(self, record)
return self.binary_name + '(' + self.app + ')' + ': ' + msg return self.binary_name + '(' + self.app + ')' + ': ' + msg
_loggers = {} _loggers = {}

View File

@ -15,11 +15,12 @@ class timespec(ctypes.Structure):
""" """
_fields_ = [('tv_sec', ctypes.c_long), ('tv_nsec', ctypes.c_long)] _fields_ = [('tv_sec', ctypes.c_long), ('tv_nsec', ctypes.c_long)]
try: try:
librt = ctypes.CDLL('librt.so.1', use_errno=True) librt = ctypes.CDLL('librt.so.1', use_errno=True)
clock_gettime = librt.clock_gettime clock_gettime = librt.clock_gettime
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)] clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
except: except Exception:
raise OSError("Could not load librt.so.1 library") raise OSError("Could not load librt.so.1 library")

28
tox.ini
View File

@ -24,7 +24,7 @@ commands =
-o -type f -name '*.yaml' \ -o -type f -name '*.yaml' \
-print0 | xargs -0 yamllint" -print0 | xargs -0 yamllint"
[pep8] [flake8]
# Temporarily ignoring these warnings # Temporarily ignoring these warnings
# E116 unexpected indentation (comment) # E116 unexpected indentation (comment)
# E121 continuation line under-indented for hanging indent # E121 continuation line under-indented for hanging indent
@ -43,16 +43,34 @@ commands =
# E265 block comment should start with '# ' # E265 block comment should start with '# '
# E501 line too long # E501 line too long
# E712 comparison to bool should be reworded # E712 comparison to bool should be reworded
# - hacking codes -
ignore = E116,E121,E122,E123,E124,E126,E127,E128,E129,E225,E226,E231,E241,E261,E265,E501,E712 # H102: license header not found
# H104: File contains nothing but comments
# H301: one import per line
# H306: imports not in alphabetical order
# H401: docstring should not start with a space
# H404: multi line docstring should start without a leading new line
# H405: multi line docstring summary not separated with an empty line
# H501: Do not use self.__dict__ for string formatting
# - flake8 codes -
# F401 '<module>' imported but unused
# F821 undefined name 'unicode' (python3 specific)
ignore = E116,E121,E122,E123,E124,E126,E127,E128,E129,E225,E226,E231,E241,E261,E265,E501,E712,
H102,H104,H301,H306,H401,H404,H405,H501,
F401,F821,
# H106 Dont put vim configuration in source files (off by default).
# H203 Use assertIs(Not)None to check for None (off by default).
# TODO: enable: H904 Delay string interpolations at logging calls (off by default).
enable-extensions = H106,H203
[testenv:pep8] [testenv:pep8]
usedevelop = False usedevelop = False
skip_install = True skip_install = True
deps = deps =
pep8 hacking
flake8
commands = commands =
pep8 flake8
[testenv:venv] [testenv:venv]
commands = {posargs} commands = {posargs}