A community-maintained Python framework for creating mathematical animations.
fix: importing manim should not trigger pygments.styles.get_all_styles (#3797)
Eddie Ruiz3ed86a820b01
diff --git a/manim/mobject/text/code_mobject.py b/manim/mobject/text/code_mobject.pyindex b7aa6a798..999ab3c90 100644--- a/manim/mobject/text/code_mobject.py+++ b/manim/mobject/text/code_mobject.py@@ -12,11 +12,11 @@ import refrom pathlib import Pathimport numpy as np-from pygments import highlight+from pygments import highlight, stylesfrom pygments.formatters.html import HtmlFormatterfrom pygments.lexers import get_lexer_by_name, guess_lexer_for_filename-from pygments.styles import get_all_styles+# from pygments.styles import get_all_stylesfrom manim.constants import *from manim.mobject.geometry.arc import Dotfrom manim.mobject.geometry.polygram import RoundedRectangle@@ -25,8 +25,6 @@ from manim.mobject.text.text_mobject import Paragraphfrom manim.mobject.types.vectorized_mobject import VGroupfrom manim.utils.color import WHITE-__all__ = ["Code"]-class Code(VGroup):"""A highlighted source code listing.@@ -63,7 +61,7 @@ class Code(VGroup):background_stroke_width=1,background_stroke_color=WHITE,insert_line_no=True,- style=Code.styles_list[15],+ style="emacs",background="window",language="cpp",)@@ -127,7 +125,9 @@ class Code(VGroup):line_no_buffDefines the spacing between line numbers and displayed code. Defaults to 0.4.style- Defines the style type of displayed code. You can see possible names of styles in with :attr:`styles_list`. Defaults to ``"vim"``.+ Defines the style type of displayed code. To see a list possible+ names of styles call :meth:`get_styles_list`.+ Defaults to ``"vim"``.languageSpecifies the programming language the given code was written in. If ``None``(the default), the language will be automatically detected. For the list of@@ -156,7 +156,7 @@ class Code(VGroup):# For more information about pygments.lexers visit https://pygments.org/docs/lexers/# from pygments.lexers import get_all_lexers# all_lexers = get_all_lexers()- styles_list = list(get_all_styles())+ _styles_list_cache: list[str] | None = None# For more information about pygments.styles visit https://pygments.org/docs/styles/def __init__(@@ -288,6 +288,20 @@ class Code(VGroup):)self.move_to(np.array([0, 0, 0]))+ @classmethod+ def get_styles_list(cls):+ """Get list of available code styles.++ Returns+ -------+ list[str]+ The list of available code styles to use for the ``styles``+ argument.+ """+ if cls._styles_list_cache is None:+ cls._styles_list_cache = list(styles.get_all_styles())+ return cls._styles_list_cache+def _ensure_valid_file(self):"""Function to validate file."""if self.file_name is None: