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

Log debug message if import PythonShell and PythonEditor fail in api.py #801

Merged
merged 4 commits into from
Nov 30, 2020

Conversation

kitchoi
Copy link
Contributor

@kitchoi kitchoi commented Nov 12, 2020

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.

import logging


_PYFACE_LOGGER = logging.getLogger("pyface")
Copy link
Contributor

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.

Copy link
Contributor

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"):
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

logger.info(msg, plugin.name, module_name)
logger.debug(exc, exc_info=True)

@codecov-io
Copy link

Codecov Report

Merging #801 (0533b1e) into master (4bccc3e) will increase coverage by 0.24%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
pyface/api.py 100.00% <100.00%> (ø)
pyface/util/_optional_dependencies.py 100.00% <100.00%> (ø)
pyface/ui/qt4/tasks/split_editor_area_pane.py 65.41% <0.00%> (+0.59%) ⬆️
pyface/ui/qt4/console/console_widget.py 29.28% <0.00%> (+0.72%) ⬆️
pyface/ui/qt4/tasks/advanced_editor_area_pane.py 51.72% <0.00%> (+0.86%) ⬆️
pyface/wx/python_stc.py 10.36% <0.00%> (+1.21%) ⬆️
pyface/ui/qt4/tasks/task_window_backend.py 60.52% <0.00%> (+1.31%) ⬆️
pyface/ui/qt4/code_editor/code_widget.py 44.39% <0.00%> (+1.69%) ⬆️
pyface/ui/qt4/tasks/editor_area_pane.py 55.88% <0.00%> (+2.20%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b7311f...64f8448. Read the comment docs.

@kitchoi
Copy link
Contributor Author

kitchoi commented Nov 17, 2020

Thank you @corranwebster
I have addressed the comments, apart from the logging level: I am not entirely sure which of info or debug we should use or if we should log both.

Copy link
Contributor

@corranwebster corranwebster left a comment

Choose a reason for hiding this comment

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

LGTM

@kitchoi kitchoi merged commit adee624 into master Nov 30, 2020
@kitchoi kitchoi deleted the log-debug-if-fail-to-import branch November 30, 2020 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants