Skip to content

Conversation

@Viicos
Copy link
Member

@Viicos Viicos commented Nov 26, 2023

Fixes #3466.

What technically changed:

  • Use pydantic to create a new ManimConfig class, providing built-in type hints, validation. This eliminates the need to define properties for each parameter.
  • Remove the need to have a default.cfg file where defaults were stored. Instead, default values are set on the ManimConfig class directly (making it easier to keep in sync).
  • Fortunately, most of the existing config options were standard types (meaning supported out of the box by Pydantic). ManimColor was the only exception, so a custom annotation was created (see docs for more details; TLDR the ManimColor class in untouched and not tied to Pydantic in any way, the custom annotation simply provides info about how to validate/parse input, and how JSON schema should be generated).

What functionally changed:

  • Decouple the config model from file parsing. To do so, an abstract ConfigProvider class was added, exposing a get_config method. Each subclass of ConfigProvider is responsible for parsing a specific config format (for now, only CfgProvider is implemented and provides an instance of ManimConfig parsed from .cfg files).
  • In the future, users will be able to use other file formats such as TOML (the new standard in Python). Unlike cfg, TOML is well-specified and easier to parse because of the built-in types it supports. Thanks to the use of Pydantic, a JSON schema can be generated and used in IDEs to provide autocomplete when writing configuration files.
  • The structure of the ManimConfig class has slightly changed. Mainly:
Before After
ffmeg_loglevel ffmpeg.loglevel
ffmpeg_executable ffmpeg.executable
verbosity logging.verbosity
media_embed jupyter.media_embed
media_width jupyter.media_width

properties with deprecation warnings where added to avoid any breaking changes.

  • the CLI_CTX section is now made available in the config, through the cli_formatting attribute. cloup context settings are made accessible through the cli_formatting.context_settings property.

TODO

  • Implement tex_template / tex_template_file
  • Implement custom_folders. Needs investigation, confusing? Still required?
  • Set default values to input_file / output_file (only set through the CLI)
  • Implement get_dir
  • Implement ManimFrame
  • Parse CLI args (that is re-implement digest_args)
  • Implement support for tex_template/tex_template_file: Might need some refactor to the related tex classes.
  • Choose a serialization format for ManimColor
  • Docstrings
  • Extensive testing
  • Rename CLI switch to CLI flag in docstrings?

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@MrDiver
Copy link
Collaborator

MrDiver commented Nov 27, 2023

Looking forward to this change!

@Viicos Viicos force-pushed the 3466-refactor-config branch from 9ae9936 to 8e26d05 Compare December 11, 2023 17:12
@Viicos Viicos mentioned this pull request Dec 11, 2023
@JasonGrace2282 JasonGrace2282 added the refactor Refactor or redesign of existing code label Dec 12, 2023
@Viicos Viicos force-pushed the 3466-refactor-config branch from 764a864 to 2305816 Compare May 8, 2024 16:03
@JasonGrace2282
Copy link
Member

Heyo, are there any updates as to how the progress here is going? I'm interested in helping out here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactor or redesign of existing code

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

Refactor _config module to use pydantic

3 participants