summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-09-07 23:58:12 -0700
committerGitHub <noreply@github.com>2019-09-07 23:58:12 -0700
commit0ec80e8f161d90120ce161f35dc00b026a57ddd9 (patch)
tree4a76c5af32591983d53ea99d1dd1ef7cd843b998 /lib
parent48c3c833e8c48fb210dca1121c7b80694bf6e4e0 (diff)
downloadspack-0ec80e8f161d90120ce161f35dc00b026a57ddd9.tar.gz
spack-0ec80e8f161d90120ce161f35dc00b026a57ddd9.tar.bz2
spack-0ec80e8f161d90120ce161f35dc00b026a57ddd9.tar.xz
spack-0ec80e8f161d90120ce161f35dc00b026a57ddd9.zip
flake8: only add E501 exemptions when absolutely necessary (#12755)
E501 (line too long) exemptions are probably our most common ones -- we add them for directives, URLs, hashes, etc. in packages. But we currently add them even when a line *doesn't* need them, which can mask trailing whitespace errors. This changes `spack flake8` so that it will only add E501 exemptions if the line is *actually* too long. Co-Authored-By: Adam J. Stewart <ajstewart426@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/flake8.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/flake8.py b/lib/spack/spack/cmd/flake8.py
index 8c2b90a2a1..ebcad88a06 100644
--- a/lib/spack/spack/cmd/flake8.py
+++ b/lib/spack/spack/cmd/flake8.py
@@ -36,6 +36,8 @@ def is_package(f):
#: List of directories to exclude from checks.
exclude_directories = [spack.paths.external_path]
+#: max line length we're enforcing (note: this duplicates what's in .flake8)
+max_line_length = 79
#: This is a dict that maps:
#: filename pattern ->
@@ -151,7 +153,16 @@ def add_pattern_exemptions(line, codes):
return line + '\n'
orig_len = len(line)
- exemptions = ','.join(sorted(set(codes)))
+ codes = set(codes)
+
+ # don't add E501 unless the line is actually too long, as it can mask
+ # other errors like trailing whitespace
+ if orig_len <= max_line_length and "E501" in codes:
+ codes.remove("E501")
+ if not codes:
+ return line + "\n"
+
+ exemptions = ','.join(sorted(codes))
# append exemption to line
if '# noqa: ' in line:
@@ -160,7 +171,7 @@ def add_pattern_exemptions(line, codes):
line += ' # noqa: {0}'.format(exemptions)
# if THIS made the line too long, add an exemption for that
- if len(line) > 79 and orig_len <= 79:
+ if len(line) > max_line_length and orig_len <= max_line_length:
line += ',E501'
return line + '\n'