From 86a61ed34b9608eb2d9ce1a9fba65d56bcaeae8a Mon Sep 17 00:00:00 2001 From: jrijul1201 Date: Thu, 21 Dec 2023 15:52:30 +0530 Subject: [PATCH] requirements: Unpin pygments from ~=2.15.1 to >=2.14.0. 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 #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 #1434. --- setup.py | 2 +- tests/config/test_themes.py | 16 ++++++++-------- zulipterminal/config/themes.py | 14 +++++--------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/setup.py b/setup.py index 7b416d844d..b8d27a53e3 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tests/config/test_themes.py b/tests/config/test_themes.py index e7535e44d0..347ccc7e18 100644 --- a/tests/config/test_themes.py +++ b/tests/config/test_themes.py @@ -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, ) @@ -407,7 +407,7 @@ class Color3(Enum): @pytest.mark.parametrize( - "pygments_styles, urwid_styles, style_translations", + "pygments_styles, expected_styles, style_translations", [ case( {}, @@ -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()) diff --git a/zulipterminal/config/themes.py b/zulipterminal/config/themes.py index ca3b96f8e8..7c6dfe56da 100644 --- a/zulipterminal/config/themes.py +++ b/zulipterminal/config/themes.py @@ -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: @@ -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: