Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

delete old/unsed/moved stuff

leotrs12a5055a2d79
diff --git a/manim/config/main_utils.py b/manim/config/main_utils.py
index fbe93dbb6..faa5ecc9a 100644
--- a/manim/config/main_utils.py
+++ b/manim/config/main_utils.py
@@ -423,273 +423,3 @@ def _parse_args_no_subcmd(args):
)
return parser.parse_args(args[1:])
-
-
-def update_config_with_cli(args):
- """Update the config dictionaries after parsing CLI flags."""
- parser = make_config_parser()
- default = parser["CLI"]
-
- ## Update config
- global config
-
- # Handle the *_quality flags. These determine the section to read
- # and are stored in 'camera_config'. Note the highest resolution
- # passed as argument will be used.
- quality = _determine_quality(args)
- section = parser[quality if quality != constants.DEFAULT_QUALITY else "CLI"]
-
- # Loop over low quality for the keys, could be any quality really
- config.update({opt: section.getint(opt) for opt in parser["low_quality"]})
-
- # The -r, --resolution flag overrides the *_quality flags
- if args.resolution is not None:
- if "," in args.resolution:
- height_str, width_str = args.resolution.split(",")
- height, width = int(height_str), int(width_str)
- else:
- height = int(args.resolution)
- width = int(16 * height / 9)
- config.update({"pixel_height": height, "pixel_width": width})
-
- # Handle the -c (--background_color) flag
- if args.background_color is not None:
- try:
- background_color = colour.Color(args.background_color)
- except AttributeError as err:
- logger.warning("Please use a valid color.")
- logger.error(err)
- sys.exit(2)
- else:
- background_color = colour.Color(default["background_color"])
- config["background_color"] = background_color
-
- config["use_js_renderer"] = args.use_js_renderer or default.getboolean(
- "use_js_renderer"
- )
- config["js_renderer_path"] = args.js_renderer_path or default.get(
- "js_renderer_path"
- )
-
- # Set the rest of the frame properties
- config["frame_height"] = 8.0
- config["frame_width"] = (
- config["frame_height"] * config["pixel_width"] / config["pixel_height"]
- )
- config["frame_y_radius"] = config["frame_height"] / 2
- config["frame_x_radius"] = config["frame_width"] / 2
- config["top"] = config["frame_y_radius"] * constants.UP
- config["bottom"] = config["frame_y_radius"] * constants.DOWN
- config["left_side"] = config["frame_x_radius"] * constants.LEFT
- config["right_side"] = config["frame_x_radius"] * constants.RIGHT
-
- # Handle the --tex_template flag, if the flag is absent read it from the config.
- if args.tex_template:
- tex_fn = os.path.expanduser(args.tex_template)
- else:
- tex_fn = default["tex_template"] if default["tex_template"] != "" else None
-
- if tex_fn is not None and not os.access(tex_fn, os.R_OK):
- # custom template not available, fallback to default
- logger.warning(
- f"Custom TeX template {tex_fn} not found or not readable. "
- "Falling back to the default template."
- )
- tex_fn = None
- config["tex_template_file"] = tex_fn
- config["tex_template"] = (
- TexTemplateFromFile(filename=tex_fn) if tex_fn is not None else TexTemplate()
- )
-
- ## Update file_writer_config
- fw_config = {}
-
- if config["use_js_renderer"]:
- fw_config["disable_caching"] = True
-
- if not hasattr(args, "subcommands"):
- fw_config["input_file"] = args.file if args.file else ""
- fw_config["scene_names"] = (
- args.scene_names if args.scene_names is not None else []
- )
- fw_config["output_file"] = args.output_file if args.output_file else ""
-
- # Note ConfigParser options are all strings and each needs to be converted
- # to the appropriate type.
- for boolean_opt in [
- "preview",
- "show_in_file_browser",
- "leave_progress_bars",
- "write_to_movie",
- "save_last_frame",
- "save_pngs",
- "save_as_gif",
- "write_all",
- "disable_caching",
- "flush_cache",
- "log_to_file",
- ]:
- attr = getattr(args, boolean_opt)
- fw_config[boolean_opt] = (
- default.getboolean(boolean_opt) if attr is None else attr
- )
- # for str_opt in ['media_dir', 'video_dir', 'tex_dir', 'text_dir']:
- for str_opt in ["media_dir"]:
- attr = getattr(args, str_opt)
- fw_config[str_opt] = os.path.relpath(default[str_opt]) if attr is None else attr
- attr = getattr(args, "log_dir")
- fw_config["log_dir"] = (
- os.path.join(fw_config["media_dir"], default["log_dir"])
- if attr is None
- else attr
- )
- dir_names = {
- "video_dir": "videos",
- "images_dir": "images",
- "tex_dir": "Tex",
- "text_dir": "texts",
- }
- for name in dir_names:
- fw_config[name] = os.path.join(fw_config["media_dir"], dir_names[name])
-
- # the --custom_folders flag overrides the default folder structure with the
- # custom folders defined in the [custom_folders] section of the config file
- fw_config["custom_folders"] = args.custom_folders
- if fw_config["custom_folders"]:
- fw_config["media_dir"] = parser["custom_folders"].get("media_dir")
- for opt in ["video_dir", "images_dir", "tex_dir", "text_dir"]:
- fw_config[opt] = parser["custom_folders"].get(opt)
-
- # Handle the -s (--save_last_frame) flag: invalidate the -w flag
- # At this point the save_last_frame option has already been set by
- # both CLI and the cfg file, so read the config dict directly
- if fw_config["save_last_frame"]:
- fw_config["write_to_movie"] = False
-
- # Handle the -t (--transparent) flag. This flag determines which
- # section to use from the .cfg file.
- section = parser["transparent"] if args.transparent else default
- for opt in ["png_mode", "movie_file_extension", "background_opacity"]:
- fw_config[opt] = section[opt]
-
- # Handle the -n flag. Read first from the cfg and then override with CLI.
- # These two are integers -- use getint()
- for opt in ["from_animation_number", "upto_animation_number"]:
- fw_config[opt] = default.getint(opt)
- if fw_config["upto_animation_number"] == -1:
- fw_config["upto_animation_number"] = float("inf")
- nflag = args.from_animation_number
- if nflag is not None:
- if "," in nflag:
- start, end = nflag.split(",")
- fw_config["from_animation_number"] = int(start)
- fw_config["upto_animation_number"] = int(end)
- else:
- fw_config["from_animation_number"] = int(nflag)
-
- # Handle the --dry_run flag. This flag determines which section
- # to use from the .cfg file. All options involved are boolean.
- # Note this overrides the flags -w, -s, -a, -g, and -i.
- if args.dry_run:
- for opt in [
- "write_to_movie",
- "save_last_frame",
- "save_pngs",
- "save_as_gif",
- "write_all",
- ]:
- fw_config[opt] = parser["dry_run"].getboolean(opt)
- if not fw_config["write_to_movie"]:
- fw_config["disable_caching"] = True
- # Read in the streaming section -- all values are strings
- fw_config["streaming"] = {
- opt: parser["streaming"][opt]
- for opt in [
- "live_stream_name",
- "twitch_stream_key",
- "streaming_protocol",
- "streaming_ip",
- "streaming_protocol",
- "streaming_client",
- "streaming_port",
- "streaming_port",
- "streaming_console_banner",
- ]
- }
-
- # For internal use (no CLI flag)
- fw_config["skip_animations"] = fw_config["save_last_frame"]
- fw_config["max_files_cached"] = default.getint("max_files_cached")
- if fw_config["max_files_cached"] == -1:
- fw_config["max_files_cached"] = float("inf")
- # Parse the verbosity flag to read in the log level
- verbosity = getattr(args, "verbosity")
- verbosity = default["verbosity"] if verbosity is None else verbosity
- fw_config["verbosity"] = verbosity
- logger.setLevel(verbosity)
-
- # Parse the ffmpeg log level in the config
- ffmpeg_loglevel = parser["ffmpeg"].get("loglevel", None)
- fw_config["ffmpeg_loglevel"] = (
- constants.FFMPEG_VERBOSITY_MAP[verbosity]
- if ffmpeg_loglevel is None
- else ffmpeg_loglevel
- )
-
- # Parse the progress_bar flag
- progress_bar = getattr(args, "progress_bar")
- if progress_bar is None:
- progress_bar = default.getboolean("progress_bar")
- fw_config["progress_bar"] = progress_bar
-
- global file_writer_config
- file_writer_config.update(fw_config)
-
-
-def _determine_quality(args):
- old_qualities = {
- "k": "fourk_quality",
- "e": "high_quality",
- "m": "medium_quality",
- "l": "low_quality",
- }
-
- for quality in constants.QUALITIES:
- if quality == constants.DEFAULT_QUALITY:
- # Skip so we prioritize anything that overwrites the default quality.
- pass
- elif getattr(args, quality, None) or (
- hasattr(args, "quality") and args.quality == constants.QUALITIES[quality]
- ):
- return quality
-
- for quality in old_qualities:
- if getattr(args, quality, None):
- logger.warning(
- f"Option -{quality} is deprecated please use the --quality/-q flag."
- )
- return old_qualities[quality]
-
- return constants.DEFAULT_QUALITY
-
-
-def set_file_logger():
- # Note: The log file name will be
- # <name_of_animation_file>_<name_of_scene>.log, gotten from
- # file_writer_config. So it can differ from the real name of the scene.
- # <name_of_scene> would only appear if scene name was provided when manim
- # was called.
- scene_name_suffix = "".join(file_writer_config["scene_names"])
- scene_file_name = os.path.basename(file_writer_config["input_file"]).split(".")[0]
- log_file_name = (
- f"{scene_file_name}_{scene_name_suffix}.log"
- if scene_name_suffix
- else f"{scene_file_name}.log"
- )
- log_file_path = os.path.join(file_writer_config["log_dir"], log_file_name)
-
- file_handler = logging.FileHandler(log_file_path, mode="w")
- file_handler.setFormatter(JSONFormatter())
-
- logger.addHandler(file_handler)
- logger.info("Log file will be saved in %(logpath)s", {"logpath": log_file_path})