diff --git a/.gitignore b/.gitignore index f19cb13b..0dd14596 100644 --- a/.gitignore +++ b/.gitignore @@ -147,5 +147,5 @@ dmypy.json # For manim /videos -/custom_defaults.yml -/manimlib/defaults.yml \ No newline at end of file +/custom_config.yml +/manimlib/default_config.yml \ No newline at end of file diff --git a/README.md b/README.md index 86b6f346..d74f0466 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Some useful flags include: * `-n ` to skip ahead to the `n`'th animation of a scene. * `-f` to make the playback window fullscreen -Take a look at custom_defaults.yml for further configuration. To add your customization, you can either edit this file, or add another file by the same name "custom_defaults.yml" to whatever directory you are running manim from. For example [this is the one](https://github.com/3b1b/videos/blob/master/custom_defaults.yml) for 3blue1brown videos. There you can specify where videos should be output to, where manim should look for image files and sounds you want to read in, and other defaults regarding style and video quality. +Take a look at custom_config.yml for further configuration. To add your customization, you can either edit this file, or add another file by the same name "custom_config.yml" to whatever directory you are running manim from. For example [this is the one](https://github.com/3b1b/videos/blob/master/custom_config.yml) for 3blue1brown videos. There you can specify where videos should be output to, where manim should look for image files and sounds you want to read in, and other defaults regarding style and video quality. Look through the [example scenes](https://3b1b.github.io/manim/getting_started/example_scenes.html) to get a sense of how it is used, and feel free to look through the code behind [3blue1brown videos](https://github.com/3b1b/videos) for a much larger set of example. Note, however, that developments are often made to the library without considering backwards compatibility with those old videos. To run an old project with a guarantee that it will work, you will have to go back to the commit which completed that project. diff --git a/docs/source/getting_started/example_scenes.rst b/docs/source/getting_started/example_scenes.rst index e33efd0b..efc6c16c 100644 --- a/docs/source/getting_started/example_scenes.rst +++ b/docs/source/getting_started/example_scenes.rst @@ -355,7 +355,7 @@ SurfaceExample # be interpreted as the side towards the light, and away from # the light. These can be either urls, or paths to a local file # in whatever you've set as the image directory in - # the custom_defaults.yml file + # the custom_config.yml file # day_texture = "EarthTextureMap" # night_texture = "NightEarthTextureMap" diff --git a/example_scenes.py b/example_scenes.py index f881a1b5..4dddbf4c 100644 --- a/example_scenes.py +++ b/example_scenes.py @@ -380,7 +380,7 @@ class SurfaceExample(Scene): # be interpreted as the side towards the light, and away from # the light. These can be either urls, or paths to a local file # in whatever you've set as the image directory in - # the custom_defaults.yml file + # the custom_config.yml file # day_texture = "EarthTextureMap" # night_texture = "NightEarthTextureMap" diff --git a/manimlib/config.py b/manimlib/config.py index 583d26bb..2970b478 100644 --- a/manimlib/config.py +++ b/manimlib/config.py @@ -156,9 +156,9 @@ def get_module(file_name): return module -def get_custom_defaults(): - filename = "custom_defaults.yml" - global_defaults_file = os.path.join(get_manim_dir(), "manimlib", "defaults.yml") +def get_custom_config(): + filename = "custom_config.yml" + 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(filename)): print("There is no configuration file detected. Initial configuration:\n") @@ -166,27 +166,29 @@ def get_custom_defaults(): if os.path.exists(global_defaults_file): with open(global_defaults_file, "r") as file: - custom_defaults = yaml.safe_load(file) + config = yaml.safe_load(file) + + if os.path.exists(filename): + with open(filename, "r") as file: + local_defaults = yaml.safe_load(file) + if local_defaults: + config = merge_dicts_recursively( + config, + local_defaults, + ) + else: with open(filename, "r") as file: - local_defaults = yaml.safe_load(file) + config = yaml.safe_load(file) - # See if there's a custom_defaults file in current directory, + # See if there's a custom_config file in current directory, # and if so, it further updates the defaults based on it. - if os.path.exists(filename): - with open(filename, "r") as file: - local_defaults = yaml.safe_load(file) - if local_defaults: - custom_defaults = merge_dicts_recursively( - custom_defaults, - local_defaults, - ) - - return custom_defaults + + return config def get_configuration(args): - custom_defaults = get_custom_defaults() + custom_config = get_custom_config() write_file = any([args.write_file, args.open, args.finder]) if args.transparent: @@ -198,14 +200,14 @@ def get_configuration(args): file_writer_config = { "write_to_movie": not args.skip_animations and write_file, - "break_into_partial_movies": custom_defaults["break_into_partial_movies"], + "break_into_partial_movies": custom_config["break_into_partial_movies"], "save_last_frame": args.skip_animations and write_file, "save_pngs": args.save_pngs, # If -t is passed in (for transparent), this will be RGBA "png_mode": "RGBA" if args.transparent else "RGB", "movie_file_extension": file_ext, - "mirror_module_path": custom_defaults["directories"]["mirror_module_path"], - "output_directory": args.video_dir or custom_defaults["directories"]["output"], + "mirror_module_path": custom_config["directories"]["mirror_module_path"], + "output_directory": args.video_dir or custom_config["directories"]["output"], "file_name": args.file_name, "input_file_path": args.file or "", "open_file_upon_completion": args.open, @@ -227,7 +229,7 @@ def get_configuration(args): } # Camera configuration - config["camera_config"] = get_camera_configuration(args, custom_defaults) + config["camera_config"] = get_camera_configuration(args, custom_config) # Default to putting window in the upper right of screen, # but make it full screen if -f is passed in @@ -257,9 +259,9 @@ def get_configuration(args): return config -def get_camera_configuration(args, custom_defaults): +def get_camera_configuration(args, custom_config): camera_config = {} - camera_qualities = get_custom_defaults()["camera_qualities"] + camera_qualities = get_custom_config()["camera_qualities"] if args.low_quality: quality = camera_qualities["low"] elif args.medium_quality: @@ -287,7 +289,7 @@ def get_camera_configuration(args, custom_defaults): }) try: - bg_color = args.color or custom_defaults["style"]["background_color"] + bg_color = args.color or custom_config["style"]["background_color"] camera_config["background_color"] = colour.Color(bg_color) except AttributeError as err: print("Please use a valid color") diff --git a/manimlib/extract_scene.py b/manimlib/extract_scene.py index 7a537769..6036765f 100644 --- a/manimlib/extract_scene.py +++ b/manimlib/extract_scene.py @@ -3,12 +3,12 @@ import sys import logging from manimlib.scene.scene import Scene -from manimlib.config import get_custom_defaults +from manimlib.config import get_custom_config class BlankScene(Scene): def construct(self): - exec(get_custom_defaults()["universal_import_line"]) + exec(get_custom_config()["universal_import_line"]) self.embed() diff --git a/manimlib/utils/customization.py b/manimlib/utils/customization.py index 333a41c6..bf79b1b8 100644 --- a/manimlib/utils/customization.py +++ b/manimlib/utils/customization.py @@ -1,7 +1,7 @@ import os import tempfile -from manimlib.config import get_custom_defaults +from manimlib.config import get_custom_config from manimlib.config import get_manim_dir CUSTOMIZATION = {} @@ -9,7 +9,7 @@ CUSTOMIZATION = {} def get_customization(): if not CUSTOMIZATION: - CUSTOMIZATION.update(get_custom_defaults()) + CUSTOMIZATION.update(get_custom_config()) directories = CUSTOMIZATION["directories"] # Unless user has specified otherwise, use the system default temp # directory for storing tex files, mobject_data, etc. diff --git a/manimlib/utils/init_config.py b/manimlib/utils/init_config.py index c94fc46f..064db879 100644 --- a/manimlib/utils/init_config.py +++ b/manimlib/utils/init_config.py @@ -48,9 +48,9 @@ def init_customization(): scope = input(" Please select the scope of the configuration [global/local]: ") if scope == "global": from manimlib.config import get_manim_dir - file_name = os.path.join(get_manim_dir(), "manimlib", "defaults.yml") + file_name = os.path.join(get_manim_dir(), "manimlib", "default_config.yml") else: - file_name = os.path.join(os.getcwd(), "custom_defaults.yml") + file_name = os.path.join(os.getcwd(), "custom_config.yml") print("\n directories:") configuration["directories"]["output"] = input(" [1/8] Where should manim output video and image files place: ") diff --git a/manimlib/utils/tex_file_writing.py b/manimlib/utils/tex_file_writing.py index 77716986..4d76d300 100644 --- a/manimlib/utils/tex_file_writing.py +++ b/manimlib/utils/tex_file_writing.py @@ -6,7 +6,7 @@ from contextlib import contextmanager from manimlib.utils.directories import get_tex_dir from manimlib.config import get_manim_dir -from manimlib.config import get_custom_defaults +from manimlib.config import get_custom_config SAVED_TEX_CONFIG = {} @@ -25,8 +25,8 @@ def get_tex_config(): """ # Only load once, then save thereafter if not SAVED_TEX_CONFIG: - custom_defaults = get_custom_defaults() - SAVED_TEX_CONFIG.update(custom_defaults["tex"]) + custom_config = get_custom_config() + SAVED_TEX_CONFIG.update(custom_config["tex"]) # Read in template file template_filename = os.path.join( get_manim_dir(), "manimlib", "tex_templates",