[dvsim] PEP8 fixes in dvsim
These should cause no functional change. Detailed list of code changes:
- Get rid of 'import *': this defeats static analysis tools. Don't
do it.
- Add newline after colon in "if foo: bar"
- Use 'is' to check for equality with boolean literals
- Don't catch exceptions when running os.system in Deploy.py: the
os.system function returns the program's exit code.
- Delete some variables that are written but not read.
- Minor whitespace changes (missing blank lines between functions;
weird indentation; missing space after '#')
- Delete autogenerated module docstrings (they didn't contain any
information. Maybe it would be good to have a docstring, but at
the moment it's just noise).
- Don't use \ as a line continuation character. Use parentheses if
necessary.
- Replace code like "foo" + \ "bar" with just "foo" "bar" (Python
concatenates adjacent string literals just like C). (I didn't do
this everywhere, but it happened a lot next to the backslash
continuations, so I got rid of the unnecessary '+' then).
- Replace "not foo in bar" with "foo not in bar"
- Use raw strings for regexes with backslashes (r'a\+', not 'a\+')
With these changes, you can run:
find util/dvsim -name '*.py' | xargs flake8
and see no errors.
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/util/dvsim/utils.py b/util/dvsim/utils.py
index 2d734be..85c1ca0 100644
--- a/util/dvsim/utils.py
+++ b/util/dvsim/utils.py
@@ -7,7 +7,6 @@
import logging as log
import os
-import pprint
import re
import shlex
import subprocess
@@ -63,7 +62,8 @@
if status != 0:
log.error("cmd \"%s\" exited with status %d", cmd, status)
- if exit_on_failure == 1: sys.exit(status)
+ if exit_on_failure == 1:
+ sys.exit(status)
return (result, status)
@@ -90,8 +90,10 @@
If var has wildcards specified within {..}, find and substitute them.
'''
def subst(wildcard, mdict):
- if wildcard in mdict.keys(): return mdict[wildcard]
- else: return None
+ if wildcard in mdict.keys():
+ return mdict[wildcard]
+ else:
+ return None
if "{eval_cmd}" in var:
idx = var.find("{eval_cmd}") + 11
@@ -133,7 +135,8 @@
else:
# Check if the wildcard exists as an environment variable
env_var = os.environ.get(item)
- if env_var is not None: subst_list[item] = env_var
+ if env_var is not None:
+ subst_list[item] = env_var
elif not ignore_error:
log.error(
"Substitution for the wildcard \"%s\" not found",
@@ -254,7 +257,7 @@
def color_cell(cell, cclass, indicator="%"):
op = cell.replace("<td", "<td class=\"" + cclass + "\"")
# Remove the indicator.
- op = re.sub(r"\s*" + indicator + "\s*", "", op)
+ op = re.sub(r"\s*" + indicator + r"\s*", "", op)
return op
# List of 'not applicable' identifiers.
@@ -262,12 +265,11 @@
na_list_patterns = '|'.join(na_list)
# List of floating point patterns: '0', '0.0' & '.0'
- fp_patterns = "[\+\-]?\d+\.?\d*"
+ fp_patterns = r"[\+\-]?\d+\.?\d*"
patterns = fp_patterns + '|' + na_list_patterns
indicators = "%|%u|G|B|E|W|EN|WN"
- match = re.findall(
- r"(<td.*>\s*(" + patterns + ")\s+(" + indicators + ")\s*</td>)", text)
+ match = re.findall(r"(<td.*>\s*(" + patterns + r")\s+(" + indicators + r")\s*</td>)", text)
if len(match) > 0:
subst_list = {}
fp_nums = []
@@ -278,20 +280,23 @@
fp_num = item[1]
indicator = item[2]
# Skip if fp_num is already processed.
- if (fp_num, indicator) in fp_nums: continue
+ if (fp_num, indicator) in fp_nums:
+ continue
fp_nums.append((fp_num, indicator))
- if fp_num in na_list: subst = color_cell(cell, "cna", indicator)
+ if fp_num in na_list:
+ subst = color_cell(cell, "cna", indicator)
else:
# Item is a fp num.
try:
fp = float(fp_num)
except ValueError:
- log.error("Percentage item \"%s\" in cell \"%s\" is not an " + \
+ log.error("Percentage item \"%s\" in cell \"%s\" is not an "
"integer or a floating point number", fp_num, cell)
continue
# Percentage, colored.
if indicator == "%":
- if fp >= 0.0 and fp < 10.0: subst = color_cell(cell, "c0")
+ if fp >= 0.0 and fp < 10.0:
+ subst = color_cell(cell, "c0")
elif fp >= 10.0 and fp < 20.0:
subst = color_cell(cell, "c1")
elif fp >= 20.0 and fp < 30.0: