Skip to content
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 new JSON reporter #8929

Merged
merged 5 commits into from
Aug 15, 2023
Merged

Conversation

DanielNoord
Copy link
Collaborator

@DanielNoord DanielNoord commented Aug 5, 2023

Type of Changes

Type
✨ New feature

Description

Closes #4741
Closes #3504

As discussed in the issue we create a new json2 reporter that users can now use to get the score and other statistics. Since I want to keep being conscious about what is and isn't public API I decided to put both reporters in the private namespace. Since we are still in beta that should be fine? 😄

@DanielNoord DanielNoord added the Enhancement ✨ Improvement to a component label Aug 5, 2023
@DanielNoord DanielNoord added this to the 3.0.0a7 milestone Aug 5, 2023
@DanielNoord
Copy link
Collaborator Author

@jacobtylerwalls Is the issue on PyPy related to changes to how we invoke tests? The module is clearly there 😅

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some preliminary comments, I'll do a more thorough review later (I'm on mobilel) I had only a quick look but nothing seems to be wrong

doc/whatsnew/fragments/4741.feature Show resolved Hide resolved
@@ -103,7 +103,7 @@ def _make_linter_options(linter: PyLinter) -> Options:
"short": "f",
"group": "Reports",
"help": "Set the output format. Available formats are text,"
" parseable, colorized, json and msvs (visual studio)."
" parseable, colorized, json2 and msvs (visual studio)."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should hide the fact that the json reporter still exists, generating this text would be nice too imo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we have a different opinion here then.

I think there should be one way to do things and that json2 is superior. Thus, that option is what we should advertise to users looking through the possibilities.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but imagine you maintain a tool that consumes the old reporter. And you're reviewing a PR, and you need to brush up on the context. You come here, and it's gone. Won't you burn time trying to figure out what happened and wondering why things aren't horribly broken?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what the changelog is for? If you search for json you'll find the change.

I'm fine with adding something like json (deprecated) but as expressed elsewhere I would really like to nudge all users to the new reporter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm waffling on this one. As long as it's somewhere I guess it doesn't have to be in the CLI help.

@github-actions

This comment has been minimized.

@jacobtylerwalls
Copy link
Member

@jacobtylerwalls Is the issue on PyPy related to changes to how we invoke tests?

I don't know, I'd appreciate help investigating.

The module is clearly there 😅

From recent experience, no, nothing about package layouts without src-layout is clear ...! 😆

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big thanks for picking this up!

doc/whatsnew/fragments/4741.feature Outdated Show resolved Hide resolved
doc/whatsnew/fragments/4741.feature Outdated Show resolved Hide resolved
@@ -103,7 +103,7 @@ def _make_linter_options(linter: PyLinter) -> Options:
"short": "f",
"group": "Reports",
"help": "Set the output format. Available formats are text,"
" parseable, colorized, json and msvs (visual studio)."
" parseable, colorized, json2 and msvs (visual studio)."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but imagine you maintain a tool that consumes the old reporter. And you're reviewing a PR, and you need to brush up on the context. You come here, and it's gone. Won't you burn time trying to figure out what happened and wondering why things aren't horribly broken?

pylint/reporters/_json_reporter.py Outdated Show resolved Hide resolved
pylint/testutils/_primer/primer_command.py Outdated Show resolved Hide resolved
tests/reporters/unittest_reporting.py Show resolved Hide resolved
@jacobtylerwalls
Copy link
Member

Since I want to keep being conscious about what is and isn't public API I decided to put both reporters in the private namespace. Since we are still in beta that should be fine? 😄

My initial inclination is that we need a stronger reason to do this, but I'm not certain yet. Is there a reason we need to be this paranoid? Don't we anticipate never touching this again?

@DanielNoord
Copy link
Collaborator Author

Since I want to keep being conscious about what is and isn't public API I decided to put both reporters in the private namespace. Since we are still in beta that should be fine? 😄

My initial inclination is that we need a stronger reason to do this, but I'm not certain yet. Is there a reason we need to be this paranoid? Don't we anticipate never touching this again?

After seeing the trouble CPython is having with their C API and our own troubles with deprecating stuff I'm (currently) inclined to always make things private unless explicitly asked for. There is a good reason pytest has almost all of their package in a private namespace:
https://github.com/pytest-dev/pytest/tree/main/src/pytest

Whenever somebody want to access something I'm highly in favour of making it public and creating a well-defined API for it, but I just don't want to deal with another spree of deprecation and removal issues.

@cdce8p
Copy link
Member

cdce8p commented Aug 5, 2023

My initial inclination is that we need a stronger reason to do this, but I'm not certain yet. Is there a reason we need to be this paranoid? Don't we anticipate never touching this again?

