-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve addon report infrastructure #64
Conversation
I like very much the idea, at least it decouples reporting from the checking step which is really usefull for creating integrations later. Two minor suggestions:
|
Hi @enen92,
Sure
You have read my mind :-) |
Well, it definitely has my approval. That's in fact one of the reasons for opening #46 . The issue is not specifically targetted at Checkstyle but more at architectural considerations to decouple the checking and reporting steps so that external tools can consume data produced by the tool and maybe be integrated into IDE's, text editors or code quality projects. Great to see this being implemented at such an early stage to avoid introducing drastic changes in the future |
kodi_addon_checker/check_repo.py
Outdated
colorPrint("We found %s problems and %s warnings, please check the logfile." % ( | ||
error_counter["problems"], error_counter["warnings"]), "31") | ||
if repo_report.problem > 0: | ||
colorPrint("We found %s problem and %s warning, please check the logfile." % ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/check_repo.py
Outdated
error_counter["problems"], error_counter["warnings"]), "35") | ||
elif repo_report.warning > 0: | ||
# If we only found warning, don't mark the build as broken | ||
colorPrint("We found %s problem and %s warning, please check the logfile." % ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/report.py
Outdated
class Report(object): | ||
def __init__(self, artifact_name): | ||
self.artifact_name = artifact_name | ||
self.problem = 0 |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/report.py
Outdated
|
||
|
||
class Record(Report): | ||
def __init__(self, artifact_name, message, start_line=-1, end_line=-1, start_char_position=-1, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/report.py
Outdated
self.start_char_position = start_char_position | ||
self.end_char_position = end_char_position | ||
|
||
if PROBLEM == artifact_name: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Very very good direction to move things in. So definatly welcome. Keep up the great work. 🎉 |
colorPrint(report, "35") | ||
elif report.problem: | ||
colorPrint(report, "31") | ||
else: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
else: | ||
print(report) | ||
else: | ||
print("\nChecking %s" % report.artifact_name) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the new commit.
kodi_addon_checker/check_repo.py
Outdated
colorPrint("We found %s problems and %s warnings, please check the logfile." % ( | ||
error_counter["problems"], error_counter["warnings"]), "31") | ||
if repo_report.problem > 0: | ||
colorPrint("We found %s problem and %s warning, please check the logfile." % ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/check_repo.py
Outdated
error_counter["problems"], error_counter["warnings"]), "35") | ||
elif repo_report.warning > 0: | ||
# If we only found warning, don't mark the build as broken | ||
colorPrint("We found %s problem and %s warning, please check the logfile." % ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
colorPrint(report, "35") | ||
elif report.problem: | ||
colorPrint(report, "31") | ||
else: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
else: | ||
print(report) | ||
else: | ||
print("\nChecking %s" % report.artifact_name) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/report.py
Outdated
class Report(object): | ||
def __init__(self, artifact_name): | ||
self.artifact_name = artifact_name | ||
self.problem = 0 |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/report.py
Outdated
|
||
|
||
class Record(Report): | ||
def __init__(self, artifact_name, message, start_line=-1, end_line=-1, start_char_position=-1, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/report.py
Outdated
self.start_char_position = start_char_position | ||
self.end_char_position = end_char_position | ||
|
||
if PROBLEM == artifact_name: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Hi @enen92,
Shall we find a different name or leave |
Add might work, as we basically add the record / report item and do some processing |
Renamed By default, Console reporter is enabled (
The user can override that option in the command line by providing
If there are more than one reporters (say
It can also be achieved by modifying
I feel it is enough for a PR. I will improve the file checker architecture in another PR. Please let me know if there is anything to fix. |
def fill_cmd_args(cls, parser: ArgumentParser): | ||
# Add --reporter | ||
parser.add_argument("--reporter", action="append", choices=list(ReportManager.reporters.keys()), | ||
help="""enable a reporter with the given name. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/report.py
Outdated
end_char_position=-1): | ||
self.log_level = log_level | ||
self.message = message | ||
self.start_line = start_line |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good code wise, but I want to do some manual tests before merging.
Well maybe it's not needed / not a good fit to derrive Record from Report? |
I'll try to review later today, thank you! |
kodi_addon_checker/report.py
Outdated
|
||
|
||
class Record(object): | ||
def __init__(self, log_level, message, start_line=-1, end_line=-1, start_char_position=-1, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/check_repo.py
Outdated
error_counter = {"warnings": 0, "problems": 0} | ||
def check_repo(config, repo_path, parameters): | ||
repo_report = Report(repo_path) | ||
repo_report.add(Record(INFORMATION, "Checking repository %s" % repo_path)) | ||
print("Repo path " + repo_path) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/check_repo.py
Outdated
@@ -24,21 +17,22 @@ def check_repo(repo_path, parameters): | |||
|
|||
print("Toplevel folders " + str(toplevel_folders)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/check_repo.py
Outdated
colorPrint("We found %s problems and %s warnings, please check the logfile." % ( | ||
error_counter["problems"], error_counter["warnings"]), "35") | ||
repo_report.problem_count, repo_report.warning_count), "35") | ||
|
||
print("Finished!") |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/common.py
Outdated
return True | ||
else: | ||
return False | ||
def colorPrint(string, color): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/check_repo.py
Outdated
|
||
if error_counter["problems"] > 0: | ||
if repo_report.problem_count > 0: | ||
colorPrint("We found %s problems and %s warnings, please check the logfile." % ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
kodi_addon_checker/check_repo.py
Outdated
elif error_counter["warnings"] > 0: | ||
# If we only found warnings, don't mark the build as broken | ||
elif repo_report.warning_count > 0: | ||
# If we only found warning, don't mark the build as broken | ||
colorPrint("We found %s problems and %s warnings, please check the logfile." % ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@slgobinath I just added some suggestions. |
@razzeee please note that I have fixed all your suggestions in slgobinath@8fb6fc0
I am from strong OOP and strict type background (Java person) so I was too concern about exact relationships. My design was "Record IS A Report" and "Report HAS A Report". However, I find removing inheritance makes the code more readable and does not hurt in Python world so +1 for it. |
Thank you very much for this 🎉 |
Hi @razzeee,
Could you please have a look at this design improvement. This PR improves how addon-checker handles reports. Currently, all reports are printed to the console as you check add-ons. It cannot support multiple reporters (say GitHub reporter, markdown reporter, checkstyle reporter, etc).
This PR isolates reports and reporters into separate modules so that add-on checker can be easily extended to support new reporters in future. For the moment, I have implemented ConsoleReporter which is printing the report to the console as we have right now.
The low level Record object is designed to include line numbers and character level positions for future requirements (to report errors in Python scripts). This design also allows you to report problems and/or warnings at repo level, add-on level or file level.
I have also defined three log levels: 'INFO', 'WARN' and 'ERROR'(which is equivalent to 'PROBLEM'). These terms were chosen to make the output more structured.
Sample report generated according to this implementation:
Annotation support is introduced for future implementations to automate config property definition which will be used to enable/disable reporters using
.test-config.json
or command line argument.WDYT?