From 4c9fd9bcb112510ed6bb0ccb952aa75cb9c1fdfc Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Sat, 4 Dec 2021 23:41:22 +0100 Subject: [PATCH 1/6] filecheck --version: point to mull-project --- filecheck/FileCheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index 84e8cdd..ff7089a 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -140,7 +140,7 @@ def print_version(): "filecheck: Python port of LLVM's FileCheck, " "flexible pattern matching file verifier" ) - print("https://github.com/stanislaw/FileCheck.py") + print("https://github.com/mull-project/FileCheck.py") print("Version: {}".format(__version__)) From 2659c2438ce09e8b471f143a98d48d89839920c3 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Sun, 5 Dec 2021 00:00:58 +0100 Subject: [PATCH 2/6] Code climate: Fix format()-related Pylint warnings --- filecheck/FileCheck.py | 157 +++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 91 deletions(-) diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index ff7089a..ca350a6 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -11,6 +11,8 @@ __version__ = "0.0.20" +from typing import Optional + class FailedCheck: def __init__(self, check, line_idx): @@ -63,7 +65,7 @@ def __init__( # pylint: disable=too-many-arguments check_type: CheckType, match_type: MatchType, check_keyword: str, - expression: str, + expression: Optional[str], source_line: str, check_line_idx: int, start_index: int, @@ -141,7 +143,7 @@ def print_version(): "flexible pattern matching file verifier" ) print("https://github.com/mull-project/FileCheck.py") - print("Version: {}".format(__version__)) + print(f"Version: {__version__}") def escape_non_regex_or_skip(match_obj): @@ -258,7 +260,7 @@ def exit_handler(code): print("Full input was:") for input_line in input_lines: print(input_line.rstrip()) - exit(code) + sys.exit(code) if len(sys.argv) == 1: print(" not specified") @@ -278,9 +280,8 @@ def exit_handler(code): if not os.path.isfile(check_file): sys.stdout.flush() err = ( - "Could not open check file '{}': No such file or directory".format( - check_file - ) + f"Could not open check file '{check_file}': " + f"No such file or directory" ) print(err) exit_handler(2) @@ -343,14 +344,16 @@ def exit_handler(code): # CHECK and CHECK-NEXT strict_whitespace_match = "" if strict_mode else " *" - check_regex = "{}({}):{}(.*)".format( - before_prefix, check_prefix, strict_whitespace_match + check_regex = ( + f"{before_prefix}({check_prefix}):{strict_whitespace_match}(.*)" ) + check_match = re.search(check_regex, line) check_type = CheckType.CHECK if not check_match: - check_regex = "{}({}-NEXT):{}(.*)".format( - before_prefix, check_prefix, strict_whitespace_match + check_regex = ( + f"{before_prefix}({check_prefix}-NEXT):" + f"{strict_whitespace_match}(.*)" ) check_match = re.search(check_regex, line) check_type = CheckType.CHECK_NEXT @@ -403,8 +406,9 @@ def exit_handler(code): checks.append(check) continue - check_not_regex = "{}({}-NOT):{}(.*)".format( - before_prefix, check_prefix, strict_whitespace_match + check_not_regex = ( + f"{before_prefix}({check_prefix}-NOT):" + f"{strict_whitespace_match}(.*)" ) check_match = re.search(check_not_regex, line) if check_match: @@ -434,9 +438,7 @@ def exit_handler(code): checks.append(check) continue - check_empty_regex = "{}({}-EMPTY):".format( - before_prefix, check_prefix - ) + check_empty_regex = f"{before_prefix}({check_prefix}-EMPTY):" check_match = re.search(check_empty_regex, line) if check_match: check_keyword = check_match.group(2) @@ -452,9 +454,10 @@ def exit_handler(code): ) if len(checks) == 0: + # TODO: 1 and 3? print( - "{}:{}:{}: error: found 'CHECK-EMPTY' without " - "previous 'CHECK: line".format(check_file, 1, 3) + f"{check_file}:{1}:{3}: error: " + f"found 'CHECK-EMPTY' without previous 'CHECK: line" ) print(line) print(" ^") @@ -475,9 +478,7 @@ def exit_handler(code): current_check = next(check_iterator) except StopIteration: error_message = ( - "error: no check strings found with prefix '{}:'".format( - check_prefix - ) + f"error: no check strings found with prefix '{check_prefix}:'" ) print(error_message, file=sys.stderr) sys.stdout.flush() @@ -518,7 +519,7 @@ def exit_handler(code): line_idx, line = next(stdin_input_iter) except StopIteration: print("CHECK: FileCheck error: '-' is empty.") - print("FileCheck command line: {}".format(check_file)) + print(f"FileCheck command line: {check_file}") exit_handler(2) current_not_checks = [] @@ -696,12 +697,10 @@ def exit_handler(code): "command line:1:22: error: CHECK-NOT: excluded string found " "in input" ) - print("-implicit-check-not='{}'".format(failed_check.original_check)) + print(f"-implicit-check-not='{failed_check.original_check}'") print(" ^") print( - ":{}:{}: note: found here".format( - failed_line_num, failed_column_num - ) + f":{failed_line_num}:{failed_column_num}: note: found here" ) print(context.line) print( @@ -733,20 +732,14 @@ def exit_handler(code): if current_check.check_type == CheckType.CHECK_EMPTY: last_read_line = input_lines[current_scan_base].rstrip() print( - "{}:{}:{}: error: CHECK-EMPTY: expected string not found " - "in input".format( - check_file, - current_check.check_line_idx + 1, - len(current_check.source_line) + 1, - ) + f"{check_file}:" + f"{current_check.check_line_idx + 1}:" + f"{len(current_check.source_line) + 1}: " + "error: CHECK-EMPTY: expected string not found in input" ) - print("{}".format(current_check.source_line)) + print(current_check.source_line) print("^".rjust(len(current_check.source_line) + 1)) - print( - ":{}:{}: note: scanning from here".format( - current_scan_base + 1, 1 - ) - ) + print(f":{current_scan_base + 1}:{1}: note: scanning from here") print(last_read_line) print("^") @@ -769,22 +762,18 @@ def exit_handler(code): or current_check.match_type == MatchType.REGEX ): print( - "{}:{}:{}: error: {}: expected string not found " - "in input".format( - check_file, - current_check.check_line_idx + 1, - current_check.start_index + 1, - check_prefix, - ) + f"{check_file}:" + f"{current_check.check_line_idx + 1}:" + f"{current_check.start_index + 1}: " + f"error: {check_prefix}: expected string not found in input" ) print(current_check.source_line.rstrip()) print("^".rjust(current_check.start_index + 1)) print( - ":{}:{}: note: scanning from here".format( - current_scan_base + 1, current_scan_col + 1 - ) + f":{current_scan_base + 1}:{current_scan_col + 1}: " + f"note: scanning from here" ) print(last_read_line) print("^".rjust(current_scan_col + 1)) @@ -816,8 +805,8 @@ def exit_handler(code): if candidate_line: caret_pos = len(candidate_line) // 2 + 1 print( - ":{}:{}: note: possible intended " - "match here".format(candidate_line_idx + 1, caret_pos) + f":{candidate_line_idx + 1}:{caret_pos}: " + f"note: possible intended match here" ) print(candidate_line) print("^".rjust(caret_pos, " ")) @@ -836,21 +825,15 @@ def exit_handler(code): last_read_line = re.sub("\\s+", " ", last_read_line).strip() print( - "{}:{}:{}: error: CHECK-NOT: excluded string " - "found in input".format( - check_file, - current_check.check_line_idx + 1, - current_check.start_index + 1, - ) + f"{check_file}:" + f"{current_check.check_line_idx + 1}:" + f"{current_check.start_index + 1}: " + f"error: CHECK-NOT: excluded string found in input" ) print(current_check.source_line.rstrip()) print("^".rjust(current_check.start_index + 1)) - print( - ":{}:{}: note: found here".format( - current_check_line_idx + 1, 1 - ) - ) + print(f":{current_check_line_idx + 1}:{1}: note: found here") print(last_read_line) if current_check.match_type == MatchType.SUBSTRING: @@ -881,20 +864,17 @@ def exit_handler(code): if matching_line_idx == -1: print( - "{}:{}:{}: error: CHECK-NEXT: expected string not found in " - "input".format( - check_file, - current_check.check_line_idx + 1, - current_check.start_index + 1, - ) + f"{check_file}:" + f"{current_check.check_line_idx + 1}:" + f"{current_check.start_index + 1}: " + f"error: CHECK-NEXT: expected string not found in input" ) print(current_check.source_line.rstrip()) print("^".rjust(current_check.start_index + 1)) print( - ":{}:{}: note: scanning from here".format( - current_scan_base + 1, 1 - ) + f":{current_scan_base + 1}:{1}: " + "note: scanning from here" ) print(last_read_line) print("^") @@ -903,21 +883,19 @@ def exit_handler(code): else: if current_scan_base > 0: print( - "{}:{}:{}: error: CHECK-NEXT: is not on the line after " - "the previous match".format( - check_file, - current_check.check_line_idx + 1, - current_check.start_index + 1, - ) + f"{check_file}:" + f"{current_check.check_line_idx + 1}:" + f"{current_check.start_index + 1}: " + "error: CHECK-NEXT: is not on the line after " + "the previous match" ) print(current_check.source_line.rstrip()) print("^".rjust(current_check.start_index + 1)) matching_line = input_lines[matching_line_idx].rstrip() print( - ":{}:1: note: 'next' match was here".format( - matching_line_idx + 1 - ) + f":{matching_line_idx + 1}:1: " + "note: 'next' match was here" ) print(matching_line) print("^") @@ -926,17 +904,15 @@ def exit_handler(code): current_scan_base - 1 ].rstrip() print( - ":{}:{}: note: previous match ended here".format( - current_scan_base, len(previous_matched_line) + 1 - ) + f":{current_scan_base}:" + f"{len(previous_matched_line) + 1}: " + f"note: previous match ended here" ) print(previous_matched_line) print("^".rjust(len(previous_matched_line) + 1)) print( - ":{}:{}: note: non-matching line after " - "previous match is here".format( - current_scan_base + 1, 1 - ) + f":{current_scan_base + 1}:{1}: " + f"note: non-matching line after previous match is here" ) print(last_read_line) print("^") @@ -947,12 +923,11 @@ def exit_handler(code): current_check.check_keyword ) print( - "{}:{}:{}: error: found 'CHECK-NEXT' " - "without previous 'CHECK: line".format( - check_file, - current_check.check_line_idx + 1, - check_expression_idx + 1, - ) + f"{check_file}:" + f"{current_check.check_line_idx + 1}:" + f"{check_expression_idx + 1}: " + f"error: found 'CHECK-NEXT' without " + f"previous 'CHECK: line" ) print(current_check.source_line.rstrip()) print("^".rjust(check_expression_idx + 1)) From ce7a95b64983f19057147265c355e8d69d453645 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Sun, 5 Dec 2021 00:03:13 +0100 Subject: [PATCH 3/6] Code climate: "consider merging if check" Pylint warning --- filecheck/FileCheck.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index ca350a6..ab3e6cb 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -758,8 +758,7 @@ def exit_handler(code): last_read_line = input_lines[current_scan_base].rstrip() if ( - current_check.match_type == MatchType.SUBSTRING - or current_check.match_type == MatchType.REGEX + current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX) ): print( f"{check_file}:" @@ -815,8 +814,7 @@ def exit_handler(code): if current_check.check_type == CheckType.CHECK_NOT: if ( - current_check.match_type == MatchType.SUBSTRING - or current_check.match_type == MatchType.REGEX + current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX) ): assert current_check_line_idx is not None last_read_line = input_lines[current_check_line_idx].rstrip() @@ -854,8 +852,7 @@ def exit_handler(code): last_read_line = input_lines[current_scan_base].rstrip() if ( - current_check.match_type == MatchType.SUBSTRING - or current_check.match_type == MatchType.REGEX + current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX) ): matching_line_idx = -1 for line_idx, line in enumerate(input_lines[current_scan_base:]): From 69c9c73d0b6b5854ba1d4ba067c43ce8afc02789 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Sun, 5 Dec 2021 00:07:43 +0100 Subject: [PATCH 4/6] Code climate: fix W0707 (raise-missing-from) --- filecheck/FileCheck.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index ab3e6cb..1c07bf1 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -597,7 +597,7 @@ def exit_handler(code): ) raise ImplicitCheckNotFailedException( failed_implicit_check - ) + ) from None exit_handler(0) @@ -607,7 +607,7 @@ def exit_handler(code): current_scan_col = 0 break except StopIteration: - raise InputFinishedException + raise InputFinishedException from None elif check_result == CheckResult.CHECK_NOT_MATCH: failed_check = FailedCheck(current_check, line_idx) @@ -616,7 +616,7 @@ def exit_handler(code): current_check = next(check_iterator) continue except StopIteration: - raise CheckFailedException(failed_check) + raise CheckFailedException(failed_check) from None elif check_result == CheckResult.CHECK_NOT_WITHOUT_MATCH: if failed_check: @@ -627,7 +627,7 @@ def exit_handler(code): current_check = next(check_iterator) continue except StopIteration: - raise CheckNOTIsLastException + raise CheckNOTIsLastException from None elif check_result == CheckResult.FAIL_SKIP_LINE: try: @@ -635,7 +635,7 @@ def exit_handler(code): break except StopIteration: failed_check = FailedCheck(current_check, line_idx) - raise CheckFailedException(failed_check) + raise CheckFailedException(failed_check) from None assert 0, "Should not reach here" except InputFinishedException: @@ -670,21 +670,21 @@ def exit_handler(code): ): current_check_line_idx = line_idx failed_check = FailedCheck(not_check, line_idx) - raise CheckFailedException(failed_check) + raise CheckFailedException(failed_check) from None - except CheckFailedException as e: - current_check = e.failed_check.check - current_check_line_idx = e.failed_check.line_idx + except CheckFailedException as check_failed_exception: + current_check = check_failed_exception.failed_check.check + current_check_line_idx = check_failed_exception.failed_check.line_idx except StopIteration: exit_handler(0) - except CheckFailedException as e: - current_check = e.failed_check.check - current_check_line_idx = e.failed_check.line_idx + except CheckFailedException as check_failed_exception: + current_check = check_failed_exception.failed_check.check + current_check_line_idx = check_failed_exception.failed_check.line_idx - except ImplicitCheckNotFailedException as e: - context = e.failed_check_context + except ImplicitCheckNotFailedException as implicit_check_not_exception: + context = implicit_check_not_exception.failed_check_context failed_check = context.check failed_line_num = context.line_idx + 1 From 20fe4edf29f01c5c0b628d67044ef88ace41b2f1 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Sun, 5 Dec 2021 00:10:17 +0100 Subject: [PATCH 5/6] Code climate: fix C0103 (invalid-name) --- filecheck/FileCheck.py | 44 +++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/filecheck/FileCheck.py b/filecheck/FileCheck.py index 1c07bf1..ae5f0d0 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/FileCheck.py @@ -276,17 +276,17 @@ def exit_handler(code): print_version() exit_handler(0) - check_file = sys.argv[1] - if not os.path.isfile(check_file): + check_file_path = sys.argv[1] + if not os.path.isfile(check_file_path): sys.stdout.flush() err = ( - f"Could not open check file '{check_file}': " + f"Could not open check file '{check_file_path}': " f"No such file or directory" ) print(err) exit_handler(2) - if os.path.getsize(check_file) == 0: + if os.path.getsize(check_file_path) == 0: sys.stdout.flush() print( "error: no check strings found with prefix 'CHECK:'", @@ -334,8 +334,8 @@ def exit_handler(code): exit_handler(2) checks = [] - with open(check_file, encoding="utf-8") as f: - for line_idx, line in enumerate(f): + with open(check_file_path, encoding="utf-8") as check_file: + for line_idx, line in enumerate(check_file): line = line.rstrip() if not args.strict_whitespace: @@ -456,7 +456,7 @@ def exit_handler(code): if len(checks) == 0: # TODO: 1 and 3? print( - f"{check_file}:{1}:{3}: error: " + f"{check_file_path}:{1}:{3}: error: " f"found 'CHECK-EMPTY' without previous 'CHECK: line" ) print(line) @@ -519,7 +519,7 @@ def exit_handler(code): line_idx, line = next(stdin_input_iter) except StopIteration: print("CHECK: FileCheck error: '-' is empty.") - print(f"FileCheck command line: {check_file}") + print(f"FileCheck command line: {check_file_path}") exit_handler(2) current_not_checks = [] @@ -674,7 +674,9 @@ def exit_handler(code): except CheckFailedException as check_failed_exception: current_check = check_failed_exception.failed_check.check - current_check_line_idx = check_failed_exception.failed_check.line_idx + current_check_line_idx = ( + check_failed_exception.failed_check.line_idx + ) except StopIteration: exit_handler(0) @@ -732,7 +734,7 @@ def exit_handler(code): if current_check.check_type == CheckType.CHECK_EMPTY: last_read_line = input_lines[current_scan_base].rstrip() print( - f"{check_file}:" + f"{check_file_path}:" f"{current_check.check_line_idx + 1}:" f"{len(current_check.source_line) + 1}: " "error: CHECK-EMPTY: expected string not found in input" @@ -757,11 +759,9 @@ def exit_handler(code): current_scan_base += 1 last_read_line = input_lines[current_scan_base].rstrip() - if ( - current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX) - ): + if current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX): print( - f"{check_file}:" + f"{check_file_path}:" f"{current_check.check_line_idx + 1}:" f"{current_check.start_index + 1}: " f"error: {check_prefix}: expected string not found in input" @@ -813,9 +813,7 @@ def exit_handler(code): exit_handler(1) if current_check.check_type == CheckType.CHECK_NOT: - if ( - current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX) - ): + if current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX): assert current_check_line_idx is not None last_read_line = input_lines[current_check_line_idx].rstrip() @@ -823,7 +821,7 @@ def exit_handler(code): last_read_line = re.sub("\\s+", " ", last_read_line).strip() print( - f"{check_file}:" + f"{check_file_path}:" f"{current_check.check_line_idx + 1}:" f"{current_check.start_index + 1}: " f"error: CHECK-NOT: excluded string found in input" @@ -851,9 +849,7 @@ def exit_handler(code): if current_check.check_type == CheckType.CHECK_NEXT: last_read_line = input_lines[current_scan_base].rstrip() - if ( - current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX) - ): + if current_check.match_type in (MatchType.SUBSTRING, MatchType.REGEX): matching_line_idx = -1 for line_idx, line in enumerate(input_lines[current_scan_base:]): if current_check.expression in line: @@ -861,7 +857,7 @@ def exit_handler(code): if matching_line_idx == -1: print( - f"{check_file}:" + f"{check_file_path}:" f"{current_check.check_line_idx + 1}:" f"{current_check.start_index + 1}: " f"error: CHECK-NEXT: expected string not found in input" @@ -880,7 +876,7 @@ def exit_handler(code): else: if current_scan_base > 0: print( - f"{check_file}:" + f"{check_file_path}:" f"{current_check.check_line_idx + 1}:" f"{current_check.start_index + 1}: " "error: CHECK-NEXT: is not on the line after " @@ -920,7 +916,7 @@ def exit_handler(code): current_check.check_keyword ) print( - f"{check_file}:" + f"{check_file_path}:" f"{current_check.check_line_idx + 1}:" f"{check_expression_idx + 1}: " f"error: found 'CHECK-NEXT' without " From 9754db1f406e98d5dca02826ddb0a4dbc1938a46 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Sun, 5 Dec 2021 00:16:37 +0100 Subject: [PATCH 6/6] Code climate: fix remaining Pylint warnings --- filecheck/{FileCheck.py => filecheck.py} | 42 +++++++++++++----------- pyproject.toml | 2 +- tasks.py | 11 ++----- 3 files changed, 25 insertions(+), 30 deletions(-) rename filecheck/{FileCheck.py => filecheck.py} (97%) diff --git a/filecheck/FileCheck.py b/filecheck/filecheck.py similarity index 97% rename from filecheck/FileCheck.py rename to filecheck/filecheck.py index ae5f0d0..ae5557a 100755 --- a/filecheck/FileCheck.py +++ b/filecheck/filecheck.py @@ -29,11 +29,13 @@ def __init__(self, check, line, line_idx): class CheckFailedException(BaseException): def __init__(self, failed_check): + super().__init__() self.failed_check = failed_check class ImplicitCheckNotFailedException(BaseException): def __init__(self, failed_check_context): + super().__init__() self.failed_check_context = failed_check_context @@ -42,8 +44,7 @@ class CheckNOTIsLastException(BaseException): class InputFinishedException(BaseException): - def __init__(self): - pass + pass class MatchType(Enum): @@ -104,8 +105,8 @@ def __init__(self, original_check: str, check: str): LINE_NUMBER_REGEX = r"\[\[# +@LINE *([+-])? *([0-9]+)? *\]\]" -def similar(a, b): - return SequenceMatcher(None, a, b).ratio() +def similar(lhs, rhs): + return SequenceMatcher(None, lhs, rhs).ratio() def print_help(): @@ -167,9 +168,8 @@ def escape_non_regex_parts(check_expression): # tabs) which causes it to ignore these differences (a space will match a tab). # The --strict-whitespace argument disables this behavior. # https://llvm.org/docs/CommandGuide/FileCheck.html#cmdoption-filecheck-strict-whitespace -def canonicalize_whitespace(input): - output = re.sub("\\s+", " ", input) - return output +def canonicalize_whitespace(input_string): + return re.sub("\\s+", " ", input_string) class CheckResult(Enum): @@ -182,10 +182,12 @@ class CheckResult(Enum): # Allow check prefixes only at the beginnings of lines or # after non-word characters. -before_prefix = "^(.*?[^\\w-])?" +BEFORE_PREFIX = "^(.*?[^\\w-])?" -def check_line(line, current_check, match_full_lines): +def check_line( + line, current_check, match_full_lines +): # pylint: disable=too-many-return-statements if current_check.check_type == CheckType.CHECK_EMPTY: if line != "": return CheckResult.FAIL_FATAL @@ -220,14 +222,12 @@ def check_line(line, current_check, match_full_lines): if current_check.match_type == MatchType.SUBSTRING: if current_check.expression in line: return CheckResult.CHECK_NOT_MATCH - else: - return CheckResult.CHECK_NOT_WITHOUT_MATCH + return CheckResult.CHECK_NOT_WITHOUT_MATCH - elif current_check.match_type == MatchType.REGEX: + if current_check.match_type == MatchType.REGEX: if re.search(current_check.expression, line): return CheckResult.CHECK_NOT_MATCH - else: - return CheckResult.CHECK_NOT_WITHOUT_MATCH + return CheckResult.CHECK_NOT_WITHOUT_MATCH return CheckResult.PASS @@ -244,7 +244,9 @@ def implicit_check_line(check_not_check, strict_mode, line): def main(): # Force UTF-8 to be sent to stdout. # https://stackoverflow.com/a/3597849/598057 - sys.stdout = open(1, "w", encoding="utf-8", closefd=False) + sys.stdout = open( + 1, "w", encoding="utf-8", closefd=False + ) # pylint: disable=consider-using-with args = None input_lines = None @@ -345,14 +347,14 @@ def exit_handler(code): strict_whitespace_match = "" if strict_mode else " *" check_regex = ( - f"{before_prefix}({check_prefix}):{strict_whitespace_match}(.*)" + f"{BEFORE_PREFIX}({check_prefix}):{strict_whitespace_match}(.*)" ) check_match = re.search(check_regex, line) check_type = CheckType.CHECK if not check_match: check_regex = ( - f"{before_prefix}({check_prefix}-NEXT):" + f"{BEFORE_PREFIX}({check_prefix}-NEXT):" f"{strict_whitespace_match}(.*)" ) check_match = re.search(check_regex, line) @@ -407,7 +409,7 @@ def exit_handler(code): continue check_not_regex = ( - f"{before_prefix}({check_prefix}-NOT):" + f"{BEFORE_PREFIX}({check_prefix}-NOT):" f"{strict_whitespace_match}(.*)" ) check_match = re.search(check_not_regex, line) @@ -438,7 +440,7 @@ def exit_handler(code): checks.append(check) continue - check_empty_regex = f"{before_prefix}({check_prefix}-EMPTY):" + check_empty_regex = f"{BEFORE_PREFIX}({check_prefix}-EMPTY):" check_match = re.search(check_empty_regex, line) if check_match: check_keyword = check_match.group(2) @@ -567,7 +569,7 @@ def exit_handler(code): failed_check = FailedCheck(current_check, line_idx) raise CheckFailedException(failed_check) - elif check_result == CheckResult.PASS: + if check_result == CheckResult.PASS: if failed_implicit_check: raise ImplicitCheckNotFailedException( failed_implicit_check diff --git a/pyproject.toml b/pyproject.toml index be46fb5..7a47e60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ lit = "^0.9" pylint = "2.12.2" [tool.poetry.scripts] -filecheck = "filecheck.FileCheck:main" +filecheck = "filecheck.filecheck:main" [build-system] requires = ["poetry>=0.12"] diff --git a/tasks.py b/tasks.py index c5dcee3..7c032cc 100644 --- a/tasks.py +++ b/tasks.py @@ -40,7 +40,7 @@ def get_filecheck_llvm_path(filecheck_exec): def get_filecheck_py_exec(): cwd = os.getcwd() - return f'python \\"{cwd}/filecheck/FileCheck.py\\"' + return f'python \\"{cwd}/filecheck/filecheck.py\\"' def run_lit_tests( @@ -104,13 +104,6 @@ def lint_flake8(context): def lint_pylint(context): command = one_line_command( """ - pylint - --rcfile=.pylint.ini - --disable=all - --fail-under=10.0 - --enable=E1101,R0201,R0902,R0913,R1701,R1705,R1710,R1714,R1719,R1725,C0103,C0209,C0303,C0411,C1801,W0703,W0231,W0235,W0612,W0613,W0640,W0707,W1514 - filecheck/ tasks.py - && pylint --rcfile=.pylint.ini --disable=c-extension-no-member @@ -126,7 +119,7 @@ def lint_pylint(context): raise exc -@task(lint_black_diff, lint_flake8) +@task(lint_black_diff, lint_flake8, lint_pylint) def lint(_): pass