A community-maintained Python framework for creating mathematical animations.
run black
leotrs334e2c4ccef3
diff --git a/manim/camera/camera.py b/manim/camera/camera.pyindex d5c265464..69d1e28c5 100644--- a/manim/camera/camera.py+++ b/manim/camera/camera.py@@ -89,6 +89,7 @@ class Camera(object):"frame_height","frame_width","frame_rate",+ "background_color",]:setattr(self, attr, kwargs.get(attr, config[attr]))diff --git a/manim/config/logger.py b/manim/config/logger.pyindex bc8a154c3..9b1d91291 100644--- a/manim/config/logger.py+++ b/manim/config/logger.py@@ -105,7 +105,7 @@ def set_file_logger(config, verbosity):file_handler = logging.FileHandler(log_file_path, mode="w")file_handler.setFormatter(JSONFormatter())- logger = logging.getLogger('manim')+ logger = logging.getLogger("manim")logger.addHandler(file_handler)logger.info("Log file will be saved in %(logpath)s", {"logpath": log_file_path})logger.setLevel(verbosity)diff --git a/manim/config/utils.py b/manim/config/utils.pyindex b0b338815..d383c8593 100644--- a/manim/config/utils.py+++ b/manim/config/utils.py@@ -80,7 +80,7 @@ def determine_quality(args):for quality in old_qualities:if getattr(args, quality, None):- logging.getLogger('manim').warning(+ logging.getLogger("manim").warning(f"Option -{quality} is deprecated please use the --quality/-q flag.")return old_qualities[quality]@@ -89,59 +89,59 @@ def determine_quality(args):_QUAL = {- 'low_quality': {'pixel_height': 480, 'pixel_width': 854, 'frame_rate': 15},- 'medium_quality': {'pixel_height': 720, 'pixel_width': 1280, 'frame_rate': 30},- 'high_quality': {'pixel_height': 1080, 'pixel_width': 1920, 'frame_rate': 60},- 'production_quality': {'pixel_height': 1440, 'pixel_width': 2560, 'frame_rate': 60},- '4k_quality': {'pixel_height': 2160, 'pixel_width': 3840, 'frame_rate': 60},+ "low_quality": {"pixel_height": 480, "pixel_width": 854, "frame_rate": 15},+ "medium_quality": {"pixel_height": 720, "pixel_width": 1280, "frame_rate": 30},+ "high_quality": {"pixel_height": 1080, "pixel_width": 1920, "frame_rate": 60},+ "production_quality": {"pixel_height": 1440, "pixel_width": 2560, "frame_rate": 60},+ "4k_quality": {"pixel_height": 2160, "pixel_width": 3840, "frame_rate": 60},}class ManimConfig(MutableMapping):_OPTS = {- 'background_color',- 'background_opacity',- 'custom_folders',- 'disable_caching',- 'ffmpeg_loglevel',- 'flush_cache',- 'frame_height',- 'frame_rate',- 'frame_width',- 'frame_x_radius',- 'frame_y_radius',- 'from_animation_number',- 'images_dir',- 'input_file',- 'js_renderer_path',- 'leave_progress_bars',- 'log_dir',- 'log_to_file',- 'max_files_cached',- 'media_dir',- 'movie_file_extension',- 'pixel_height',- 'pixel_width',- 'png_mode',- 'preview',- 'progress_bar',- 'save_as_gif',- 'save_last_frame',- 'save_pngs',- 'scene_names',- 'show_in_file_browser',- 'skip_animations',- 'sound',- 'tex_dir',- 'tex_template_file',- 'text_dir',- 'upto_animation_number',- 'use_js_renderer',- 'verbosity',- 'video_dir',- 'write_all',- 'write_to_movie',+ "background_color",+ "background_opacity",+ "custom_folders",+ "disable_caching",+ "ffmpeg_loglevel",+ "flush_cache",+ "frame_height",+ "frame_rate",+ "frame_width",+ "frame_x_radius",+ "frame_y_radius",+ "from_animation_number",+ "images_dir",+ "input_file",+ "js_renderer_path",+ "leave_progress_bars",+ "log_dir",+ "log_to_file",+ "max_files_cached",+ "media_dir",+ "movie_file_extension",+ "pixel_height",+ "pixel_width",+ "png_mode",+ "preview",+ "progress_bar",+ "save_as_gif",+ "save_last_frame",+ "save_pngs",+ "scene_names",+ "show_in_file_browser",+ "skip_animations",+ "sound",+ "tex_dir",+ "tex_template_file",+ "text_dir",+ "upto_animation_number",+ "use_js_renderer",+ "verbosity",+ "video_dir",+ "write_all",+ "write_to_movie",}def __init__(self, parser):@@ -167,7 +167,7 @@ class ManimConfig(MutableMapping):return getattr(self, key)def __setitem__(self, key, val):- getattr(ManimConfig, key).fset(self, val) # fset is the property's setter+ getattr(ManimConfig, key).fset(self, val) # fset is the property's setter# don't allow to delete anythingdef __delitem__(self, key):@@ -181,13 +181,13 @@ class ManimConfig(MutableMapping):if val in values:self._d[key] = valelse:- raise ValueError(f'attempted to set {key} to {val}; must be in {values}')+ raise ValueError(f"attempted to set {key} to {val}; must be in {values}")def _set_boolean(self, key, val):if val in [True, False]:self._d[key] = valelse:- raise ValueError(f'{key} must be boolean')+ raise ValueError(f"{key} must be boolean")def _set_str(self, key, val):if isinstance(val, str):@@ -195,77 +195,79 @@ class ManimConfig(MutableMapping):elif not val:self._d[key] = ""else:- raise ValueError(f'{key} must be str or falsy value')+ raise ValueError(f"{key} must be str or falsy value")def _set_between(self, key, val, lo, hi):if lo <= val <= hi:self._d[key] = valelse:- raise ValueError(f'{key} must be {lo} <= {key} <= {hi}')+ raise ValueError(f"{key} must be {lo} <= {key} <= {hi}")def _set_pos_number(self, key, val, allow_inf):if isinstance(val, int) and val > -1:self._d[key] = val- elif allow_inf and (val == -1 or val == float('inf')):- self._d[key] = float('inf')+ elif allow_inf and (val == -1 or val == float("inf")):+ self._d[key] = float("inf")else:- raise ValueError(f'{key} must be a non-negative integer (use -1 for infinity)')+ raise ValueError(+ f"{key} must be a non-negative integer (use -1 for infinity)"+ )# buildersdef digest_parser(self, parser):# boolean keysfor key in [- 'write_to_movie',- 'save_last_frame',- 'write_all',- 'save_pngs',- 'save_as_gif',- 'preview',- 'show_in_file_browser',- 'progress_bar',- 'sound',- 'leave_progress_bars',- 'log_to_file',- 'disable_caching',- 'flush_cache',- 'custom_folders',- 'skip_animations',- 'use_js_renderer',+ "write_to_movie",+ "save_last_frame",+ "write_all",+ "save_pngs",+ "save_as_gif",+ "preview",+ "show_in_file_browser",+ "progress_bar",+ "sound",+ "leave_progress_bars",+ "log_to_file",+ "disable_caching",+ "flush_cache",+ "custom_folders",+ "skip_animations",+ "use_js_renderer",]:- setattr(self, key, parser['CLI'].getboolean(key, fallback=False))+ setattr(self, key, parser["CLI"].getboolean(key, fallback=False))# int keysfor key in [- 'from_animation_number',- 'upto_animation_number',- 'frame_rate',- 'max_files_cached',- 'pixel_height',- 'pixel_width',+ "from_animation_number",+ "upto_animation_number",+ "frame_rate",+ "max_files_cached",+ "pixel_height",+ "pixel_width",]:- setattr(self, key, parser['CLI'].getint(key))+ setattr(self, key, parser["CLI"].getint(key))# str keysfor key in [- 'verbosity',- 'media_dir',- 'log_dir',- 'video_dir',- 'images_dir',- 'text_dir',- 'tex_dir',- 'input_file',- 'output_file',- 'png_mode',- 'movie_file_extension',- 'background_color',- 'js_renderer_path',+ "verbosity",+ "media_dir",+ "log_dir",+ "video_dir",+ "images_dir",+ "text_dir",+ "tex_dir",+ "input_file",+ "output_file",+ "png_mode",+ "movie_file_extension",+ "background_color",+ "js_renderer_path",]:- setattr(self, key, parser['CLI'].get(key, fallback='', raw=True))+ setattr(self, key, parser["CLI"].get(key, fallback="", raw=True))# float keys- for key in ['background_opacity']:- setattr(self, key, parser['CLI'].getfloat(key))+ for key in ["background_opacity"]:+ setattr(self, key, parser["CLI"].getfloat(key))# other logicself["frame_height"] = 8.0@@ -273,39 +275,37 @@ class ManimConfig(MutableMapping):self["frame_height"] * self["pixel_width"] / self["pixel_height"])- val = parser['CLI'].get('tex_template_file')+ val = parser["CLI"].get("tex_template_file")if val:- setattr(self, 'tex_template_file', val)+ setattr(self, "tex_template_file", val)- val = parser['ffmpeg'].get('loglevel')+ val = parser["ffmpeg"].get("loglevel")if val:- setattr(self, 'ffmpeg_loglevel', val)+ setattr(self, "ffmpeg_loglevel", val)return selfdef digest_args(self, args):self.input_file = args.file- self.scene_names = (- args.scene_names if args.scene_names is not None else []- )+ self.scene_names = args.scene_names if args.scene_names is not None else []self.output_file = args.output_filefor key in [- "preview",- "show_in_file_browser",- "sound",- "leave_progress_bars",- "write_to_movie",- "save_last_frame",- "save_pngs",- "save_as_gif",- "write_all",- "disable_caching",- "flush_cache",- "transparent",- "scene_names",- "verbosity",- "background_color",+ "preview",+ "show_in_file_browser",+ "sound",+ "leave_progress_bars",+ "write_to_movie",+ "save_last_frame",+ "save_pngs",+ "save_as_gif",+ "write_all",+ "disable_caching",+ "flush_cache",+ "transparent",+ "scene_names",+ "verbosity",+ "background_color",]:if hasattr(args, key):attr = getattr(args, key)@@ -315,19 +315,19 @@ class ManimConfig(MutableMapping):self[key] = attr# dry_run is special because it can only be set to True- if hasattr(args, 'dry_run'):- if getattr(args, 'dry_run'):- self['dry_run'] = True+ if hasattr(args, "dry_run"):+ if getattr(args, "dry_run"):+ self["dry_run"] = Truefor key in [- "media_dir", # always set this one first- "video_dir",- "images_dir",- "tex_dir",- "text_dir",- "log_dir",- "custom_folders",- "log_to_file", # always set this one last+ "media_dir", # always set this one first+ "video_dir",+ "images_dir",+ "tex_dir",+ "text_dir",+ "log_dir",+ "custom_folders",+ "log_to_file", # always set this one last]:if hasattr(args, key):attr = getattr(args, key)@@ -361,18 +361,14 @@ class ManimConfig(MutableMapping):self.pixel_width = int(w)self.pixel_height = int(h)except ValueError:- raise ValueError(f'invalid argument {rflag} for -r flag (must have a comma ",")')+ raise ValueError(+ f'invalid argument {rflag} for -r flag (must have a comma ",")'+ )# Handle --custom_foldersif args.custom_folders:- for opt in [- 'media_dir',- 'video_dir',- 'text_dir',- 'tex_dir',- 'log_dir'- ]:- self[opt] = self._parser['custom_folders'].get(opt, raw=True)+ for opt in ["media_dir", "video_dir", "text_dir", "tex_dir", "log_dir"]:+ self[opt] = self._parser["custom_folders"].get(opt, raw=True)return self@@ -388,251 +384,257 @@ class ManimConfig(MutableMapping):# config options are propertiespreview = property(- lambda self: self._d['preview'],- lambda self, val: self._set_boolean('preview', val),- doc='Whether to play the movie once it is done rendering'+ lambda self: self._d["preview"],+ lambda self, val: self._set_boolean("preview", val),+ doc="Whether to play the movie once it is done rendering",)show_in_file_browser = property(- lambda self: self._d['show_in_file_browser'],- lambda self, val: self._set_boolean('show_in_file_browser', val),- doc='Whether to show the rendered file in the file browser'+ lambda self: self._d["show_in_file_browser"],+ lambda self, val: self._set_boolean("show_in_file_browser", val),+ doc="Whether to show the rendered file in the file browser",)progress_bar = property(- lambda self: self._d['progress_bar'],- lambda self, val: self._set_boolean('progress_bar', val),- doc='Whether to show progress bars while rendering animations'+ lambda self: self._d["progress_bar"],+ lambda self, val: self._set_boolean("progress_bar", val),+ doc="Whether to show progress bars while rendering animations",)leave_progress_bars = property(- lambda self: self._d['leave_progress_bars'],- lambda self, val: self._set_boolean('leave_progress_bars', val),- doc='Whether to leave the progress bar for each animations'+ lambda self: self._d["leave_progress_bars"],+ lambda self, val: self._set_boolean("leave_progress_bars", val),+ doc="Whether to leave the progress bar for each animations",)@propertydef log_to_file(self):"""Whether to save logs to a file"""- return self._d['log_to_file']+ return self._d["log_to_file"]@log_to_file.setter- def log_to_file(self, val):- self._set_boolean('log_to_file', val)+ def log_to_file(self, val):+ self._set_boolean("log_to_file", val)if val:- if not os.path.exists(self['log_dir']):- os.makedirs(self['log_dir'])- set_file_logger(self, self['verbosity'])+ if not os.path.exists(self["log_dir"]):+ os.makedirs(self["log_dir"])+ set_file_logger(self, self["verbosity"])sound = property(- lambda self: self._d['sound'],- lambda self, val: self._set_boolean('sound', val),- doc='Whether to play a sound to notify when a scene is rendered'+ lambda self: self._d["sound"],+ lambda self, val: self._set_boolean("sound", val),+ doc="Whether to play a sound to notify when a scene is rendered",)write_to_movie = property(- lambda self: self._d['write_to_movie'],- lambda self, val: self._set_boolean('write_to_movie', val),- doc='Whether to render the scene to a movie file'+ lambda self: self._d["write_to_movie"],+ lambda self, val: self._set_boolean("write_to_movie", val),+ doc="Whether to render the scene to a movie file",)save_last_frame = property(- lambda self: self._d['save_last_frame'],- lambda self, val: self._set_boolean('save_last_frame', val),- doc='Whether to save the last frame of the scene as an image file'+ lambda self: self._d["save_last_frame"],+ lambda self, val: self._set_boolean("save_last_frame", val),+ doc="Whether to save the last frame of the scene as an image file",)write_all = property(- lambda self: self._d['write_all'],- lambda self, val: self._set_boolean('write_all', val),- doc='Whether to render all scenes in the input file'+ lambda self: self._d["write_all"],+ lambda self, val: self._set_boolean("write_all", val),+ doc="Whether to render all scenes in the input file",)save_pngs = property(- lambda self: self._d['save_pngs'],- lambda self, val: self._set_boolean('save_pngs', val),- doc='Whether to save all frames in the scene as images files'+ lambda self: self._d["save_pngs"],+ lambda self, val: self._set_boolean("save_pngs", val),+ doc="Whether to save all frames in the scene as images files",)save_as_gif = property(- lambda self: self._d['save_as_gif'],- lambda self, val: self._set_boolean('save_as_gif', val),- doc='Whether to save the rendered scene in .gif format.'+ lambda self: self._d["save_as_gif"],+ lambda self, val: self._set_boolean("save_as_gif", val),+ doc="Whether to save the rendered scene in .gif format.",)@propertydef verbosity(self):- return self._d['verbosity']+ return self._d["verbosity"]@verbosity.setterdef verbosity(self, val):"""Verbosity level of the logger."""self._set_from_list(- 'verbosity',+ "verbosity",val,- ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],+ ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],)- logging.getLogger('manim').setLevel(val)+ logging.getLogger("manim").setLevel(val)ffmpeg_loglevel = property(- lambda self: self._d['ffmpeg_loglevel'],+ lambda self: self._d["ffmpeg_loglevel"],lambda self, val: self._set_from_list(- 'ffmpeg_loglevel', val, ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']+ "ffmpeg_loglevel", val, ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),- doc='Verbosity level of ffmpeg.'+ doc="Verbosity level of ffmpeg.",)pixel_width = property(- lambda self: self._d['pixel_width'],- lambda self, val: self._set_pos_number('pixel_width', val, False),- doc='Frame width in pixels'+ lambda self: self._d["pixel_width"],+ lambda self, val: self._set_pos_number("pixel_width", val, False),+ doc="Frame width in pixels",)pixel_height = property(- lambda self: self._d['pixel_height'],- lambda self, val: self._set_pos_number('pixel_height', val, False),- doc='Frame height in pixels'+ lambda self: self._d["pixel_height"],+ lambda self, val: self._set_pos_number("pixel_height", val, False),+ doc="Frame height in pixels",)aspect_ratio = property(- lambda self: self._d['pixel_width'] / self._d['pixel_height'],- doc='Aspect ratio (width / height) in pixels'+ lambda self: self._d["pixel_width"] / self._d["pixel_height"],+ doc="Aspect ratio (width / height) in pixels",)frame_height = property(- lambda self: self._d['frame_height'],- lambda self, val: self._d.__setitem__('frame_height', val),- doc='Frame height in logical units'+ lambda self: self._d["frame_height"],+ lambda self, val: self._d.__setitem__("frame_height", val),+ doc="Frame height in logical units",)frame_width = property(- lambda self: self._d['frame_width'],- lambda self, val: self._d.__setitem__('frame_width', val),- doc='Frame width in logical units'+ lambda self: self._d["frame_width"],+ lambda self, val: self._d.__setitem__("frame_width", val),+ doc="Frame width in logical units",)frame_y_radius = property(- lambda self: self._d['frame_height'] / 2,+ lambda self: self._d["frame_height"] / 2,lambda self, val: (- self._d.__setitem__('frame_y_radius', val)- or self._d.__setitem__('frame_height', 2*val)+ self._d.__setitem__("frame_y_radius", val)+ or self._d.__setitem__("frame_height", 2 * val)),- doc='Half the frame height'+ doc="Half the frame height",)frame_x_radius = property(- lambda self: self._d['frame_width'] / 2,+ lambda self: self._d["frame_width"] / 2,lambda self, val: (- self._d.__setitem__('frame_x_radius', val)- or self._d.__setitem__('frame_width', 2*val)+ self._d.__setitem__("frame_x_radius", val)+ or self._d.__setitem__("frame_width", 2 * val)),- doc='Half the frame width'+ doc="Half the frame width",)top = property(lambda self: self.frame_y_radius * constants.UP,- doc='One unit step in the positive vertical direction'+ doc="One unit step in the positive vertical direction",)bottom = property(lambda self: self.frame_y_radius * constants.DOWN,- doc='One unit step in the negative vertical direction'+ doc="One unit step in the negative vertical direction",)left_side = property(lambda self: self.frame_x_radius * constants.LEFT,- doc='One unit step in the negative horizontal direction'+ doc="One unit step in the negative horizontal direction",)right_side = property(lambda self: self.frame_x_radius * constants.RIGHT,- doc='One unit step in the positive horizontal direction'+ doc="One unit step in the positive horizontal direction",)frame_rate = property(- lambda self: self._d['frame_rate'],- lambda self, val: self._d.__setitem__('frame_rate', val),- doc='Frame rate in fps (rames per second)'+ lambda self: self._d["frame_rate"],+ lambda self, val: self._d.__setitem__("frame_rate", val),+ doc="Frame rate in fps (rames per second)",)background_color = property(- lambda self: self._d['background_color'],+ lambda self: self._d["background_color"],lambda self, val: self._d.__setitem__("background_color", colour.Color(val)),- doc="Background color of the scene."+ doc="Background color of the scene.",)from_animation_number = property(- lambda self: self._d['from_animation_number'],- lambda self, val: self._d.__setitem__('from_animation_number', val),- doc='Set to a number greater than 1 to skip animations.'+ lambda self: self._d["from_animation_number"],+ lambda self, val: self._d.__setitem__("from_animation_number", val),+ doc="Set to a number greater than 1 to skip animations.",)upto_animation_number = property(- lambda self: self._d['upto_animation_number'],- lambda self, val: self._set_pos_number('upto_animation_number', val, True),- doc=('Set to less than the number of animations to skip '- 'animations. Use -1 to avoid skipping.')+ lambda self: self._d["upto_animation_number"],+ lambda self, val: self._set_pos_number("upto_animation_number", val, True),+ doc=(+ "Set to less than the number of animations to skip "+ "animations. Use -1 to avoid skipping."+ ),)skip_animations = property(- lambda self: self._d['skip_animations'],- lambda self, val: self._set_boolean('skip_animations', val),- doc=('Set to less than the number of animations to skip '- 'animations. Use -1 to avoid skipping.')+ lambda self: self._d["skip_animations"],+ lambda self, val: self._set_boolean("skip_animations", val),+ doc=(+ "Set to less than the number of animations to skip "+ "animations. Use -1 to avoid skipping."+ ),)max_files_cached = property(- lambda self: self._d['max_files_cached'],- lambda self, val: self._set_pos_number('max_files_cached', val, True),- doc='Maximum number of files cached. Use -1 for infinity.'+ lambda self: self._d["max_files_cached"],+ lambda self, val: self._set_pos_number("max_files_cached", val, True),+ doc="Maximum number of files cached. Use -1 for infinity.",)flush_cache = property(- lambda self: self._d['flush_cache'],- lambda self, val: self._set_boolean('flush_cache', val),- doc='whether to delete all the cached partial movie files.'+ lambda self: self._d["flush_cache"],+ lambda self, val: self._set_boolean("flush_cache", val),+ doc="whether to delete all the cached partial movie files.",)disable_caching = property(- lambda self: self._d['disable_caching'],- lambda self, val: self._set_boolean('disable_caching', val),- doc='whether to use scene caching.'+ lambda self: self._d["disable_caching"],+ lambda self, val: self._set_boolean("disable_caching", val),+ doc="whether to use scene caching.",)png_mode = property(- lambda self: self._d['png_mode'],- lambda self, val: self._set_from_list('png_mode', val, ['RGB', 'RGBA']),- doc='Either RGA (no transparency) or RGBA (with transparency).'+ lambda self: self._d["png_mode"],+ lambda self, val: self._set_from_list("png_mode", val, ["RGB", "RGBA"]),+ doc="Either RGA (no transparency) or RGBA (with transparency).",)movie_file_extension = property(- lambda self: self._d['movie_file_extension'],- lambda self, val: self._set_from_list('movie_file_extension', val, ['.mp4', '.mov']),- doc='Either .mp4 or .mov.'+ lambda self: self._d["movie_file_extension"],+ lambda self, val: self._set_from_list(+ "movie_file_extension", val, [".mp4", ".mov"]+ ),+ doc="Either .mp4 or .mov.",)background_opacity = property(- lambda self: self._d['background_opacity'],- lambda self, val: self._set_between('background_opacity', val, 0, 1),- doc='A number between 0.0 (fully transparent) and 1.0 (fully opaque).'+ lambda self: self._d["background_opacity"],+ lambda self, val: self._set_between("background_opacity", val, 0, 1),+ doc="A number between 0.0 (fully transparent) and 1.0 (fully opaque).",)frame_size = property(- lambda self: (self._d['pixel_width'], self._d['pixel_height']),+ lambda self: (self._d["pixel_width"], self._d["pixel_height"]),lambda self, tup: (- self._d.__setitem__('pixel_width', tup[0])- or self._d.__setitem__('pixel_height', tup[1])+ self._d.__setitem__("pixel_width", tup[0])+ or self._d.__setitem__("pixel_height", tup[1])),- doc=''+ doc="",)@propertydef quality(self):"""Video quality."""q = {- 'pixel_width': self.pixel_width,- 'pixel_height': self.pixel_height,- 'frame_rate': self.frame_rate,+ "pixel_width": self.pixel_width,+ "pixel_height": self.pixel_height,+ "frame_rate": self.frame_rate,}for qual in _QUAL:if q == _QUAL[qual]:@@ -643,24 +645,24 @@ class ManimConfig(MutableMapping):@quality.setterdef quality(self, qual):if qual not in _QUAL:- raise KeyError(f'quality must be one of {list(_QUAL.keys())}')- self.frame_size = _QUAL[qual]['pixel_width'], _QUAL[qual]['pixel_height']- self.frame_rate = _QUAL[qual]['frame_rate']+ raise KeyError(f"quality must be one of {list(_QUAL.keys())}")+ self.frame_size = _QUAL[qual]["pixel_width"], _QUAL[qual]["pixel_height"]+ self.frame_rate = _QUAL[qual]["frame_rate"]@propertydef transparent(self):"""Whether the background opacity is 0.0."""- return self._d['background_opacity'] == 0.0+ return self._d["background_opacity"] == 0.0@transparent.setterdef transparent(self, val):if val:- self.png_mode = 'RGBA'- self.movie_file_extension = '.mov'+ self.png_mode = "RGBA"+ self.movie_file_extension = ".mov"self.background_opacity = 0.0else:- self.png_mode = 'RGB'- self.movie_file_extension = '.mp4'+ self.png_mode = "RGB"+ self.movie_file_extension = ".mp4"self.background_opacity = 1.0@property@@ -683,105 +685,107 @@ class ManimConfig(MutableMapping):self.save_pngs = Falseself.save_as_gif = Falseelse:- raise ValueError('It is unclear what it means to set dry_run to '- 'False. Instead, try setting each option '- 'individually. (write_to_movie, write_alll, '- 'save_last_frame, save_pngs, or save_as_gif)')+ raise ValueError(+ "It is unclear what it means to set dry_run to "+ "False. Instead, try setting each option "+ "individually. (write_to_movie, write_alll, "+ "save_last_frame, save_pngs, or save_as_gif)"+ )@propertydef use_js_renderer(self):- self._d['use_js_renderer']+ self._d["use_js_renderer"]@use_js_renderer.setterdef use_js_renderer(self, val):- self._d['use_js_renderer'] = val+ self._d["use_js_renderer"] = valif val:self["disable_caching"] = Truejs_renderer_path = property(- lambda self: self._d['js_renderer_path'],- lambda self, val: self._d.__setitem__('js_renderer_path', Path(val)),- doc='Path to JS renderer.'+ lambda self: self._d["js_renderer_path"],+ lambda self, val: self._d.__setitem__("js_renderer_path", Path(val)),+ doc="Path to JS renderer.",)media_dir = property(- lambda self: self._d['media_dir'],- lambda self, val: self._d.__setitem__('media_dir', Path(val)),- doc='Main output directory, relative to execution directory.'+ lambda self: self._d["media_dir"],+ lambda self, val: self._d.__setitem__("media_dir", Path(val)),+ doc="Main output directory, relative to execution directory.",)def _get_dir(self, key):dirs = [- 'media_dir',- 'video_dir',- 'images_dir',- 'text_dir',- 'tex_dir',- 'log_dir',- 'input_file',- 'output_file',+ "media_dir",+ "video_dir",+ "images_dir",+ "text_dir",+ "tex_dir",+ "log_dir",+ "input_file",+ "output_file",]dirs.remove(key)dirs = {k: self._d[k] for k in dirs}return self._d[key].format(**dirs)log_dir = property(- lambda self: self._get_dir('log_dir'),- lambda self, val: self._d.__setitem__('log_dir', val),- doc='Directory to place logs'+ lambda self: self._get_dir("log_dir"),+ lambda self, val: self._d.__setitem__("log_dir", val),+ doc="Directory to place logs",)video_dir = property(- lambda self: self._get_dir('video_dir'),- lambda self, val: self._d.__setitem__('video_dir', val),- doc='Directory to place videos'+ lambda self: self._get_dir("video_dir"),+ lambda self, val: self._d.__setitem__("video_dir", val),+ doc="Directory to place videos",)images_dir = property(- lambda self: self._get_dir('images_dir'),- lambda self, val: self._d.__setitem__('images_dir', val),- doc='Directory to place images'+ lambda self: self._get_dir("images_dir"),+ lambda self, val: self._d.__setitem__("images_dir", val),+ doc="Directory to place images",)text_dir = property(- lambda self: self._get_dir('text_dir'),- lambda self, val: self._d.__setitem__('text_dir', val),- doc='Directory to place text'+ lambda self: self._get_dir("text_dir"),+ lambda self, val: self._d.__setitem__("text_dir", val),+ doc="Directory to place text",)tex_dir = property(- lambda self: self._get_dir('tex_dir'),- lambda self, val: self._d.__setitem__('tex_dir', val),- doc='Directory to place tex'+ lambda self: self._get_dir("tex_dir"),+ lambda self, val: self._d.__setitem__("tex_dir", val),+ doc="Directory to place tex",)custom_folders = property(- lambda self: self._d['custom_folders'],- lambda self, val: self._set_boolean('custom_folders', val),- doc='Whether to use custom folders.'+ lambda self: self._d["custom_folders"],+ lambda self, val: self._set_boolean("custom_folders", val),+ doc="Whether to use custom folders.",)input_file = property(- lambda self: self._get_dir('input_file'),- lambda self, val: self._d.__setitem__('input_file', val),- doc='Input file name.'+ lambda self: self._get_dir("input_file"),+ lambda self, val: self._d.__setitem__("input_file", val),+ doc="Input file name.",)output_file = property(- lambda self: self._get_dir('output_file'),- lambda self, val: self._d.__setitem__('output_file', val),- doc='Output file name.'+ lambda self: self._get_dir("output_file"),+ lambda self, val: self._d.__setitem__("output_file", val),+ doc="Output file name.",)scene_names = property(- lambda self: self._d['scene_names'],- lambda self, val: self._d.__setitem__('scene_names', val),- doc='Scenes to play from file.'+ lambda self: self._d["scene_names"],+ lambda self, val: self._d.__setitem__("scene_names", val),+ doc="Scenes to play from file.",)@propertydef tex_template(self):- if not hasattr(self, '_tex_template') or not self._tex_template:+ if not hasattr(self, "_tex_template") or not self._tex_template:fn = self._d["tex_template_file"]if fn:self._tex_template = TexTemplateFromFile(filename=fn)@@ -796,50 +800,52 @@ class ManimConfig(MutableMapping):@propertydef tex_template_file(self):- return self._d['tex_template_file']+ return self._d["tex_template_file"]@tex_template_file.setterdef tex_template_file(self, val):if val:if not os.access(val, os.R_OK):- logging.getLogger("manim").warning(f"Custom TeX template {val} not found or not readable.")+ logging.getLogger("manim").warning(+ f"Custom TeX template {val} not found or not readable."+ )else:self._d["tex_template_file"] = Path(val)self._tex_template = TexTemplateFromFile(filename=val)else:- self._d["tex_template_file"] = val # actually set the falsy value- self._tex_template = TexTemplate() # but don't use it+ self._d["tex_template_file"] = val # actually set the falsy value+ self._tex_template = TexTemplate() # but don't use itclass ManimFrame(Mapping):_OPTS = {- 'pixel_width',- 'pixel_height',- 'aspect_ratio',- 'frame_height',- 'frame_width',- 'frame_y_radius',- 'frame_x_radius',- 'top',- 'bottom',- 'left_side',- 'right_side',+ "pixel_width",+ "pixel_height",+ "aspect_ratio",+ "frame_height",+ "frame_width",+ "frame_y_radius",+ "frame_x_radius",+ "top",+ "bottom",+ "left_side",+ "right_side",}_CONSTANTS = {- 'UP': np.array((0.0, 1.0, 0.0)),- 'DOWN': np.array((0.0, -1.0, 0.0)),- 'RIGHT': np.array((1.0, 0.0, 0.0)),- 'LEFT': np.array((-1.0, 0.0, 0.0)),- 'IN': np.array((0.0, 0.0, -1.0)),- 'OUT': np.array((0.0, 0.0, 1.0)),- 'ORIGIN': np.array((0.0, 0.0, 0.0)),- 'X_AXIS': np.array((1.0, 0.0, 0.0)),- 'Y_AXIS': np.array((0.0, 1.0, 0.0)),- 'Z_AXIS': np.array((0.0, 0.0, 1.0)),- 'UL': np.array((-1.0, 1.0, 0.0)),- 'UR': np.array((1.0, 1.0, 0.0)),- 'DL': np.array((-1.0, -1.0, 0.0)),- 'DR': np.array((1.0, -1.0, 0.0)),+ "UP": np.array((0.0, 1.0, 0.0)),+ "DOWN": np.array((0.0, -1.0, 0.0)),+ "RIGHT": np.array((1.0, 0.0, 0.0)),+ "LEFT": np.array((-1.0, 0.0, 0.0)),+ "IN": np.array((0.0, 0.0, -1.0)),+ "OUT": np.array((0.0, 0.0, 1.0)),+ "ORIGIN": np.array((0.0, 0.0, 0.0)),+ "X_AXIS": np.array((1.0, 0.0, 0.0)),+ "Y_AXIS": np.array((0.0, 1.0, 0.0)),+ "Z_AXIS": np.array((0.0, 0.0, 1.0)),+ "UL": np.array((-1.0, 1.0, 0.0)),+ "UR": np.array((1.0, 1.0, 0.0)),+ "DL": np.array((-1.0, -1.0, 0.0)),+ "DR": np.array((1.0, -1.0, 0.0)),}def __init__(self, c):@@ -847,7 +853,7 @@ class ManimFrame(Mapping):raise TypeError("argument must be instance of 'ManimConfig'")# need to use __dict__ directly because setting attributes is not# allowed (see __setattr__)- self.__dict__['_c'] = c+ self.__dict__["_c"] = c# there are required by parent class Mapping to behave like a dictdef __getitem__(self, key):@@ -876,8 +882,4 @@ class ManimFrame(Mapping):for opt in list(ManimFrame._OPTS) + list(ManimFrame._CONSTANTS):- setattr(- ManimFrame,- opt,- property(lambda self, o=opt: self[o])- )+ setattr(ManimFrame, opt, property(lambda self, o=opt: self[o]))diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.pyindex d9f3dc88b..b3dadbf75 100644--- a/manim/scene/scene_file_writer.py+++ b/manim/scene/scene_file_writer.py@@ -86,9 +86,7 @@ class SceneFileWriter(object):))else:- movie_dir = guarantee_existence(- os.path.join(config["video_dir"])- )+ movie_dir = guarantee_existence(os.path.join(config["video_dir"]))self.movie_file_path = os.path.join(movie_dir,@@ -125,7 +123,7 @@ class SceneFileWriter(object):hash_animation : strHash of the animation."""- if not hasattr(self, 'partial_movie_directory'):+ if not hasattr(self, "partial_movie_directory"):return# None has to be added to partial_movie_files to keep the right index with scene.num_plays.@@ -409,9 +407,7 @@ class SceneFileWriter(object):# TODO #486 Why does ffmpeg need temp files ?temp_file_path = (- os.path.splitext(file_path)[0]- + "_temp"- + config["movie_file_extension"]+ os.path.splitext(file_path)[0] + "_temp" + config["movie_file_extension"])self.partial_movie_file_path = file_pathself.temp_partial_movie_file_path = temp_file_path@@ -486,11 +482,11 @@ class SceneFileWriter(object)::class:`bool`Whether the file exists."""- if not hasattr(self, 'partial_movie_directory'):+ if not hasattr(self, "partial_movie_directory"):return Falsepath = os.path.join(self.partial_movie_directory,- "{}{}".format(hash_invocation, config['movie_file_extension']),+ "{}{}".format(hash_invocation, config["movie_file_extension"]),)return os.path.exists(path)@@ -541,10 +537,10 @@ class SceneFileWriter(object):config["ffmpeg_loglevel"].lower(),]- if config['write_to_movie'] and not config['save_as_gif']:+ if config["write_to_movie"] and not config["save_as_gif"]:commands += ["-c", "copy", movie_file_path]- if config['save_as_gif']:+ if config["save_as_gif"]:commands += [self.gif_file_path]if not self.includes_sound:@@ -553,7 +549,7 @@ class SceneFileWriter(object):try:subprocess.check_call(commands)except subprocess.CalledProcessError as exc:- logger.error(f'FFMPEG returned with code {exc.returncode}')+ logger.error(f"FFMPEG returned with code {exc.returncode}")raise excif self.includes_sound:@@ -596,7 +592,7 @@ class SceneFileWriter(object):os.remove(sound_file_path)self.print_file_ready_message(- self.gif_file_path if config['save_as_gif'] else movie_file_path+ self.gif_file_path if config["save_as_gif"] else movie_file_path)if config["write_to_movie"]:for file_path in partial_movie_files: