A community-maintained Python framework for creating mathematical animations.
Imporve cfgwriter.py and changed . to _ as asked 👌
Syrus Darkd5162f546edd
diff --git a/example_scenes/manim.cfg b/example_scenes/manim.cfgindex e195a629e..88abfee43 100644--- a/example_scenes/manim.cfg+++ b/example_scenes/manim.cfg@@ -1,14 +1,82 @@-[log.color]-# The colors here are parsed by rich.color , and are not related-# to the colours defined in constants.py's COLOR_MAP-logging.keyword = magenta-logging.level.notset = dim-logging.level.debug = yellow-logging.level.info = dim purple-logging.level.warning = dim red-logging.level.error = red-logging.level.critical = red-log.level =-log.time = dim yellow-log.message = green-log.path = dim blue+[CLI]+write_to_movie = True+save_last_frame = False+write_all = False+save_pngs = False+save_as_gif = False+preview = False+show_file_in_finder = False+quiet = False+sound = False+output_file =+leave_progress_bars = False+background_color = BLACK+background_opacity = 1+from_animation_number = 0+upto_animation_number = -1+media_dir = ./media+png_mode = RGB+movie_file_extension = .mp4+frame_rate = 60+pixel_height = 1440+pixel_width = 2560++[transparent]+png_mode = RGBA+movie_file_extension = .mov+background_opacity = 0++[fourk_quality]+pixel_height = 2160+pixel_width = 3840+frame_rate = 60++[high_quality]+pixel_height = 1080+pixel_width = 1920+frame_rate = 60++[medium_quality]+pixel_height = 720+pixel_width = 1280+frame_rate = 30++[low_quality]+pixel_height = 480+pixel_width = 854+frame_rate = 15++[dry_run]+write_to_movie = False+write_all = False+save_last_frame = False+save_pngs = False+save_as_gif = False++[streaming]+live_stream_name = LiveStream+twitch_stream_key = YOUR_STREAM_KEY+streaming_protocol = tcp+streaming_ip = 127.0.0.1+streaming_port = 2000+streaming_client = ffplay+streaming_url = %(STREAMING_PROTOCOL)s://%(STREAMING_IP)s:%(STREAMING_PORT)s?listen+streaming_console_banner = Manim is now running in streaming mode.+ Stream animations by passing them to manim.play(), e.g.+ >>> c = Circle()+ >>> manim.play(ShowCreation(c))++#This is some custom configuration just as an example+[logger]+logging_keyword = magenta+logging_level_notset = dim+logging_level_debug = yellow+logging_level_info = dim purple+logging_level_warning = dim red+logging_level_error = red+logging_level_critical = red+log_level =+log_time = dim yellow+log_message = green+log_path = dim blue+diff --git a/manim/config.py b/manim/config.pyindex 92294541d..c12df46ee 100644--- a/manim/config.py+++ b/manim/config.py@@ -10,7 +10,7 @@ import sysimport colourfrom . import constants-from .utils.config_utils import _run_config, _init_dirs+from .utils.config_utils import _run_config, _init_dirs, _from_command_linefrom .logger import loggerfrom .utils.tex import TexTemplate, TexTemplateFromFile@@ -90,8 +90,8 @@ def _parse_config(config_parser, args):args, config_parser, file_writer_config, successfully_read_files = _run_config()-logger.info(f"Read configuration files: {successfully_read_files}")+if _from_command_line():+ logger.info(f"Read configuration files: {successfully_read_files}")+ _init_dirs(file_writer_config)config = _parse_config(config_parser, args)camera_config = config--_init_dirs(file_writer_config)diff --git a/manim/default.cfg b/manim/default.cfgindex 1bf723025..9cf64ede1 100644--- a/manim/default.cfg+++ b/manim/default.cfg@@ -140,3 +140,16 @@ streaming_console_banner = Manim is now running in streaming mode.Stream animations by passing them to manim.play(), e.g.>>> c = Circle()>>> manim.play(ShowCreation(c))++[logger]+logging_keyword = bold yellow+logging_level_notset = dim+logging_level_debug = green+logging_level_info = blue+logging_level_warning = red+logging_level_error = red bold+logging_level_critical = red bold reverse+log_level =+log_time = cyan dim+log_message =+log_path = dimdiff --git a/manim/logger.py b/manim/logger.pyindex 959fc7f8c..8a4a4d122 100644--- a/manim/logger.py+++ b/manim/logger.py@@ -1,3 +1,10 @@+"""+logger.py+---------+This is the logging library for manim.+This library uses rich for coloured log outputs.++"""import configparserimport logging@@ -12,7 +19,13 @@ from .utils.config_utils import _run_configdef parse_theme(fp):config_parser.read(fp)- theme = dict(config_parser["log.color"])+ theme = dict(config_parser["logger"])+ # replaces `_` by `.` as rich understands it+ for key in theme:+ temp = theme[key]+ del theme[key]+ key = key.replace("_", ".")+ theme[key] = temptry:customTheme = Theme(theme)except (color.ColorParseError, errors.StyleSyntaxError):diff --git a/manim/utils/cfgwriter.py b/manim/utils/cfgwriter.pyindex fb38eea79..27735878f 100644--- a/manim/utils/cfgwriter.py+++ b/manim/utils/cfgwriter.py@@ -2,54 +2,44 @@cfgwriter.py-------------Inputs the configuration files while checking it is valid.+Inputs the configuration files while checking it is valid. Can be executed by `manim-cfg` command."""-from os import path+import osimport configparser-from .config_utils import successfully_read_files+from .config_utils import _run_config, _paths_config_filefrom rich.console import Consolefrom rich.progress import track-from rich.color import Color+from rich.style import Style+from rich.errors import StyleSyntaxError-def check_valid_colour(color):+def check_valid_style(style):"""Checks whether the entered color is a valid color according to richParameters----------- color : :class:`str`- The color to check whether it is valid.+ style : :class:`str`+ The style to check whether it is valid.Returns-------Boolean- Returns whether it is valid color or not.+ Returns whether it is valid style or not according to rich."""try:- Color.parse(color)+ Style.parse(style)return True- except:+ except StyleSyntaxError:return Falsedef main():+ successfully_read_files = _run_config()[-1]console = Console()config = configparser.ConfigParser()- config.read( successfully_read_files )- default = {- "logging.keyword": "bold yellow",- "logging.level.notset": "dim",- "logging.level.debug": "green",- "logging.level.info": "blue",- "logging.level.warning": "red",- "logging.level.error": "red bold",- "logging.level.critical": "red bold reverse",- "log.level": "",- "log.time": "cyan dim",- "log.message": "",- "log.path": "dim",- }+ config.read(successfully_read_files)+ default = config["logger"]console.print("[yellow bold]Manim Logger Configuration Editor[/yellow bold]", justify="center")@@ -59,11 +49,16 @@ def main():console.print("[magenta]Please follow the link for available styles.[/magenta][link=https://rich.readthedocs.io/en/latest/style.html]docs[/link]")+ for key in default:+ temp = default[key]+ del default[key]+ key = key.replace("_", ".")+ default[key] = tempfor key in default:console.print("Enter the Style for %s" % key + ":", style=key, end="")temp = input()if temp:- while not check_valid_colour(temp):+ while not check_valid_style(temp):console.print("[red bold]Your Style is not valid. Try again.[/red bold]")@@ -71,15 +66,41 @@ def main():temp = input()else:default[key] = temp- config["log.color"] = default- for n in track(range(100), description="Converting to Manim.cfg"):- with open("manim.cfg", "w") as fp:- config.write(fp)+ for key in default:+ temp = default[key]+ del default[key]+ key = key.replace(".", "_")+ default[key] = temp+ config["logger"] = defaultconsole.print(- """A configuration file called [yellow]manim.cfg[/yellow] has been created.-To save your theme please save that file and each time place it in your current working directory,-(the directory where you executed the command manim)"""+ "Do you want it as a default for the User?(y/n)[[n]]",+ style="dim purple",+ end="",)+ save_to_userpath = input()+ config_paths = _paths_config_file()+ if save_to_userpath.lower() == "y":+ if not os.path.exists(os.path.abspath(os.path.join(config_paths[1], ".."))):+ os.makedirs(os.path.abspath(os.path.join(config_paths[1], "..")))+ with open(config_paths[1], "w") as fp:+ config.write(fp)+ console.print(+ """A configuration file called [yellow]{}[/yellow] has been created with your required changes.+which would be used while running manim command. If you want to overide that+you would have to create a manim.cfg in local directory.""".format(+ config_paths[1]+ )+ )+ else:+ with open(config_paths[2], "w") as fp:+ config.write(fp)+ console.print(+ """A configuration file called [yellow]{}[/yellow] has been created.+To save your theme please save that file and each time place it in your current working directory,+(the directory where you executed the command manim)""".format(+ config_paths[2]+ )+ )if __name__ == "__main__":diff --git a/manim/utils/config_utils.py b/manim/utils/config_utils.pyindex 6204421f7..be0f9a6df 100644--- a/manim/utils/config_utils.py+++ b/manim/utils/config_utils.py@@ -16,7 +16,7 @@ import colourfrom .. import constantsfrom .tex import TexTemplate, TexTemplateFromFile-__all__ = ["_run_config"]+__all__ = ["_run_config", "_paths_config_file", "_from_command_line"]def _parse_file_writer_config(config_parser, args):@@ -345,15 +345,37 @@ def _from_command_line():return from_cli_command or from_python_m-def _run_config():- # Config files to be parsed, in ascending priority+def _paths_config_file():library_wide = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "default.cfg"))- config_files = [- library_wide,- os.path.expanduser("~/.manim.cfg"),- ]+ if sys.platform.startswith("linux"):+ # This is for linux users+ user_wide = os.path.expanduser(+ os.path.join("~", ".config", "Manim", "manim.cfg")+ )+ elif sys.platform.startswith("darwin"):+ # This is for MacOS users+ user_wide = os.path.expanduser(+ os.path.join("~", "Library", "Application Support", "Manim", "manim.cfg")+ )+ elif sys.platform.startswith("win32"):+ # This is for Windows users+ user_wide = os.path.expanduser(+ os.path.join("~", "AppData", "Roaming", "Manim", "manim.cfg")+ )+ else:+ # This is for users whose OS is unknown+ user_wide = os.path.expanduser(+ os.path.join("~", ".config", "Manim", "manim.cfg")+ )+ current_working_directory = os.path.abspath("manim.cfg")+ return [library_wide, user_wide, current_working_directory]+++def _run_config():+ # Config files to be parsed, in ascending priority+ config_files = _paths_config_file()if _from_command_line():args = _parse_cli(sys.argv[1:])if args.config_file is not None: