From f910aeded816bc36da35e801cf459b68884d2f91 Mon Sep 17 00:00:00 2001 From: Celeste Ma Date: Sun, 29 Sep 2024 16:25:55 -0400 Subject: [PATCH] Replaced os.system with subprocess.run. (#89) --- manim_voiceover/translate/gettext_utils.py | 10 +++++----- manim_voiceover/translate/render.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manim_voiceover/translate/gettext_utils.py b/manim_voiceover/translate/gettext_utils.py index c39a0de..00e9ac8 100644 --- a/manim_voiceover/translate/gettext_utils.py +++ b/manim_voiceover/translate/gettext_utils.py @@ -2,6 +2,8 @@ import os import typing as t +import subprocess + from manim import logger from manim_voiceover.helper import prompt_ask_missing_extras @@ -27,10 +29,10 @@ def init_gettext(files, domain, localedir): # Check if pot_path exists if os.path.exists(pot_path): # If it does, update it - os.system(f"xgettext -j -o {pot_path} {file}") + subprocess.run(["xgettext", "-j", "-o", pot_path, file]) else: # If it does not, create it - os.system(f"xgettext -o {pot_path} {file}") + subprocess.run(["xgettext", "-o", pot_path, file]) def init_language(target_lang, domain, localedir): @@ -52,9 +54,7 @@ def init_language(target_lang, domain, localedir): pass else: # If it does not, create it - os.system( - f"msginit --no-translator -i {localedir / f'{domain}.pot'} -o {po_path} -l {target_lang}" - ) + subprocess.run(["msginit", "--no-translator", "-i", localedir / f"{domain}.pot", "-o", po_path, "-l", target_lang]) return po_path diff --git a/manim_voiceover/translate/render.py b/manim_voiceover/translate/render.py index 32ab598..2bf97bb 100644 --- a/manim_voiceover/translate/render.py +++ b/manim_voiceover/translate/render.py @@ -3,6 +3,8 @@ import sys from pathlib import Path +import subprocess + # Get the current working directory as Path CWD = Path.cwd() @@ -108,15 +110,13 @@ def main(): # If the .mo file does not exist, create it if not os.path.exists(mo_path): print(f"Creating {domain}.mo for {locale}") - os.system(f"msgfmt {po_path} -o {mo_path}") + subprocess.run(["msgfmt", po_path, "-o", mo_path]) print(f"Rendering {scene} in {locale}...") # Set LOCALE environment variable to locale os.environ["LOCALE"] = locale ofile = scene + "_" + locale + ".mp4" cmd = [ - f"LOCALE={locale}", - f"DOMAIN={domain}", "manim", f"-q{quality}", file, @@ -128,7 +128,7 @@ def main(): # Run manim with the command try: - result = os.system(" ".join(cmd)) + result = subprocess.run(cmd, env={"LOCALE": locale, "DOMAIN": domain}).returncode except KeyboardInterrupt: print("KeyboardInterrupt") sys.exit(0)