mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Add type hints to _config (#3440)
* Add type hints to `_config` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix call issues * Fix wrong value being used * Fix test * Fix wrong value being set * lint * Few type fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
94711f742d
commit
212bca09ca
7 changed files with 624 additions and 457 deletions
|
|
@ -3,7 +3,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from contextlib import _GeneratorContextManager, contextmanager
|
||||
from contextlib import contextmanager
|
||||
from typing import Any, Generator
|
||||
|
||||
from .cli_colors import parse_cli_ctx
|
||||
from .logger_utils import make_logger
|
||||
|
|
@ -40,7 +41,7 @@ frame = ManimFrame(config)
|
|||
|
||||
# This has to go here because it needs access to this module's config
|
||||
@contextmanager
|
||||
def tempconfig(temp: ManimConfig | dict) -> _GeneratorContextManager:
|
||||
def tempconfig(temp: ManimConfig | dict[str, Any]) -> Generator[None, None, None]:
|
||||
"""Context manager that temporarily modifies the global ``config`` object.
|
||||
|
||||
Inside the ``with`` statement, the modified config will be used. After
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import configparser
|
||||
|
||||
from cloup import Context, HelpFormatter, HelpTheme, Style
|
||||
|
||||
|
||||
def parse_cli_ctx(parser: configparser.ConfigParser) -> Context:
|
||||
formatter_settings = {
|
||||
def parse_cli_ctx(parser: configparser.SectionProxy) -> Context:
|
||||
formatter_settings: dict[str, str | int] = {
|
||||
"indent_increment": int(parser["indent_increment"]),
|
||||
"width": int(parser["width"]),
|
||||
"col1_max_width": int(parser["col1_max_width"]),
|
||||
|
|
@ -30,16 +32,16 @@ def parse_cli_ctx(parser: configparser.ConfigParser) -> Context:
|
|||
formatter = {}
|
||||
theme = parser["theme"] if parser["theme"] else None
|
||||
if theme is None:
|
||||
formatter = HelpFormatter().settings(
|
||||
theme=HelpTheme(**theme_settings), **formatter_settings
|
||||
formatter = HelpFormatter.settings(
|
||||
theme=HelpTheme(**theme_settings), **formatter_settings # type: ignore[arg-type]
|
||||
)
|
||||
elif theme.lower() == "dark":
|
||||
formatter = HelpFormatter().settings(
|
||||
theme=HelpTheme.dark().with_(**theme_settings), **formatter_settings
|
||||
formatter = HelpFormatter.settings(
|
||||
theme=HelpTheme.dark().with_(**theme_settings), **formatter_settings # type: ignore[arg-type]
|
||||
)
|
||||
elif theme.lower() == "light":
|
||||
formatter = HelpFormatter().settings(
|
||||
theme=HelpTheme.light().with_(**theme_settings), **formatter_settings
|
||||
formatter = HelpFormatter.settings(
|
||||
theme=HelpTheme.light().with_(**theme_settings), **formatter_settings # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
return Context.settings(
|
||||
|
|
|
|||
|
|
@ -225,5 +225,5 @@ loglevel = ERROR
|
|||
ffmpeg_executable = ffmpeg
|
||||
|
||||
[jupyter]
|
||||
media_embed =
|
||||
media_embed = False
|
||||
media_width = 60%%
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import configparser
|
|||
import copy
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from rich import color, errors
|
||||
|
|
@ -50,9 +49,9 @@ Loading the default color configuration.[/logging.level.error]
|
|||
|
||||
|
||||
def make_logger(
|
||||
parser: configparser.ConfigParser,
|
||||
parser: configparser.SectionProxy,
|
||||
verbosity: str,
|
||||
) -> tuple[logging.Logger, Console]:
|
||||
) -> tuple[logging.Logger, Console, Console]:
|
||||
"""Make the manim logger and console.
|
||||
|
||||
Parameters
|
||||
|
|
@ -84,14 +83,13 @@ def make_logger(
|
|||
theme = parse_theme(parser)
|
||||
console = Console(theme=theme)
|
||||
|
||||
# With rich 9.5.0+ we could pass stderr=True instead
|
||||
error_console = Console(theme=theme, file=sys.stderr)
|
||||
error_console = Console(theme=theme, stderr=True)
|
||||
|
||||
# set the rich handler
|
||||
RichHandler.KEYWORDS = HIGHLIGHTED_KEYWORDS
|
||||
rich_handler = RichHandler(
|
||||
console=console,
|
||||
show_time=parser.getboolean("log_timestamps"),
|
||||
keywords=HIGHLIGHTED_KEYWORDS,
|
||||
)
|
||||
|
||||
# finally, the logger
|
||||
|
|
@ -102,7 +100,7 @@ def make_logger(
|
|||
return logger, console, error_console
|
||||
|
||||
|
||||
def parse_theme(parser: configparser.ConfigParser) -> Theme:
|
||||
def parse_theme(parser: configparser.SectionProxy) -> Theme:
|
||||
"""Configure the rich style of logger and console output.
|
||||
|
||||
Parameters
|
||||
|
|
@ -178,7 +176,7 @@ class JSONFormatter(logging.Formatter):
|
|||
|
||||
"""
|
||||
|
||||
def format(self, record: dict) -> str:
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
"""Format the record in a custom JSON format."""
|
||||
record_c = copy.deepcopy(record)
|
||||
if record_c.args:
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
1
mypy.ini
1
mypy.ini
|
|
@ -50,6 +50,7 @@ warn_return_any = True
|
|||
|
||||
[mypy-manim._config.*]
|
||||
ignore_errors = True
|
||||
disable_error_code = return-value
|
||||
|
||||
[mypy-manim.animation.*]
|
||||
ignore_errors = True
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ scipy = [
|
|||
]
|
||||
tqdm = "^4.62.3"
|
||||
pydub = "^0.25.1"
|
||||
rich = ">=6.0,!=12.0.0"
|
||||
rich = ">=12.0.0"
|
||||
pycairo = "^1.21"
|
||||
manimpango = ">=0.5.0,<1.0.0"
|
||||
networkx = ">=2.5,<3.3"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue