Skip to content

Commit

Permalink
Type hinting ipython_magic.py (#2171)
Browse files Browse the repository at this point in the history
Co-authored-by: Darylgolden <[email protected]>
  • Loading branch information
Davidy22 and Darylgolden authored Oct 14, 2021
1 parent 470491e commit acd4d10
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions manim/utils/ipython_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import shutil
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List

from manim import Group, config, logger, tempconfig
from manim.__main__ import main
from manim.renderer.shader import shader_program_cache

try:
from IPython import get_ipython
from IPython.core.interactiveshell import InteractiveShell
from IPython.core.magic import (
Magics,
line_cell_magic,
Expand All @@ -25,13 +27,18 @@

@magics_class
class ManimMagic(Magics):
def __init__(self, shell):
def __init__(self, shell: InteractiveShell) -> None:
super().__init__(shell)
self.rendered_files = {}

@needs_local_scope
@line_cell_magic
def manim(self, line, cell=None, local_ns=None):
def manim(
self,
line: str,
cell: str = None,
local_ns: Dict[str, Any] = None,
) -> None:
r"""Render Manim scenes contained in IPython cells.
Works as a line or cell magic.
Expand Down Expand Up @@ -169,13 +176,13 @@ def construct(self):
),
)

def add_additional_args(self, args):
def add_additional_args(self, args: List[str]) -> List[str]:
additional_args = ["--jupyter"]
# Use webm to support transparency
if "-t" in args and "--format" not in args:
additional_args += ["--format", "webm"]
return additional_args + args[:-1] + [""] + [args[-1]]


def _generate_file_name():
def _generate_file_name() -> str:
return config["scene_names"][0] + "@" + datetime.now().strftime("%Y-%m-%d@%H-%M-%S")

0 comments on commit acd4d10

Please sign in to comment.