-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[primer] Create a class for easier comparison of pylint results
- Loading branch information
1 parent
406afd5
commit 0915546
Showing
3 changed files
with
50 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE | ||
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt | ||
|
||
from __future__ import annotations | ||
|
||
import json | ||
from collections.abc import Generator | ||
from pathlib import Path | ||
|
||
from pylint.testutils._primer.primer_command import Messages, PackageMessages | ||
|
||
|
||
class Comparator: | ||
def __init__(self, main_json: Path, pr_json: Path): | ||
main_messages = self._load_json(main_json) | ||
self.pr_messages = self._load_json(pr_json) | ||
self.missing_messages: PackageMessages = {} | ||
for package, messages in main_messages.items(): | ||
self.missing_messages[package] = [] | ||
for message in messages: | ||
try: | ||
self.pr_messages[package].remove(message) | ||
except ValueError: | ||
self.missing_messages[package].append(message) | ||
|
||
def __iter__( | ||
self, | ||
) -> Generator[tuple[str, Messages, Messages], None, None]: | ||
for package, missing_messages in self.missing_messages.items(): | ||
new_messages = self.pr_messages[package] | ||
if not missing_messages and not new_messages: | ||
print(f"PRIMER: No changes in {package}.") | ||
continue | ||
yield package, missing_messages, new_messages | ||
|
||
@staticmethod | ||
def _load_json(file_path: Path | str) -> PackageMessages: | ||
with open(file_path, encoding="utf-8") as f: | ||
result: PackageMessages = json.load(f) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters