-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Yep, 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
configandcamera_configare ambiguous -- Usage of config vs camera_config and separating them. #283 - You can't set the config when running from a file (for example when testing or making documentation) -- see Manually selecting a manim.cfg when NOT running from ClI #293
file_writer_config,cameraconfig_,configare confusing, and sometimes read/parse the same cfg files twice -- see REFACTOR : _run_config() should not return file_writer_config. #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 configwhich executesconfig/__init__.py. config/__init__.pyfirst 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.pyalso parses the sections of the configuration corresponding to the logger, and exports them as well. All ofconfig,camera_config, andfile_writer_configare 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.pytakes the config options exported fromconfig/config.pyand uses them to set the logger. NOTE this eliminates the need to execute_run_configtwice.- Back in
config/__init__.py, everything exported byconfig/config.pyandconfig/logger.pyis 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__.pynow 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
Sceneclasses and ultimately rendering them. - If the original script was
__main__because manim has been called from the command line,__init__.pyreturns execution to__main__.main(). Now, this function must deal with parsing command line flags and then updating the globalconfigdict. 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.pyhad to determine whether it had been called from the command line (i.e. the hacky_from_command_linefunction). 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_subcommandswill 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.
-
Refactor config #340(merged): add thetempconfigcontext manager for testing all of the upcoming changes. Also makeCameraread the config at instance construction, not at class definition. -
Create config subpackage #376(merged): creates a new subpackage for all the stuff related to the config system. -
Stop using config at import #397(merged): makes all modules use theconfigdict as little as possible during library initialization. -
Refactor config subpkg #543(merged): refactors the config subpackage so that onlyconfig/__init__.pydefines and exports global variables, whereas all other files just contain utilities. -
Replace the global config dict with new class ManimConfig #620(merged): replaces the global config with a custom classManimConfig.