-
Notifications
You must be signed in to change notification settings - Fork 55
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
Log debug message if import PythonShell and PythonEditor fail in api.py #801
Conversation
import logging | ||
|
||
|
||
_PYFACE_LOGGER = logging.getLogger("pyface") |
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.
This makes me a bit twitchy, having the logger being used hard-coded. Perhaps better would be to pass in the logger instance to optional_import
so it can use the logger of the module where optional_import
is called from.
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 would also make testing easier
pyface/api.py
Outdated
from .util._optional_dependencies import optional_import as _optional_import | ||
|
||
# Excuse pygments dependency (for Qt), otherwise re-raise | ||
with _optional_import("pygments", msg="PythonEditor not available"): |
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.
The log message doesn't mention that the reason it isn't available is because Pygments isn't installed - that would be useful to know.
yield | ||
except ImportError as exception: | ||
if exception.name == dependency_name: | ||
_PYFACE_LOGGER.debug(msg, exc_info=True) |
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.
Maybe info
rather than debug
?
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 still prefer debug because this is intended for debugging purposes. But that is not a strong preference.
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 think typically info message does not contain exception traceback info (the exc_info=True
) bit. Here I think we want to show the traceback which will include the ImportError on pygments.
I could do both, I suppose?
Like this?
Lines 240 to 241 in 7e32dbf
logger.info(msg, plugin.name, module_name) | |
logger.debug(exc, exc_info=True) |
Codecov Report
@@ Coverage Diff @@
## master #801 +/- ##
==========================================
+ Coverage 40.67% 40.91% +0.24%
==========================================
Files 508 509 +1
Lines 27832 27846 +14
Branches 4217 4218 +1
==========================================
+ Hits 11320 11393 +73
+ Misses 16016 15979 -37
+ Partials 496 474 -22
Continue to review full report at Codecov.
|
Thank you @corranwebster |
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
Follow up from #796
In particular, this: #796 (comment)
If PythonEditor and PythonShell cannot be imported because pygments is not available, it might help if we log a debug message so that downstream projects have more information when the import fails.
The alternative would be to emit a warning, but for developers who don't care about these two classes, this could be too noisy.