Skip to content

Commit 4b05f22

Browse files
authored
fix(cli): disable printing "Manim Community v..." (#9)
1 parent 1da3492 commit 4b05f22

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

manim_slides/manim.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
import os
12
import sys
3+
from contextlib import contextmanager
24
from importlib.util import find_spec
35

6+
7+
@contextmanager
8+
def suppress_stdout():
9+
with open(os.devnull, "w") as devnull:
10+
old_stdout = sys.stdout
11+
sys.stdout = devnull
12+
try:
13+
yield
14+
finally:
15+
sys.stdout = old_stdout
16+
17+
418
MANIM_PACKAGE_NAME = "manim"
519
MANIM_AVAILABLE = find_spec(MANIM_PACKAGE_NAME) is not None
620
MANIM_IMPORTED = MANIM_PACKAGE_NAME in sys.modules
@@ -17,14 +31,20 @@
1731
)
1832
MANIM = True
1933
MANIMGL = False
20-
elif MANIM_AVAILABLE and not MANIMGL_IMPORTED:
34+
elif MANIM_IMPORTED:
35+
MANIM = True
36+
MANIMGL = False
37+
elif MANIMGL_IMPORTED:
38+
MANIM = False
39+
MANIMGL = True
40+
elif MANIM_AVAILABLE:
2141
MANIM = True
2242
MANIMGL = False
2343
elif MANIMGL_AVAILABLE:
2444
MANIM = False
2545
MANIMGL = True
2646
else:
27-
raise ImportError(
47+
raise ModuleNotFoundError(
2848
"Either manim (community) or manimgl (3b1b) package must be installed"
2949
)
3050

@@ -37,9 +57,10 @@
3757
from manimlib.logger import log as logger
3858

3959
else:
40-
from manim import Scene, ThreeDScene, config, logger
60+
with suppress_stdout(): # Avoids printing "Manim Community v..."
61+
from manim import Scene, ThreeDScene, config, logger
4162

42-
try: # For manim<v0.16.0.post0
43-
from manim.constants import FFMPEG_BIN as FFMPEG_BIN
44-
except ImportError:
45-
FFMPEG_BIN = config.ffmpeg_executable
63+
try: # For manim<v0.16.0.post0
64+
from manim.constants import FFMPEG_BIN as FFMPEG_BIN
65+
except ImportError:
66+
FFMPEG_BIN = config.ffmpeg_executable

0 commit comments

Comments
 (0)