Refactoring the config system
See original GitHub issueYep, the config system strikes again. I’ll try to keep it short this time. The main point is that, while the current config system works fairly well, it’s quickly become a mess and difficult to maintain. For example, here are just two problems with it:
- The exported dictionaries
config
andcamera_config
are ambiguous – #283 - You can’t set the config when running from a file (for example when testing or making documentation) – see #293
file_writer_config
,cameraconfig_
,config
are confusing, and sometimes read/parse the same cfg files twice – see #443
The plan
My plan for refactoring is the following, modified from this comment:
I want to refactor the config system so that the order of events would be the following:
- A script executes
import manim
, which in turn executesmanim/__init__.py
. This can be a user scene script or our ownmanim/__main__.py
. - In
__init__.py
, the first line of code isimport config
which executesconfig/__init__.py
. config/__init__.py
first executesconfig/config.py
.- In
config.py
, as much as possible of the config dict should be defined. In particular, all config files must be read and parsed. Also,config.py
also parses the sections of the configuration corresponding to the logger, and exports them as well. All ofconfig
,camera_config
, andfile_writer_config
are defined and exported. NOTE the logger is NOT set here. - Back in
config/__init__.py
, the next line it runs executesconfig/logger.py
. config/logger.py
takes the config options exported fromconfig/config.py
and uses them to set the logger. NOTE this eliminates the need to execute_run_config
twice.- Back in
config/__init__.py
, everything exported byconfig/config.py
andconfig/logger.py
is exported up to the top-level package. After this, the config subpackage should never really have to be used again (other than for importing config/logger).config/__init__.py
now returns execution to the top-level__init__.py
. - Back in
__init__.py
, here comes the split.
- If the original script is a user script, then we are done and execution is returned to the user. They can then go about defining their
Scene
classes and ultimately rendering them. - If the original script was
__main__
because manim has been called from the command line,__init__.py
returns execution to__main__.main()
. Now, this function must deal with parsing command line flags and then updating the globalconfig
dict. This can easily be done by implementing e.g.manim.config.parse_cli(args)
. Note this will remove the problem we’ve had in the past whereconfig.py
had to determine whether it had been called from the command line (i.e. the hacky_from_command_line
function). Once the CLI flags have been parsed and the config updated,__main__.main()
simply decides what to execute next, depending on the subcommand used. Thus, a big chunk ofcfg_subcommands
will be ported into__main__.py
.
Associated PRs
This is a fairly major overhaul so I’ll try to keep the PRs short and self-contained so that they are easy to review.
-
#340(merged): add thetempconfig
context manager for testing all of the upcoming changes. Also makeCamera
read the config at instance construction, not at class definition. -
#376(merged): creates a new subpackage for all the stuff related to the config system. -
#397(merged): makes all modules use theconfig
dict as little as possible during library initialization. -
#543(merged): refactors the config subpackage so that onlyconfig/__init__.py
defines and exports global variables, whereas all other files just contain utilities. -
#620(merged): replaces the global config with a custom classManimConfig
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
Ok I see now. Then tempconfig is not what you want. What you want is to call
config.update(some_dict)
at the beginning of the pytest session. I’m currently working on this.make sure to specify their types as well, then sure