After seeing the trouble CPython is having with their C API and our own troubles with deprecating stuff I'm (currently) inclined to always make things private unless explicitly asked for. There is a good reason pytest has almost all of their package in a private namespace: https://github.com/pytest-dev/pytest/tree/main/src/pytest

Whenever somebody want to access something I'm highly in favour of making it public and creating a well-defined API for it, but I just don't want to deal with another spree of deprecation and removal issues.

It it really necessary to add an underscore? Yes deprecations are quite a hassle, but it also has it's upsides. E.g. if users want to customize any of the existing reporters, they can easily subclass it. As long as it isn't documented publicly, it's just kindness / good responsibility of us not to break stuff unnecessarily.

Another example, consider the checkers/utils.py module which is probably used by a lot of plugins. We can still change things. Plugins authors will adjust. Only it shouldn't be for x.1, then x.2, x.3 and so on. Change it once and stick with it (at least for some time).

@jacobtylerwalls jacobtylerwalls modified the milestones: 3.0.0a7, 3.0.0b1 Aug 6, 2023
@DanielNoord
Copy link
Collaborator Author

E.g. if users want to customize any of the existing reporters, they can easily subclass it. As long as it isn't documented publicly, it's just kindness / good responsibility of us not to break stuff unnecessarily.

If there is a need for it they can for it to become public and we can then make that explicit. For me using the underscores is also about setting expectations about what can and what can not change. I'm fine with maintaining a large public API, but only when we see a need for it because plugin writers or users ask for it. From the current state we are in we can only get there by making new code explicitly private.

Another example, consider the checkers/utils.py module which is probably used by a lot of plugins. We can still change things. Plugins authors will adjust. Only it shouldn't be for x.1, then x.2, x.3 and so on. Change it once and stick with it (at least for some time).

Again, I think there is too much of a grey array there. There were quite a bit of number of functions that I would have liked to change or delete when doing the configuration rewrite and the typing stuff but which I couldn't. Some utils should just be for internal use and should be documented as such.

@codecov
Copy link

codecov bot commented Aug 6, 2023

Codecov Report

Merging #8929 (a9002af) into main (f40e9ff) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8929   +/-   ##
=======================================
  Coverage   95.74%   95.75%           
=======================================
  Files         173      173           
  Lines       18558    18592   +34     
=======================================
+ Hits        17768    17802   +34     
  Misses        790      790           
Files Changed Coverage Δ
pylint/lint/base_options.py 100.00% <ø> (ø)
pylint/interfaces.py 100.00% <100.00%> (ø)
pylint/reporters/__init__.py 100.00% <100.00%> (ø)
pylint/reporters/json_reporter.py 100.00% <100.00%> (ø)
pylint/testutils/_primer/primer_run_command.py 30.76% <100.00%> (-1.05%) ⬇️

@github-actions

This comment has been minimized.

doc/whatsnew/fragments/4741.feature Show resolved Hide resolved
@@ -35,3 +35,4 @@ class Confidence(NamedTuple):

CONFIDENCE_LEVELS = [HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE, UNDEFINED]
CONFIDENCE_LEVEL_NAMES = [i.name for i in CONFIDENCE_LEVELS]
CONFIDENCE_MAP = {i.name: i for i in CONFIDENCE_LEVELS}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It pains me to see that we're basically recreating the enum.Enum interface for our 5 confidences constants and their 1 helper class and 3 helper constants. I don't think we should refactor but it does itch me every time.

evaluation, {}, {**counts_dict, "statement": stats.statement or 1}
)
except Exception as ex: # pylint: disable=broad-except
score: str | int = f"An exception occurred while rating: {ex}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can mock an exception in the score evaluation in order to get coverage, or maybe provide a bad string via config that will create an error ?

tests/reporters/unittest_reporting.py Show resolved Hide resolved
doc/whatsnew/fragments/4741.feature Show resolved Hide resolved
Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with Marc that we should prefer building new reporters like json3 if it ever came to that rather than make this private.

@DanielNoord
Copy link
Collaborator Author

I rebased and force pushed to remove the private making commits.

This now only introduce a new reporter and uses it where necessary/possible. Let me know what you guys think!

@github-actions
Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 53a5835

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look ready, it only needs the example of json in 3.0.md that Jacob suggested and let's merge 👍

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
@jacobtylerwalls jacobtylerwalls modified the milestones: 3.0.0b1, 3.0.0a7 Aug 15, 2023
@Pierre-Sassoulas Pierre-Sassoulas enabled auto-merge (squash) August 15, 2023 16:07
@Pierre-Sassoulas Pierre-Sassoulas merged commit 7264e33 into pylint-dev:main Aug 15, 2023
44 checks passed
@DanielNoord DanielNoord deleted the json-reporter branch August 15, 2023 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve JSON output format with score Exporting to JSON does not honor score option
4 participants