Adjust typings for sounds.py and tex_file_writing.py

This commit is contained in:
YishiMichael
2022-04-16 14:37:28 +08:00
parent 654da85cf6
commit 0406ef70bb
2 changed files with 12 additions and 8 deletions

View File

@ -1,8 +1,10 @@
from __future__ import annotations
from manimlib.utils.directories import get_sound_dir
from manimlib.utils.file_ops import find_file
def get_full_sound_file_path(sound_file_name) -> str:
def get_full_sound_file_path(sound_file_name: str) -> str:
return find_file(
sound_file_name,
directories=[get_sound_dir()],

View File

@ -1,3 +1,5 @@
from __future__ import annotations
from contextlib import contextmanager
import hashlib
import os
@ -12,7 +14,7 @@ from manimlib.utils.directories import get_tex_dir
SAVED_TEX_CONFIG = {}
def get_tex_config():
def get_tex_config() -> dict[str, str]:
"""
Returns a dict which should look something like this:
{
@ -37,13 +39,13 @@ def get_tex_config():
return SAVED_TEX_CONFIG
def tex_hash(tex_file_content):
def tex_hash(tex_file_content: str) -> int:
# Truncating at 16 bytes for cleanliness
hasher = hashlib.sha256(tex_file_content.encode())
return hasher.hexdigest()[:16]
def tex_to_svg_file(tex_file_content):
def tex_to_svg_file(tex_file_content: str) -> str:
svg_file = os.path.join(
get_tex_dir(), tex_hash(tex_file_content) + ".svg"
)
@ -53,7 +55,7 @@ def tex_to_svg_file(tex_file_content):
return svg_file
def tex_to_svg(tex_file_content, svg_file):
def tex_to_svg(tex_file_content: str, svg_file: str) -> str:
tex_file = svg_file.replace(".svg", ".tex")
with open(tex_file, "w", encoding="utf-8") as outfile:
outfile.write(tex_file_content)
@ -69,7 +71,7 @@ def tex_to_svg(tex_file_content, svg_file):
return svg_file
def tex_to_dvi(tex_file):
def tex_to_dvi(tex_file: str) -> str:
tex_config = get_tex_config()
program = tex_config["executable"]
file_type = tex_config["intermediate_filetype"]
@ -96,7 +98,7 @@ def tex_to_dvi(tex_file):
return result
def dvi_to_svg(dvi_file, regen_if_exists=False):
def dvi_to_svg(dvi_file: str) -> str:
"""
Converts a dvi, which potentially has multiple slides, into a
directory full of enumerated pngs corresponding with these slides.
@ -123,7 +125,7 @@ def dvi_to_svg(dvi_file, regen_if_exists=False):
# TODO, perhaps this should live elsewhere
@contextmanager
def display_during_execution(message):
def display_during_execution(message: str) -> None:
# Only show top line
to_print = message.split("\n")[0]
max_characters = os.get_terminal_size().columns - 1