Skip to content

Commit f68dcbd

Browse files
committed
Merge branch 'refactor-tests' of https://github.com/Darylgolden/manim into refactor-tests
2 parents c3ad5da + 56daada commit f68dcbd

31 files changed

+521
-3727
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Install Manim
4747
run: |
48-
poetry install -E webgl_renderer
48+
poetry install
4949
5050
- name: Run tests
5151
run: |
@@ -202,7 +202,7 @@ jobs:
202202
- name: Install manim
203203
run: |
204204
poetry config experimental.new-installer false
205-
poetry install -E webgl_renderer
205+
poetry install
206206
207207
- name: Run tests
208208
run: |

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ repos:
5656
flake8-docstrings==1.6.0, flake8-rst-docstrings==0.2.3,
5757
flake8-pytest-style==1.5.0, flake8-simplify==0.14.1, flake8-comprehensions>=3.6.1]
5858
- repo: https://github.com/pre-commit/mirrors-mypy
59-
rev: 'v0.941'
59+
rev: 'v0.942'
6060
hooks:
6161
- id: mypy
6262
additional_dependencies: [types-decorator, types-docutils, types-requests, types-setuptools]

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ RUN wget -O /tmp/install-tl-unx.tar.gz http://mirror.ctan.org/systems/texlive/tl
3030
# clone and build manim
3131
COPY . /opt/manim
3232
WORKDIR /opt/manim
33-
RUN pip install --no-cache .[jupyterlab,webgl_renderer]
33+
RUN pip install --no-cache .[jupyterlab]
3434

3535
RUN pip install -r docs/requirements.txt
3636

docs/source/tutorials/configuration.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ A list of all config options
360360
'progress_bar', 'quality', 'right_side', 'save_as_gif', 'save_last_frame',
361361
'save_pngs', 'scene_names', 'show_in_file_browser', 'sound', 'tex_dir',
362362
'tex_template', 'tex_template_file', 'text_dir', 'top', 'transparent',
363-
'upto_animation_number', 'use_opengl_renderer', 'use_webgl_renderer',
364-
'verbosity', 'video_dir', 'webgl_renderer_path', 'window_position',
365-
'window_monitor', 'window_size', 'write_all', 'write_to_movie', 'enable_wireframe',
366-
'force_window']
363+
'upto_animation_number', 'use_opengl_renderer', 'verbosity', 'video_dir',
364+
'window_position', 'window_monitor', 'window_size', 'write_all', 'write_to_movie',
365+
'enable_wireframe', 'force_window']

manim/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
config.renderer = parsed_renderer
2828
elif arg == "--use_opengl_renderer":
2929
config.renderer = "opengl"
30-
elif arg == "--use_webgl_renderer":
31-
config.renderer = "webgl"
3230

3331
# many scripts depend on this -> has to be loaded first
3432
from .utils.commands import * # isort:skip

manim/_config/default.cfg

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,9 @@ tex_dir = {media_dir}/Tex
9393
text_dir = {media_dir}/texts
9494
partial_movie_dir = {video_dir}/partial_movie_files/{scene_name}
9595

96-
# --renderer [cairo|opengl|webgl]
96+
# --renderer [cairo|opengl]
9797
renderer = cairo
9898

99-
# --use_webgl_renderer
100-
use_webgl_renderer = False
101-
102-
# --webgl_renderer_path
103-
webgl_renderer_path =
104-
10599
# --use_opengl_renderer
106100
use_opengl_renderer = False
107101

manim/_config/logger_utils.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import copy
1616
import json
1717
import logging
18-
import os
1918
import sys
2019
from typing import TYPE_CHECKING
2120

@@ -26,7 +25,7 @@
2625
from rich.theme import Theme
2726

