Skip to content

Commit

Permalink
requirements: Unpin pygments from ~=2.15.1 to >=2.14.0.
Browse files Browse the repository at this point in the history
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 was temporarily fixed by pinning pygments at ~=2.15.1 in zulip#1433.

Method `translate_styles` manually converts the pygments `bold italic`
style into the urwid-compatible `bold, italics` is there.

Unpin Pygments from ~=2.15.1 to >=2.14.0.

Fixes part of zulip#1434.
  • Loading branch information
jrijul1201 committed Dec 22, 2023
1 parent 24ee3f2 commit 86a61ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def long_description():
"urwid_readline>=0.13",
"beautifulsoup4>=4.11.1",
"lxml>=4.9.2",
"pygments~=2.15.1",
"pygments>=2.14.0",
"typing_extensions~=4.5.0",
"python-dateutil>=2.8.2",
"pytz>=2022.7.1",
Expand Down
16 changes: 8 additions & 8 deletions tests/config/test_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
generate_pygments_styles,
generate_theme,
parse_themefile,
translate_pygments_styles_to_urwid_styles,
generate_urwid_compatible_pygments_styles,
valid_16_color_codes,
validate_colors,
)
Expand Down Expand Up @@ -407,7 +407,7 @@ class Color3(Enum):


@pytest.mark.parametrize(
"pygments_styles, urwid_styles, style_translations",
"pygments_styles, expected_styles, style_translations",
[
case(
{},
Expand Down Expand Up @@ -444,23 +444,23 @@ class Color3(Enum):
case(
{
"token1": "style italic",
"token3": "#abc",
"token2": "#abc",
},
{
"token1": "newstyle italic",
"token3": "#abc",
"token2": "#abc",
},
{"style": "newstyle"},
id="custom_translations",
),
],
)
def test_translate_pygments_styles_to_urwid_styles(
def test_generate_urwid_compatible_pygments_styles(
pygments_styles: Dict[_TokenType, str],
urwid_styles: Dict[_TokenType, str],
expected_styles: Dict[_TokenType, str],
style_translations: Dict[str, str],
) -> None:
translated_styles = translate_pygments_styles_to_urwid_styles(
generated_styles = generate_urwid_compatible_pygments_styles(
pygments_styles, style_translations
)
assert sorted(urwid_styles) == sorted(translated_styles)
assert sorted(expected_styles.items()) == sorted(generated_styles.items())
14 changes: 5 additions & 9 deletions zulipterminal/config/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,17 @@ def parse_themefile(
return urwid_theme


def translate_pygments_styles_to_urwid_styles(
def generate_urwid_compatible_pygments_styles(
pygments_styles: Dict[_TokenType, str],
style_translations: Dict[str, str] = STYLE_TRANSLATIONS,
) -> Dict[_TokenType, str]:
"""
This function translates pygments styles into urwid compatible styles.
"""
urwid_styles = {}
urwid_compatible_styles = {}
for token, style in pygments_styles.items():
updated_style = style
for old_value, new_value in style_translations.items():
updated_style = updated_style.replace(old_value, new_value)
urwid_styles[token] = updated_style
return urwid_styles
urwid_compatible_styles[token] = updated_style
return urwid_compatible_styles


def generate_pygments_styles(pygments: Dict[str, Any]) -> ThemeSpec:
Expand All @@ -301,8 +298,7 @@ def generate_pygments_styles(pygments: Dict[str, Any]) -> ThemeSpec:
term16_bg = term16.background_color

theme_styles_from_pygments: ThemeSpec = []

pygments_styles = translate_pygments_styles_to_urwid_styles(pygments_styles)
pygments_styles = generate_urwid_compatible_pygments_styles(pygments_styles)

for token, css_class in STANDARD_TYPES.items():
if css_class in pygments_overrides:
Expand Down

0 comments on commit 86a61ed

Please sign in to comment.