black: fix style check package and flake8 formatting for black
Black will automatically fix a lot of the exceptions we previously allowed for
directives, so we don't need them in our custom `flake8_formatter` anymore.
- [x] remove `E501` (long line) exceptions for directives from `flake8_formatter`,
as they won't help us now.
- [x] Refine exceptions for long URLs in the `flake8_formatter`.
- [x] Adjust the mock `flake8-package` to exhibit the exceptions we still allow.
- [x] Update style tests for new `flake8-package`.
- [x] Blacken style test.
This commit is contained in:
@@ -21,24 +21,6 @@
|
||||
r"^from spack.package import \*$",
|
||||
r"^from spack.package_defs import \*$",
|
||||
],
|
||||
# Exempt lines with urls and descriptions from overlong line errors.
|
||||
"E501": [
|
||||
r"^\s*homepage\s*=",
|
||||
r"^\s*url\s*=",
|
||||
r"^\s*git\s*=",
|
||||
r"^\s*svn\s*=",
|
||||
r"^\s*hg\s*=",
|
||||
r"^\s*pypi\s*=",
|
||||
r"^\s*list_url\s*=",
|
||||
r"^\s*version\(",
|
||||
r"^\s*variant\(",
|
||||
r"^\s*provides\(",
|
||||
r"^\s*extends\(",
|
||||
r"^\s*depends_on\(",
|
||||
r"^\s*conflicts\(",
|
||||
r"^\s*resource\(",
|
||||
r"^\s*patch\(",
|
||||
],
|
||||
# Exempt '@when' decorated functions from redefinition errors.
|
||||
"F811": [
|
||||
r"^\s*@when\(.*\)",
|
||||
@@ -47,7 +29,7 @@
|
||||
# exemptions applied to all files.
|
||||
r".py$": {
|
||||
"E501": [
|
||||
r"(https?|ftp|file)\:", # URLs
|
||||
r"(ssh|https?|ftp|file)\:", # URLs
|
||||
r'([\'"])[0-9a-fA-F]{32,}\1', # long hex checksums
|
||||
]
|
||||
},
|
||||
@@ -58,10 +40,7 @@
|
||||
pattern_exemptions = dict(
|
||||
(
|
||||
re.compile(file_pattern),
|
||||
dict(
|
||||
(code, [re.compile(p) for p in patterns])
|
||||
for code, patterns in error_dict.items()
|
||||
),
|
||||
dict((code, [re.compile(p) for p in patterns]) for code, patterns in error_dict.items()),
|
||||
)
|
||||
for file_pattern, error_dict in pattern_exemptions.items()
|
||||
)
|
||||
@@ -105,9 +84,7 @@ def handle(self, error): # type: (Violation) -> None
|
||||
# get list of patterns for this error code
|
||||
pats = self.spack_errors.get(error.code, None)
|
||||
# if any pattern matches, skip line
|
||||
if pats is not None and any(
|
||||
(pat.search(error.physical_line) for pat in pats)
|
||||
):
|
||||
if pats is not None and any((pat.search(error.physical_line) for pat in pats)):
|
||||
return
|
||||
|
||||
# Special F811 handling
|
||||
@@ -117,16 +94,10 @@ def handle(self, error): # type: (Violation) -> None
|
||||
# https://gitlab.com/pycqa/flake8/issues/583
|
||||
# we can only determine if F811 should be ignored given the previous
|
||||
# line, so get the previous line and check it
|
||||
if (
|
||||
self.spack_errors.get("F811", False)
|
||||
and error.code == "F811"
|
||||
and error.line_number > 1
|
||||
):
|
||||
if self.spack_errors.get("F811", False) and error.code == "F811" and error.line_number > 1:
|
||||
if self.file_lines is None:
|
||||
if self.filename in {"stdin", "-", "(none)", None}:
|
||||
self.file_lines = pycodestyle.stdin_get_value().splitlines(
|
||||
True
|
||||
)
|
||||
self.file_lines = pycodestyle.stdin_get_value().splitlines(True)
|
||||
else:
|
||||
self.file_lines = pycodestyle.readlines(self.filename)
|
||||
for pat in self.spack_errors["F811"]:
|
||||
|
||||
Reference in New Issue
Block a user