Clean up the diff a little bit

This commit is contained in:
JasonGrace2282 2024-09-08 16:06:08 -04:00
commit bfaa9003ea
No known key found for this signature in database
GPG key ID: 8D61FE3F93FB15FA
5 changed files with 25 additions and 42 deletions

View file

@ -101,10 +101,6 @@ def make_logger(
logger.setLevel(verbosity)
logger.propagate = False
if not (libav_logger := logging.getLogger()).hasHandlers():
libav_logger.addHandler(rich_handler)
libav_logger.setLevel(verbosity)
if not (libav_logger := logging.getLogger()).hasHandlers():
libav_logger.addHandler(rich_handler)
libav_logger.setLevel(verbosity)

View file

@ -19,11 +19,8 @@ __all__ = ("AnimationProtocol",)
class AnimationProtocol(Protocol):
"""A protocol that all animations must implement."""
# it has internal mutability, so we don't need a setter
@property
def buffer(self) -> SceneBuffer:
"""The interface to the scene. This can be used to add, remove, or replace mobjects on the scene."""
raise NotImplementedError
buffer: SceneBuffer
"""The interface to the scene. This can be used to add, remove, or replace mobjects on the scene."""
apply_buffer: bool
"""Normally, the buffer is only applied at the beginning and end of an animation.

View file

@ -24,7 +24,7 @@ from manim.cli.render.ease_of_access_options import ease_of_access_options
from manim.cli.render.global_options import global_options
from manim.cli.render.output_options import output_options
from manim.cli.render.render_options import render_options
from manim.constants import EPILOG, RendererType
from manim.constants import EPILOG
from manim.manager import Manager
from manim.utils.module_ops import scene_classes_from_file
@ -83,28 +83,14 @@ def render(
config.digest_args(click_args)
file = Path(config.input_file)
if config.renderer == RendererType.OPENGL:
try:
keep_running = True
while keep_running:
for SceneClass in scene_classes_from_file(file):
with tempconfig({}):
manager = Manager(SceneClass)
rerun = manager.render()
if rerun or config["write_all"]:
manager.scene.num_plays = 0
continue
else:
keep_running = False
break
if config["write_all"]:
keep_running = False
except Exception:
error_console.print_exception()
sys.exit(1)
else:
raise NotImplementedError
try:
for SceneClass in scene_classes_from_file(file):
with tempconfig({}):
manager = Manager(SceneClass)
manager.render()
except Exception:
error_console.print_exception()
sys.exit(1)
if config.notify_outdated_version:
manim_info_url = "https://pypi.org/pypi/manim/json"

View file

@ -83,6 +83,10 @@ class FileWriter(FileWriterProtocol):
name="autocreated", type_=DefaultSectionType.NORMAL, skip_animations=False
)
@classmethod
def use_output_as_scene_name(cls) -> None:
cls.force_output_as_scene_name = True
def init_output_directories(self, scene_name: str) -> None:
"""Initialise output directories.

View file

@ -84,33 +84,33 @@ def get_scene_classes_from_module(module: types.ModuleType) -> list[type[Scene]]
]
def get_scenes_to_render(scene_classes: Sequence[type[Scene]]) -> list[type[Scene]]:
def get_scenes_to_render(scene_classes: Sequence[type[Scene]]) -> Sequence[type[Scene]]:
if not scene_classes:
logger.error(constants.NO_SCENE_MESSAGE)
return []
if config["write_all"]:
if config.write_all:
return scene_classes
result = []
for scene_name in config["scene_names"]:
found = False
for scene_name in config.scene_names:
if not scene_name:
continue
for scene_class in scene_classes:
if scene_class.__name__ == scene_name:
result.append(scene_class)
found = True
break
if not found and (scene_name != ""):
else:
logger.error(constants.SCENE_NOT_FOUND_MESSAGE.format(scene_name))
if result:
return result
if len(scene_classes) == 1:
config["scene_names"] = [scene_classes[0].__name__]
config.scene_names = [scene_classes[0].__name__]
return [scene_classes[0]]
return prompt_user_for_choice(scene_classes)
def prompt_user_for_choice(scene_classes: Iterable[type[Scene]]) -> list[type[Scene]]:
num_to_class = {}
FileWriter.force_output_as_scene_name = True
FileWriter.use_output_as_scene_name()
for count, scene_class in enumerate(scene_classes, 1):
name = scene_class.__name__
console.print(f"{count}: {name}", style="logging.level.info")
@ -137,7 +137,7 @@ def prompt_user_for_choice(scene_classes: Iterable[type[Scene]]) -> list[type[Sc
def scene_classes_from_file(
file_path: Path, require_single_scene: bool = False, full_list: bool = False
) -> type[Scene] | list[type[Scene]]:
) -> Sequence[type[Scene]]:
module = get_module(file_path)
all_scene_classes = get_scene_classes_from_module(module)
if full_list:
@ -145,5 +145,5 @@ def scene_classes_from_file(
scene_classes_to_render = get_scenes_to_render(all_scene_classes)
if require_single_scene:
assert len(scene_classes_to_render) == 1
return scene_classes_to_render[0]
return [scene_classes_to_render[0]]
return scene_classes_to_render