-
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
Make pygments optional for pyface.api #796
Conversation
Codecov Report
@@ Coverage Diff @@
## master #796 +/- ##
==========================================
+ Coverage 40.67% 40.88% +0.21%
==========================================
Files 508 508
Lines 27832 27837 +5
Branches 4217 4217
==========================================
+ Hits 11320 11382 +62
+ Misses 16016 15981 -35
+ Partials 496 474 -22
Continue to review full report at Codecov.
|
def test_api_importable(self): | ||
# make sure api is importable with the most minimal | ||
# required dependencies, including in the absence of toolkit backends. | ||
from pyface import api # noqa: F401 |
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 verified this test failed when I have an environment with Qt but no pygments. Then the test passes after I made the change in api.py.
Ideally our CI matrix should cover more minimal setups...
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 will block usage of the PythonEditor
and the PythonShell
with wx if Pygments is not installed, even though the Wx backend doesn't use Pygments.
I think if you move this import:
from .pygments_highlighter import PygmentsHighlighter |
to here:
self.highlighter = PygmentsHighlighter(self.document(), lexer) |
And potentially, if the import fails we can just continue on with highlighter set to the default, which means graceful degradation of capabilities.
Something similar would be needed for the shell, with a slight complication that it interacts more with the highlighter.
There may be alternative approaches that work, but it feels like we want to handle this in the qt-specific code.
This change might also cause problems for TraitsUI because:
|
The concern for wx CodeEditor is legit.
I think when one does need the Qt implementation of CodeEditor, then they need to have pygments. The goal here is not to make CodeEditor work without pygments. That could be a separate issue, though. |
@corranwebster I looked into the Qt specific code you mentioned, and I find that somewhat messy. While moving the import down in PythonShell could defer the import error, it defers the error all the way to when the class is instantiated. The PythonShell, like you said, is even trickier because it is subclassing. And even if I try to make that work, the final solution does not look like it would last: It is too easy to add an import in the Qt specific modules that could reintroduce the dependency. Taking a step back, at the moment, pygments is still a core dependency for PythonShell and PythonEditor, so failing early when they are imported seems fair. What we are trying to achieve is to make I attempted the other approach which only touches |
#776 strikes again! :grumpy: |
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 OK with this implementation - it solves the immediate problem - however I think we will end up with different error reports from users about PythonEditor
and PythonShell
not importing correctly. Time will tell if this is better or worse than the current situation.
I have an alternative suggestion:
|
Something like:
|
Thanks @corranwebster
Shall I open a separate issue for this implementation option and merge this one? |
I also thought about raising a warning in the |
I will merge this now. I opened #800 for considering the alternative approach in the future (subject to feedback). I will open a separate PR on the logging idea. |
For reference, the decision for not emitting a warning is partly similar to enthought/traitsui#731. In TraitsUI, ArrayEditor is not available when NumPy is not available. While |
Closes #655
Depending on the project context, PythonEditor and PythonShell may never be needed, and yet importing
pyface.api
still requirespygments
. This PR modifiespyface.api
such that if import of PythonEditor and PythonShell fail because of missing pygments, it will carry on. It makes maintaining dependencies easier for projects that don't use PythonEditor/PythonShell.This PR does not modify the
extras_requires
in setup.py. Pip-installing pyface with the Qt tag is still going to bring in pygments, see discussion in #655.