From 0406ef70bbdd01bf686492ad8e1d86782871241d Mon Sep 17 00:00:00 2001 From: YishiMichael Date: Sat, 16 Apr 2022 14:37:28 +0800 Subject: [PATCH] Adjust typings for sounds.py and tex_file_writing.py --- manimlib/utils/sounds.py | 4 +++- manimlib/utils/tex_file_writing.py | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manimlib/utils/sounds.py b/manimlib/utils/sounds.py index dc37ff00..f34ba435 100644 --- a/manimlib/utils/sounds.py +++ b/manimlib/utils/sounds.py @@ -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()], diff --git a/manimlib/utils/tex_file_writing.py b/manimlib/utils/tex_file_writing.py index 5b57be64..3e4591a9 100644 --- a/manimlib/utils/tex_file_writing.py +++ b/manimlib/utils/tex_file_writing.py @@ -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