-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
config/themes: Convert pygments styles to urwid compatible styles. #1452
Conversation
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.
@jrijul1201 Thanks for working on this! 👍
I tried upgrading pygments, and I at least don't have an issue with a crash. I would assume it's making a correct translation, and would suggest a before and after comparison - except that the pygments styles did change, of course!
Most of my comments are minor, with the exception of ensuring the tests cover what you expect.
You're welcome to add a commit to upgrade pygments following the standard form we've used in the past.
tests/config/test_themes.py
Outdated
for style in expected_styles: | ||
assert style in pygments_styles |
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 doesn't test what you might think; I can alter the input or output styles and the tests all pass.
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.
Fixed, Thanks a lot for the thorough review!
16a94be
to
24ee3f2
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.
@jrijul1201 Good changes, with a few suggestions - though give those tests a reread/explore :)
9e3b6b1
to
0ac17c0
Compare
The previous commit in zulip#1452 fixes the issue zulip#1431 that was temporarily fixed by pinning Pygments at ~=2.15.1. Combined with <2.18.0, since that unreleased version depends on Python3.8 and could make ZT uninstallable on older pythons. Fixes part of zulip#1434.
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.
@jrijul1201 Thanks for the update 👍
Your latest push was great, and I've just pushed a very slightly updated version here, which I'll merge shortly :)
The inline comments were some minor feedback on the tests to consider in the future - I've addressed them in my push.
I also updated the commit text for the first commit
bold strong
seemed incorrect vsbold italic
?- there is no longer a 'translate_styles' function; instead I clarified it minimally covers certain translations, and not all of the possibilities from pygments (which may change in future, of course)
For details of any other changes, I'd suggest you use git range-diff
or an equivalent tool.
tests/config/test_themes.py
Outdated
"token1": "bold italic", | ||
"token2": "italic bold", | ||
"token3": "italic #abc", |
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 case tests multiple aspects at once - that's fine, depending on how small we wish each test/case to be.
However, if these were separate tests, we might give ids to the tokens to indicate the reason for including them. For here, it therefore could be useful to add a few minimal comments to indicate eg. lack of ordering-dependence, and working with colors.
tests/config/test_themes.py
Outdated
def test_generate_urwid_compatible_pygments_styles( | ||
pygments_styles: Dict[_TokenType, str], | ||
expected_styles: Dict[_TokenType, str], | ||
style_translations: Dict[str, str], | ||
) -> None: |
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's great to have the annotations here 👍
This works fine in the test itself, however note that mypy/pytest doesn't validate that the parametrize values match these types, only that the function parameters work with the body.
That doesn't invalidate the test, as long as we acknowledge that we're using placeholder values, with eg. a comment regarding the "token"
values (str
) not being of type _TokenType
.
To improve upon this, one could imagine testing with actual pygments styles, but that's not necessary for this PR.
generated_styles = generate_urwid_compatible_pygments_styles( | ||
pygments_styles, style_translations | ||
) | ||
assert sorted(expected_styles.items()) == sorted(generated_styles.items()) |
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 looks good 👍
The test values are good to cover many cases, but we can also assert the keys are unchanged, as a quick check before we look at the values. That allows a test to fail with a more significant assertion first.
Pygments 2.16.0 introduced a style to support a combination of bold and italic styling in pygments/pygments#2444. Both of our gruvbox themes and the light native theme gain a 'bold italic' style via pygments as a result, which urwid fails to parse and blocks the application from loading. This work would represent a clean fix for zulip#1431, which was temporarily fixed by pinning pygments at ~=2.15.1 in zulip#1433. This minimally handles spaces and the shortened `italic` in pygments styles, sufficient to resolve the current style issue. Note that other pygments styles in themes that we do not yet use may need additional translation or adjustment. Tests added. Fixes part of zulip#1434.
The previous commit fixes the issue zulip#1431 that was temporarily fixed by pinning pygments at ~=2.15.1 in zulip#1433. Subsequent versions of pygments have since been released, but an upper limit of 2.18.0 is included, since that unreleased version depends on Python3.8 and could make ZT uninstallable on older pythons. Fixes part of zulip#1434.
@jrijul1201 Thanks for your work on this 👍 I rebased over the CI workaround in #1458, so merged this a little later than anticipated, but it's in now :) 🎉 |
What does this PR do, and why?
Pygments 2.16.0 introduced a style to support a combination of bold and italic styling in pygments/pygments#2444. Both of our gruvbox themes and the light native theme gain a 'bold strong' style via pygments as a result, which urwid fails to parse and blocks the application from loading.
This work would represent a clean fix for #1431, which was temporarily fixed by pinning pygments at ~=2.15.1 in #1433. Pygments can be unpinned after this fix.
Add method
translate_styles
that manually converts the pygmentsbold italic
style into the urwid-compatiblebold, italics
.In requirements, unpin pygments from
~=2.15.1
to>=2.14.0,<2.18.0
.External discussion & connections
Translate pygments styles into urwid #T1434 #T1452
How did you test this?
Self-review checklist for each commit