-
-
Notifications
You must be signed in to change notification settings - Fork 292
Capture and log messages emitted by C modules when importing them #1514
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
Conversation
Pull Request Test Coverage Report for Build 2374232989
💛 - Coveralls |
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'm wondering if the solution would be to add debug logging to astroid. It seems to me that this output is not error so technically should not be printed to stderr (although it's convenient to do so because we would not have to setup logging). I don't think we have logging in astroid yet, but we don't have to do the configuration, probably just clarifying in the documentation that you need to activate logging with debug level if you want to see the stdout from loading c module.
Thanks, I thought about this for a bit. I think the fact that astroid imports C modules (that are allowlisted, or even just that have a brain, see #562), is worth warning the user, and that's an okay use for stderr. "Welcome to pygame!" is not an error in I found a couple interesting things at the Python logging docs for library developers:
So I think even if we go the logging route we'll end up generating messages in |
Ah, maybe we could wrap it in a UserWarning or something that can be filtered idiomatically. |
I would use the "info" log level for what comes from stdout, debug is a little low. If the output comes from stderr originally we should use the error level though. Reading your documentation it seems we should add a
import logging
logger = logging.getLogger(astroid).addHandler(logging.NullHandler())
# (logger = logging.getLogger(__file__))
...
if stderr:
logger.error(...)
else:
logger.info(...) |
b6fbe3c
to
d7126d1
Compare
This prevents contaminating programmatic output, e.g. pylint's JSON reporter. Co-authored-by: Pierre Sassoulas <[email protected]>
320bfb4
to
26f81b8
Compare
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.
LGTM, that's a nice addition to 2.12 !
@@ -5,7 +5,6 @@ coveralls~=3.3 | |||
coverage~=6.3.3 | |||
pre-commit~=2.19 | |||
pytest-cov~=3.0 | |||
contributors-txt>=0.7.3 |
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.
@Pierre-Sassoulas did you want to remove this in another MR? I reverted this change here.
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.
It happened to prevent installing with pip locally I guess it's not that important. (Duplicated entry)
Steps
Description
Pipe stdout to stderrCapture and log messages emitted while importing C modules. This prevents contaminating programmatic output, e.g. pylint's JSON reporter.An alternative would be to silence stdout altogether, but there may be users who appreciate the notice that code is being executed. This way no information is lost, while still allowing clean programmatic output.
Type of Changes
Related Issue
Closes pylint-dev/pylint#3518
/cc @piotr-machura, what do you think of this approach?