Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Merge branch 'master' into logging-with-rich

XorUnisone447b3448117
diff --cc manim/__init__.py
index ea30833b6,505db0fb4..2bf914703
--- a/manim/__init__.py
+++ b/manim/__init__.py
@@@ -3,9 -4,8 +4,8 @@@ from . import confi
from . import constants
-def main():
+def main():
args = config.parse_cli()
cfg = config.get_configuration(args)
- constants.initialize_directories(cfg)
- from . import extract_scene
+ config.initialize_directories(cfg)
extract_scene.main(cfg)
diff --cc manim/config.py
index 972d70f66,01dce9102..b511fe342
--- a/manim/config.py
+++ b/manim/config.py
@@@ -5,10 -5,8 +5,9 @@@ import sy
import types
from . import constants
+ from . import dirs
+from .logger import logger
-
-
def parse_cli():
try:
parser = argparse.ArgumentParser()
@@@ -133,9 -132,13 +133,13 @@@
"--tex_dir",
help="directory to write tex",
)
+ parser.add_argument(
+ "--text_dir",
+ help="directory to write text",
+ )
return parser.parse_args()
except argparse.ArgumentError as err:
- print(str(err))
+ logger.error(str(err))
sys.exit(2)
diff --cc manim/constants.py
index 0a4f19d20,23769bbdb..c1b2e8687
--- a/manim/constants.py
+++ b/manim/constants.py
@@@ -1,61 -1,11 +1,11 @@@
import numpy as np
import os
+from .logger import logger
- MEDIA_DIR = ""
- VIDEO_DIR = ""
- VIDEO_OUTPUT_DIR = ""
- TEX_DIR = ""
- TEXT_DIR = ""
-
- def initialize_directories(config):
- global MEDIA_DIR
- global VIDEO_DIR
- global VIDEO_OUTPUT_DIR
- global TEX_DIR
- global TEXT_DIR
-
- video_path_specified = config["video_dir"] or config["video_output_dir"]
-
- if not (video_path_specified and config["tex_dir"]):
- if config["media_dir"]:
- MEDIA_DIR = config["media_dir"]
- else:
- MEDIA_DIR = os.path.join(
- os.path.expanduser('~'),
- "Dropbox (3Blue1Brown)/3Blue1Brown Team Folder"
- )
- if not os.path.isdir(MEDIA_DIR):
- MEDIA_DIR = "./media"
- logger.info(
- f"Media will be written to {MEDIA_DIR + os.sep}. You can change "
- "this behavior with the --media_dir flag."
- )
- else:
- if config["media_dir"]:
- logger.warning(
- "Ignoring --media_dir, since both --tex_dir and a video "
- "directory were both passed"
- )
-
- TEX_DIR = config["tex_dir"] or os.path.join(MEDIA_DIR, "Tex")
- TEXT_DIR = os.path.join(MEDIA_DIR, "texts")
- if not video_path_specified:
- VIDEO_DIR = os.path.join(MEDIA_DIR, "videos")
- VIDEO_OUTPUT_DIR = os.path.join(MEDIA_DIR, "videos")
- elif config["video_output_dir"]:
- VIDEO_OUTPUT_DIR = config["video_output_dir"]
- else:
- VIDEO_DIR = config["video_dir"]
-
- for folder in [VIDEO_DIR, VIDEO_OUTPUT_DIR, TEX_DIR, TEXT_DIR]:
- if folder != "" and not os.path.exists(folder):
- os.makedirs(folder)
-
NOT_SETTING_FONT_MSG='''
-Warning:
-You haven't set a font.
-If you are not using English, this may cause text rendering problems.
-You set fonts like:
+You haven't set font.
+If you are not using English, this may cause text rendering problem.
+You set font like:
text = Text('your text', font='your font')
or:
class MyText(Text):
diff --cc manim/mobject/svg/text_mobject.py
index 1e56ae49d,64da1c4dc..f229a95ba
--- a/manim/mobject/svg/text_mobject.py
+++ b/manim/mobject/svg/text_mobject.py
@@@ -3,9 -3,10 +3,11 @@@ import o
import copy
import hashlib
import cairo
+
from ...constants import *
+ from ... import dirs
from ...container.container import Container
+from ...logger import logger
from ...mobject.geometry import Dot, Rectangle
from ...mobject.svg.svg_mobject import SVGMobject
from ...mobject.types.vectorized_mobject import VGroup
@@@ -288,9 -289,9 +290,9 @@@ class Text(SVGMobject)
if self.font == '':
if NOT_SETTING_FONT_MSG != '':
- print(NOT_SETTING_FONT_MSG)
+ logger.warning(NOT_SETTING_FONT_MSG)
- dir_name = TEXT_DIR
+ dir_name = dirs.TEXT_DIR
hash_name = self.text2hash()
file_name = os.path.join(dir_name, hash_name)+'.svg'
if os.path.exists(file_name):
diff --cc manim/scene/scene_file_writer.py
index 9cbc61cb5,5467ed59e..820e25ea8
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@@ -12,9 -12,7 +12,8 @@@ from ..constants import FFMPEG_BI
from ..constants import STREAMING_IP
from ..constants import STREAMING_PORT
from ..constants import STREAMING_PROTOCOL
- from ..constants import VIDEO_DIR
- from ..constants import VIDEO_OUTPUT_DIR
+ from .. import dirs
+from ..logger import logger
from ..utils.config_ops import digest_config
from ..utils.file_ops import guarantee_existence
from ..utils.file_ops import add_extension_if_not_present
diff --cc manim/utils/tex_file_writing.py
index d781f1797,78cf60ba3..e3951187d
--- a/manim/utils/tex_file_writing.py
+++ b/manim/utils/tex_file_writing.py
@@@ -5,10 -5,8 +5,9 @@@ from pathlib import Pat
from ..constants import TEX_TEXT_TO_REPLACE
from ..constants import TEX_USE_CTEX
- from ..constants import TEX_DIR
+ from .. import dirs
+from ..logger import logger
-
def tex_hash(expression, template_tex_file_body):
id_str = str(expression + template_tex_file_body)
hasher = hashlib.sha256()