From 0e574882b3bf321cb995614c302bd52342b5a413 Mon Sep 17 00:00:00 2001 From: Michael W <50232075+YishiMichael@users.noreply.github.com> Date: Sat, 16 Oct 2021 13:04:52 +0800 Subject: [PATCH] Refactor #1637 (#1650) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactor #1637 * Refactor #1637 * Refactor #1637 * Refactor #1637 * Refactor #1637 * Refactor #1637 * Update config.py Co-authored-by: 鹤翔万里 --- manimlib/__main__.py | 6 +++--- manimlib/config.py | 12 ++++++------ manimlib/logger.py | 5 ++++- manimlib/scene/scene.py | 14 ++++++-------- manimlib/scene/scene_file_writer.py | 2 +- manimlib/utils/bezier.py | 6 +++--- manimlib/utils/init_config.py | 1 + requirements.txt | 1 + setup.cfg | 2 ++ 9 files changed, 27 insertions(+), 22 deletions(-) diff --git a/manimlib/__main__.py b/manimlib/__main__.py index 82e9b38f58..615c1df49f 100644 --- a/manimlib/__main__.py +++ b/manimlib/__main__.py @@ -6,9 +6,9 @@ def main(): - args = manimlib.config.parse_cli() - print(f"ManimGL \033[32mv{__version__}\033[0m") + + args = manimlib.config.parse_cli() if args.version and args.file == None: return @@ -21,5 +21,5 @@ def main(): for scene in scenes: scene.run() -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/manimlib/config.py b/manimlib/config.py index 636adb71cf..cbb2942aec 100644 --- a/manimlib/config.py +++ b/manimlib/config.py @@ -193,9 +193,9 @@ def get_custom_config(): def check_temporary_storage(config): if config["directories"]["temporary_storage"] == "" and sys.platform == "win32": - log.warning("You may be using Windows platform and have not specified the `temporary\ -_storage` path, which may cause OSError. So it is recommended that you specify the `temporary\ -_storage` in the config file (.yml)") + log.warning("You may be using Windows platform and have not specified the path of" + " `temporary_storage`, which may cause OSError. So it is recommended" + " to specify the `temporary_storage` in the config file (.yml)") def get_configuration(args): @@ -220,13 +220,13 @@ def get_configuration(args): global_defaults_file = os.path.join(get_manim_dir(), "manimlib", "default_config.yml") if not (os.path.exists(global_defaults_file) or os.path.exists(__config_file__)): - log.info("There is no configuration file detected. Initial configuration:\n") + log.info("There is no configuration file detected. Switch to the config file initializer:") init_customization() elif not os.path.exists(__config_file__): log.info(f"Using the default configuration file, which you can modify in `{global_defaults_file}`") - log.info(f"If you want to create a local configuration file, you can create a file named \ -`{__config_file__}`, or run `manimgl --config`") + log.info("If you want to create a local configuration file, you can create a file named" + f" `{__config_file__}`, or run `manimgl --config`") custom_config = get_custom_config() check_temporary_storage(custom_config) diff --git a/manimlib/logger.py b/manimlib/logger.py index b8f9fa36d6..874415527f 100644 --- a/manimlib/logger.py +++ b/manimlib/logger.py @@ -1,9 +1,12 @@ import logging from rich.logging import RichHandler +__all__ = ["log"] + + FORMAT = "%(message)s" logging.basicConfig( level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()] ) -log = logging.getLogger("rich") \ No newline at end of file +log = logging.getLogger("rich") diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index 21f0524145..118404be3b 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -10,10 +10,10 @@ from manimlib.animation.animation import prepare_animation from manimlib.animation.transform import MoveToTarget -from manimlib.mobject.mobject import Point from manimlib.camera.camera import Camera from manimlib.constants import DEFAULT_WAIT_TIME from manimlib.mobject.mobject import Mobject +from manimlib.mobject.mobject import Point from manimlib.scene.scene_file_writer import SceneFileWriter from manimlib.utils.config_ops import digest_config from manimlib.utils.family_ops import extract_mobject_family_members @@ -101,8 +101,8 @@ def interact(self): # If there is a window, enter a loop # which updates the frame while under # the hood calling the pyglet event loop - log.info("Tips: You are now in the interactive mode. Now you can use the keyboard\ -and the mouse to interact with the scene. Just press `q` if you want to quit.") + log.info("Tips: You are now in the interactive mode. Now you can use the keyboard" + " and the mouse to interact with the scene. Just press `q` if you want to quit.") self.quit_interaction = False self.lock_static_mobject_data() while not (self.window.is_closing or self.quit_interaction): @@ -134,8 +134,8 @@ def embed(self): local_ns["touch"] = self.interact for term in ("play", "wait", "add", "remove", "clear", "save_state", "restore"): local_ns[term] = getattr(self, term) - log.info("Tips: Now the embed iPython terminal is open. But you can't interact with \ -the window directly. To do so, you need to type `touch()` or `self.interact()`") + log.info("Tips: Now the embed iPython terminal is open. But you can't interact with" + " the window directly. To do so, you need to type `touch()` or `self.interact()`") shell(local_ns=local_ns, stack_depth=2) # End scene when exiting an embed. raise EndSceneEarlyException() @@ -463,9 +463,7 @@ def finish_animations(self, animations): @handle_play_like_call def play(self, *args, **kwargs): if len(args) == 0: - log.warning( - "Called Scene.play with no animations" - ) + log.warning("Called Scene.play with no animations") return animations = self.anims_from_play_args(*args, **kwargs) self.lock_static_mobject_data(*animations) diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index 8d74765e3b..3269b416ab 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -301,7 +301,7 @@ def save_final_image(self, image): self.print_file_ready_message(file_path) def print_file_ready_message(self, file_path): - log.info(f"\nFile ready at {file_path}\n") + log.info(f"File ready at {file_path}") def should_open_file(self): return any([ diff --git a/manimlib/utils/bezier.py b/manimlib/utils/bezier.py index f531758427..c6b750e16a 100644 --- a/manimlib/utils/bezier.py +++ b/manimlib/utils/bezier.py @@ -69,9 +69,9 @@ def interpolate(start, end, alpha): try: return (1 - alpha) * start + alpha * end except TypeError: - log.debug(type(start), start.dtype) - log.debug(type(end), start.dtype) - log.debug(alpha) + log.debug(f"`start` parameter with type `{type(start)}` and dtype `{start.dtype}`") + log.debug(f"`end` parameter with type `{type(end)}` and dtype `{end.dtype}`") + log.debug(f"`alpha` parameter with value `{alpha}`") import sys sys.exit(2) diff --git a/manimlib/utils/init_config.py b/manimlib/utils/init_config.py index 10a0b8ba19..db33cd709c 100644 --- a/manimlib/utils/init_config.py +++ b/manimlib/utils/init_config.py @@ -46,6 +46,7 @@ def init_customization(): } } + print("Initialize configuration") scope = input(" Please select the scope of the configuration [global/local]: ") if scope == "global": from manimlib.config import get_manim_dir diff --git a/requirements.txt b/requirements.txt index 1b85903b2b..e10b45212b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ moderngl_window pydub pygments pyyaml +rich screeninfo pyreadline; sys_platform == 'win32' validators diff --git a/setup.cfg b/setup.cfg index 3b3ed5fdef..403729d651 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,7 +29,9 @@ install_requires = moderngl moderngl_window pydub + pygments pyyaml + rich screeninfo pyreadline; sys_platform == 'win32' validators