-
Notifications
You must be signed in to change notification settings - Fork 249
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
Add Pylint logs #512
base: master
Are you sure you want to change the base?
Add Pylint logs #512
Changes from all commits
56c2a9c
79c85ec
01c9c59
dfc9b09
7886ae6
3d82cc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,9 @@ | |
# limitations under the License. | ||
|
||
from pybuilder.core import use_plugin, after, init, task | ||
from pybuilder.utils import assert_can_execute | ||
from pybuilder.errors import BuildFailedException | ||
from pybuilder.plugins.python.python_plugin_helper import execute_tool_on_modules | ||
from pybuilder.utils import assert_can_execute | ||
|
||
use_plugin("python.core") | ||
use_plugin("analysis") | ||
|
@@ -44,4 +45,63 @@ def execute_pylint(project, logger): | |
logger.info("Executing pylint on project sources") | ||
|
||
command_and_arguments = ["pylint"] + project.get_property("pylint_options") | ||
execute_tool_on_modules(project, "pylint", command_and_arguments, True) | ||
pylint_output_file_path = execute_tool_on_modules(project, "pylint", command_and_arguments, True)[1] | ||
|
||
with open(pylint_output_file_path, 'r') as f: | ||
file_content = f.read().splitlines() | ||
|
||
module_name = '' | ||
pylint_score = 0 | ||
pylint_change = 0 | ||
errors = 0 | ||
errors_info = '' | ||
warnings = 0 | ||
warnings_info = '' | ||
show_info_messages = project.get_property('pylint_show_info_messages') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need separated properties There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With verbose you can not decide if you want to see only warnings, moreover with verbose you will see a lot of other logs. I think it is good to have separate configuration for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @maciejpolanczyk There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pylint shows all issues in report file. I would like to have possibility to show only warnings or only infos from pylint on console as output from pybuilder without big output which will be created by 'verbose' from other plugins and pybuiilder. It will be easy to read them and I will not have to go to report file to find out what went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand - cause of report parsing You can manage different type of issues. Why not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean all logger.info in this file or only the one which shows infos from pylint? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to particular row - https://github.com/pybuilder/pybuilder/pull/512/files#r148052635 |
||
show_warning_messages = project.get_property('pylint_show_warning_messages') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could set show_info_messages = True and show_info_messages = True when verbose and debug are true. What do you think about it @AlexeySanko ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @maciejpolanczyk |
||
for line in file_content: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we parse pylint results I think that more suitable is JSON format Example, of JSON output
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, JSON report doesn't provide scores. :( |
||
if line.startswith('************* Module'): | ||
module_name = line.split(' ')[2] | ||
|
||
if line.startswith('E:') or line.startswith('F:'): | ||
logger.error('Pylint: Module %s: ' % module_name + line) | ||
errors += 1 | ||
|
||
if show_warning_messages and line.startswith('W:'): | ||
logger.warn('Pylint: Module %s: ' % module_name + line) | ||
warnings += 1 | ||
|
||
if show_info_messages and (line.startswith('C:') or line.startswith('R:')): | ||
logger.info('Pylint: Module %s: ' % module_name + line) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @maciejpolanczyk There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, will fix this. |
||
|
||
if line.startswith('Your code has been rated at '): | ||
pylint_score = float(line.split(' ')[6].split('/')[0]) | ||
pylint_change = float(line.split(' ')[10][:-1]) | ||
|
||
if errors > 0: | ||
errors_info = ' / Errors: {}'.format(errors) | ||
|
||
if warnings > 0: | ||
warnings_info = ' / Warnings {}'.format(warnings) | ||
|
||
logger.info( | ||
'Pylint ratio: {} / Pylint change: {}'.format(pylint_score, pylint_change) + errors_info + warnings_info | ||
) | ||
|
||
if errors > 0 and project.get_property('pylint_break_build_on_errors'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flake8 and frosted use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @AlexeySanko thanks for quick response to PR. In case of pylint we have a little different situation. In this plugin we assumed we can fail from different reasons:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @maciejpolanczyk There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, we will change it to work as you described. |
||
raise BuildFailedException( | ||
"Pylint: Building failed due to {} errors or fatal errors".format(errors) | ||
) | ||
|
||
pylint_expected_score = project.get_property('pylint_score_threshold') | ||
pylint_expected_score_change = project.get_property('pylint_score_change_threshold') | ||
if pylint_expected_score and pylint_score < pylint_expected_score: | ||
raise BuildFailedException( | ||
"Pylint: Building failed due to Pylint score({}) less then expected({})". | ||
format(pylint_score, pylint_expected_score) | ||
) | ||
if pylint_expected_score_change and pylint_change < pylint_expected_score_change: | ||
raise BuildFailedException( | ||
"Pylint: Building failed due to Pylint score decrease({}) higher then allowed({})". | ||
format(pylint_change, pylint_expected_score_change) | ||
) |
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.
I suggest to use
We will get two advantages:
pylint_include_test_sources
execute_tool_on_modules
usesdiscover_modules
which returns list of all packages AND modules. For example, I have packagepckg
with modulesa
,b
andc
.discover_modules
returns list:[ 'pckg', 'pckg.a', 'pckg.b', 'pckg.c']
and pylint will report problem with duplicated code into files (it will parsepckg.a
twice).