6
6
The functions below can be called via the `manim cfg` subcommand.
7
7
8
8
"""
9
+
9
10
import os
10
- import configparser
11
11
from ast import literal_eval
12
12
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
19
16
20
17
__all__ = ["write" , "show" , "export" ]
21
18
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.
23
21
If 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
+ """
25
24
RICH_NON_STYLE_ENTRIES = ["log.width" , "log.height" , "log.timestamps" ]
26
- console = Console ()
27
25
28
26
29
27
def value_from_string (value ):
@@ -114,8 +112,7 @@ def replace_keys(default):
114
112
115
113
116
114
def 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 ()
119
116
console .print (
120
117
"[yellow bold]Manim Configuration File Writer[/yellow bold]" , justify = "center"
121
118
)
@@ -127,11 +124,12 @@ def write(level=None, openfile=False):
127
124
CWD_CONFIG_MSG = f"""A configuration file at [yellow]{ config_paths [2 ]} [/yellow] has been created.
128
125
To save your config please save that file and place it in your current working directory, from where you run the manim command."""
129
126
127
+ parser = make_config_parser ()
130
128
if not openfile :
131
129
action = "save this as"
132
- for category in config :
130
+ for category in parser :
133
131
console .print (f"{ category } " , style = "bold green underline" )
134
- default = config [category ]
132
+ default = parser [category ]
135
133
if category == "logger" :
136
134
console .print (RICH_COLOUR_INSTRUCTIONS )
137
135
default = replace_keys (default )
@@ -178,7 +176,7 @@ def write(level=None, openfile=False):
178
176
179
177
default = replace_keys (default ) if category == "logger" else default
180
178
181
- config [category ] = dict (default )
179
+ parser [category ] = dict (default )
182
180
183
181
else :
184
182
action = "open"
@@ -194,40 +192,37 @@ def write(level=None, openfile=False):
194
192
action_to_userpath = ""
195
193
196
194
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 ])
200
197
console .print (USER_CONFIG_MSG )
201
198
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 ])
205
201
console .print (CWD_CONFIG_MSG )
206
202
with open (cfg_file_path , "w" ) as fp :
207
- config .write (fp )
203
+ parser .write (fp )
208
204
if openfile :
209
205
open_file (cfg_file_path )
210
206
211
207
212
208
def show ():
213
- current_config = finalized_configs_dict ()
209
+ parser = make_config_parser ()
214
210
rich_non_style_entries = [a .replace ("." , "_" ) for a in RICH_NON_STYLE_ENTRIES ]
215
- for category in current_config :
211
+ for category in parser :
216
212
console .print (f"{ category } " , style = "bold green underline" )
217
- for entry in current_config [category ]:
213
+ for entry in parser [category ]:
218
214
if category == "logger" and entry not in rich_non_style_entries :
219
215
console .print (f"{ entry } :" , end = "" )
220
216
console .print (
221
- f" { current_config [category ][entry ]} " ,
222
- style = current_config [category ][entry ],
217
+ f" { parser [category ][entry ]} " ,
218
+ style = parser [category ][entry ],
223
219
)
224
220
else :
225
- console .print (f"{ entry } : { current_config [category ][entry ]} " )
221
+ console .print (f"{ entry } : { parser [category ][entry ]} " )
226
222
console .print ("\n " )
227
223
228
224
229
225
def export (path ):
230
- config = _run_config ()[1 ]
231
226
if os .path .abspath (path ) == os .path .abspath (os .getcwd ()):
232
227
console .print (
233
228
"""You are reading the config from the same directory you are exporting to.
0 commit comments