66The functions below can be called via the `manim cfg` subcommand.
77
88"""
9+
910import os
10- import configparser
1111from ast import literal_eval
1212
13- from .config_utils import _run_config , _paths_config_file , finalized_configs_dict
14- from ..utils .file_ops import guarantee_existence , open_file
15-
16- from rich .console import Console
17- from rich .style import Style
18- from rich .errors import StyleSyntaxError
13+ from manim import logger , console , config
14+ from manim .config .utils import config_file_paths , make_config_parser
15+ from manim .utils .file_ops import guarantee_existence , open_file
1916
2017__all__ = ["write" , "show" , "export" ]
2118
22- RICH_COLOUR_INSTRUCTIONS = """[red]The default colour is used by the input statement.
19+ RICH_COLOUR_INSTRUCTIONS = """
20+ [red]The default colour is used by the input statement.
2321If left empty, the default colour will be used.[/red]
24- [magenta] For a full list of styles, visit[/magenta] [green]https://rich.readthedocs.io/en/latest/style.html[/green]"""
22+ [magenta] For a full list of styles, visit[/magenta] [green]https://rich.readthedocs.io/en/latest/style.html[/green]
23+ """
2524RICH_NON_STYLE_ENTRIES = ["log.width" , "log.height" , "log.timestamps" ]
26- console = Console ()
2725
2826
2927def value_from_string (value ):
@@ -114,8 +112,7 @@ def replace_keys(default):
114112
115113
116114def write (level = None , openfile = False ):
117- config = _run_config ()[1 ]
118- config_paths = _paths_config_file () + [os .path .abspath ("manim.cfg" )]
115+ config_paths = config_file_paths ()
119116 console .print (
120117 "[yellow bold]Manim Configuration File Writer[/yellow bold]" , justify = "center"
121118 )
@@ -127,11 +124,12 @@ def write(level=None, openfile=False):
127124 CWD_CONFIG_MSG = f"""A configuration file at [yellow]{ config_paths [2 ]} [/yellow] has been created.
128125To save your config please save that file and place it in your current working directory, from where you run the manim command."""
129126
127+ parser = make_config_parser ()
130128 if not openfile :
131129 action = "save this as"
132- for category in config :
130+ for category in parser :
133131 console .print (f"{ category } " , style = "bold green underline" )
134- default = config [category ]
132+ default = parser [category ]
135133 if category == "logger" :
136134 console .print (RICH_COLOUR_INSTRUCTIONS )
137135 default = replace_keys (default )
@@ -178,7 +176,7 @@ def write(level=None, openfile=False):
178176
179177 default = replace_keys (default ) if category == "logger" else default
180178
181- config [category ] = dict (default )
179+ parser [category ] = dict (default )
182180
183181 else :
184182 action = "open"
@@ -194,40 +192,37 @@ def write(level=None, openfile=False):
194192 action_to_userpath = ""
195193
196194 if action_to_userpath .lower () == "y" or level == "user" :
197- cfg_file_path = os .path .join (
198- guarantee_existence (os .path .dirname (config_paths [1 ])), "manim.cfg"
199- )
195+ cfg_file_path = config_paths [1 ]
196+ guarantee_existence (config_paths [1 ].parents [0 ])
200197 console .print (USER_CONFIG_MSG )
201198 else :
202- cfg_file_path = os .path .join (
203- guarantee_existence (os .path .dirname (config_paths [2 ])), "manim.cfg"
204- )
199+ cfg_file_path = config_paths [2 ]
200+ guarantee_existence (config_paths [2 ].parents [0 ])
205201 console .print (CWD_CONFIG_MSG )
206202 with open (cfg_file_path , "w" ) as fp :
207- config .write (fp )
203+ parser .write (fp )
208204 if openfile :
209205 open_file (cfg_file_path )
210206
211207
212208def show ():
213- current_config = finalized_configs_dict ()
209+ parser = make_config_parser ()
214210 rich_non_style_entries = [a .replace ("." , "_" ) for a in RICH_NON_STYLE_ENTRIES ]
215- for category in current_config :
211+ for category in parser :
216212 console .print (f"{ category } " , style = "bold green underline" )
217- for entry in current_config [category ]:
213+ for entry in parser [category ]:
218214 if category == "logger" and entry not in rich_non_style_entries :
219215 console .print (f"{ entry } :" , end = "" )
220216 console .print (
221- f" { current_config [category ][entry ]} " ,
222- style = current_config [category ][entry ],
217+ f" { parser [category ][entry ]} " ,
218+ style = parser [category ][entry ],
223219 )
224220 else :
225- console .print (f"{ entry } : { current_config [category ][entry ]} " )
221+ console .print (f"{ entry } : { parser [category ][entry ]} " )
226222 console .print ("\n " )
227223
228224
229225def export (path ):
230- config = _run_config ()[1 ]
231226 if os .path .abspath (path ) == os .path .abspath (os .getcwd ()):
232227 console .print (
233228 """You are reading the config from the same directory you are exporting to.
0 commit comments