2827
if TYPE_CHECKING:
29-
from manim._config.utils import ManimConfig
28+
from pathlib import Path
3029
HIGHLIGHTED_KEYWORDS = [ # these keywords are highlighted specially
3130
"Played",
3231
"animations",
@@ -142,7 +141,7 @@ def parse_theme(parser: configparser.ConfigParser) -> Theme:
142141
return custom_theme
143142

144143

145-
def set_file_logger(config: ManimConfig, verbosity: str) -> None:
144+
def set_file_logger(scene_name: str, module_name: str, log_dir: Path) -> None:
146145
"""Add a file handler to manim logger.
147146
148147
The path to the file is built using ``config.log_dir``.
@@ -152,28 +151,13 @@ def set_file_logger(config: ManimConfig, verbosity: str) -> None:
152151
config : :class:`ManimConfig`
153152
The global config, used to determine the log file path.
154153
155-
verbosity : :class:`str`
156-
The verbosity level of the logger.
157-
158-
Notes
159-
-----
160-
Calling this function changes the verbosity of all handlers assigned to
161-
manim logger.
162-
163154
"""
164155
# Note: The log file name will be
165156
# <name_of_animation_file>_<name_of_scene>.log, gotten from config. So it
166157
# can differ from the real name of the scene. <name_of_scene> would only
167158
# appear if scene name was provided when manim was called.
168-
scene_name_suffix = "".join(config["scene_names"])
169-
scene_file_name = os.path.basename(config["input_file"]).split(".")[0]
170-
log_file_name = (
171-
f"{scene_file_name}_{scene_name_suffix}.log"
172-
if scene_name_suffix
173-
else f"{scene_file_name}.log"
174-
)
175-
log_file_path = config.get_dir("log_dir") / log_file_name
176-
log_file_path.parent.mkdir(parents=True, exist_ok=True)
159+
log_file_name = f"{module_name}_{scene_name}.log"
160+
log_file_path = log_dir / log_file_name
177161

178162
file_handler = logging.FileHandler(log_file_path, mode="w")
179163
file_handler.setFormatter(JSONFormatter())
@@ -182,9 +166,6 @@ def set_file_logger(config: ManimConfig, verbosity: str) -> None:
182166
logger.addHandler(file_handler)
183167
logger.info("Log file will be saved in %(logpath)s", {"logpath": log_file_path})
184168

185-
config.verbosity = verbosity
186-
logger.setLevel(verbosity)
187-
188169

189170
class JSONFormatter(logging.Formatter):
190171
"""A formatter that outputs logs in a custom JSON format.

manim/_config/utils.py

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919
import os
2020
import re
2121
import sys
22-
import typing
2322
from collections.abc import Mapping, MutableMapping
2423
from pathlib import Path
24+
from typing import Any, Iterable, Iterator
2525

2626
import colour
2727
import numpy as np
2828

2929
from .. import constants
3030
from ..utils.tex import TexTemplate, TexTemplateFromFile
3131
from ..utils.tex_templates import TexTemplateLibrary
32-
from .logger_utils import set_file_logger
3332

3433

3534
def config_file_paths() -> list[Path]:
@@ -255,7 +254,6 @@ class MyScene(Scene):
255254
"input_file",
256255
"media_embed",
257256
"media_width",
258-
"webgl_renderer_path",
259257
"log_dir",
260258
"log_to_file",
261259
"max_files_cached",
@@ -282,7 +280,6 @@ class MyScene(Scene):
282280
"upto_animation_number",
283281
"renderer",
284282
"use_opengl_renderer",
285-
"use_webgl_renderer",
286283
"enable_gui",
287284
"gui_location",
288285
"use_projection_fill_shaders",
@@ -304,7 +301,7 @@ def __init__(self) -> None:
304301
self._d = {k: None for k in self._OPTS}
305302

306303
# behave like a dict
307-
def __iter__(self) -> typing.Iterator[str]:
304+
def __iter__(self) -> Iterator[str]:
308305
return iter(self._d)
309306

310307
def __len__(self) -> int:
@@ -317,10 +314,10 @@ def __contains__(self, key) -> bool:
317314
except AttributeError:
318315
return False
319316

320-
def __getitem__(self, key) -> typing.Any:
317+
def __getitem__(self, key) -> Any:
321318
return getattr(self, key)
322319

323-
def __setitem__(self, key: str, val: typing.Any) -> None:
320+
def __setitem__(self, key: str, val: Any) -> None:
324321
getattr(ManimConfig, key).fset(self, val) # fset is the property's setter
325322

326323
def update(self, obj: ManimConfig | dict) -> None:
@@ -395,7 +392,7 @@ def __copy__(self) -> ManimConfig:
395392
"""See ManimConfig.copy()."""
396393
return copy.deepcopy(self)
397394

398-
def __deepcopy__(self, memo: dict[str, typing.Any]) -> ManimConfig:
395+
def __deepcopy__(self, memo: dict[str, Any]) -> ManimConfig:
399396
"""See ManimConfig.copy()."""
400397
c = ManimConfig()
401398
# Deepcopying the underlying dict is enough because all properties
@@ -405,14 +402,14 @@ def __deepcopy__(self, memo: dict[str, typing.Any]) -> ManimConfig:
405402
return c
406403

407404
# helper type-checking methods
408-
def _set_from_list(self, key: str, val: typing.Any, values: list) -> None:
405+
def _set_from_list(self, key: str, val: Any, values: list) -> None:
409406
"""Set ``key`` to ``val`` if ``val`` is contained in ``values``."""
410407
if val in values:
411408
self._d[key] = val
412409
else:
413410
raise ValueError(f"attempted to set {key} to {val}; must be in {values}")
414411

415-
def _set_boolean(self, key: str | int, val: typing.Any) -> None:
412+
def _set_boolean(self, key: str | int, val: Any) -> None:
416413
"""Set ``key`` to ``val`` if ``val`` is Boolean."""
417414
if val in [True, False]:
418415
self._d[key] = val
@@ -425,7 +422,7 @@ def _set_tuple(self, key: str, val: tuple) -> None:
425422
else:
426423
raise ValueError(f"{key} must be tuple")
427424

428-
def _set_str(self, key: str, val: typing.Any) -> None:
425+
def _set_str(self, key: str, val: Any) -> None:
429426
"""Set ``key`` to ``val`` if ``val`` is a string."""
430427
if isinstance(val, str):
431428
self._d[key] = val
@@ -537,7 +534,6 @@ def digest_parser(self, parser: configparser.ConfigParser) -> ManimConfig:
537534
"flush_cache",
538535
"custom_folders",
539536
"use_opengl_renderer",
540-
"use_webgl_renderer",
541537
"enable_gui",
542538
"fullscreen",
543539
"use_projection_fill_shaders",
@@ -577,7 +573,6 @@ def digest_parser(self, parser: configparser.ConfigParser) -> ManimConfig:
577573
"movie_file_extension",
578574
"background_color",
579575
"renderer",
580-
"webgl_renderer_path",
581576
"window_position",
582577
]:
583578
setattr(self, key, parser["CLI"].get(key, fallback="", raw=True))
@@ -710,7 +705,6 @@ def digest_args(self, args: argparse.Namespace) -> ManimConfig:
710705
"renderer",
711706
"background_color",
712707
"use_opengl_renderer",
713-
"use_webgl_renderer",
714708
"enable_gui",
715709
"fullscreen",
716710
"use_projection_fill_shaders",
@@ -835,8 +829,7 @@ def digest_file(self, filename: str) -> ManimConfig:
835829
filename,
836830
)
837831

838-
if filename:
839-
return self.digest_parser(make_config_parser(filename))
832+
return self.digest_parser(make_config_parser(filename))
840833

841834
# config options are properties
842835
preview = property(
@@ -861,19 +854,11 @@ def digest_file(self, filename: str) -> ManimConfig:
861854
doc="Whether to show progress bars while rendering animations.",
862855
)
863856

864-
@property
865-
def log_to_file(self):
866-
"""Whether to save logs to a file."""
867-
return self._d["log_to_file"]
868-
869-
@log_to_file.setter
870-
def log_to_file(self, val: str) -> None:
871-
self._set_boolean("log_to_file", val)
872-
if val:
873-
log_dir = self.get_dir("log_dir")
874-
if not os.path.exists(log_dir):
875-
os.makedirs(log_dir)
876-
set_file_logger(self, self["verbosity"])
857+
log_to_file = property(
858+
lambda self: self._d["log_to_file"],
859+
lambda self, val: self._set_boolean("log_to_file", val),
860+
doc="Whether to save logs to a file.",
861+
)
877862

878863
notify_outdated_version = property(
879864
lambda self: self._d["notify_outdated_version"],
@@ -929,12 +914,6 @@ def log_to_file(self, val: str) -> None:
929914
doc="Set to force window when using the opengl renderer",
930915
)
931916

932-
dry_run = property(
933-
lambda self: self._d["dry_run"],
934-
lambda self, val: self._set_boolean("dry_run", val),
935-
doc="Enable dry_run so that no output files are generated and window is disabled.",
936-
)
937-
938917
@property
939918
def verbosity(self):
940919
"""Logger verbosity; "DEBUG", "INFO", "WARNING", "ERROR", or "CRITICAL" (-v)."""
@@ -1181,7 +1160,7 @@ def dry_run(self, val: bool) -> None:
11811160

11821161
@property
11831162
def renderer(self):
1184-
"""Renderer: "cairo", "opengl", "webgl"""
1163+
"""Renderer: "cairo", "opengl"""
11851164
return self._d["renderer"]
11861165

11871166
@renderer.setter
@@ -1221,7 +1200,7 @@ def renderer(self, val: str) -> None:
12211200
self._set_from_list(
12221201
"renderer",
12231202
val,
1224-
["cairo", "opengl", "webgl"],
1203+
["cairo", "opengl"],
12251204
)
12261205

12271206
@property
@@ -1236,31 +1215,9 @@ def use_opengl_renderer(self, val: bool) -> None:
12361215
self._set_from_list(
12371216
"renderer",
12381217
"opengl",
1239-
["cairo", "opengl", "webgl"],
1218+
["cairo", "opengl"],
12401219
)
12411220

1242-
@property
1243-
def use_webgl_renderer(self):
1244-
"""Whether or not to use WebGL renderer."""
1245-
return self._d["use_webgl_renderer"]
1246-
1247-
@use_webgl_renderer.setter
1248-
def use_webgl_renderer(self, val: bool) -> None:
1249-
self._d["use_webgl_renderer"] = val
1250-
if val:
1251-
self._set_from_list(
1252-
"webgl",
1253-
"renderer",
1254-
["cairo", "opengl", "webgl"],
1255-
)
1256-
self["disable_caching"] = True
1257-
1258-
webgl_renderer_path = property(
1259-
lambda self: self._d["webgl_renderer_path"],
1260-
lambda self, val: self._d.__setitem__("webgl_renderer_path", val),
1261-
doc="Path to WebGL renderer.",
1262-
)
1263-
12641221
media_dir = property(
12651222
lambda self: self._d["media_dir"],
12661223
lambda self, val: self._set_dir("media_dir", val),
@@ -1637,15 +1594,15 @@ def __init__(self, c: ManimConfig) -> None:
16371594
self.__dict__["_c"] = c
16381595

16391596
# there are required by parent class Mapping to behave like a dict
1640-
def __getitem__(self, key: str | int) -> typing.Any:
1597+
def __getitem__(self, key: str | int) -> Any:
16411598
if key in self._OPTS:
16421599
return self._c[key]
16431600
elif key in self._CONSTANTS:
16441601
return self._CONSTANTS[key]
16451602
else:
16461603
raise KeyError(key)
16471604

1648-
def __iter__(self) -> typing.Iterable:
1605+
def __iter__(self) -> Iterable:
16491606
return iter(list(self._OPTS) + list(self._CONSTANTS))
16501607

16511608
def __len__(self) -> int:

0 commit comments

Comments
 (0)