Skip to content

Replace the global config dict with new class ManimConfig #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1ba7873
split config/utils.py into config/logger.py and config/utils.py, in p…
leotrs Oct 13, 2020
6e0ba47
change every mention of file_writer_config to config. Also some tweak…
leotrs Oct 15, 2020
e33d3aa
refactor logger to play nicely with the new config system
leotrs Oct 15, 2020
8b1a8fc
move init_dirs
leotrs Oct 15, 2020
5d787f3
change a dumb logic for a smart logic
leotrs Oct 15, 2020
12a5055
delete old/unsed/moved stuff
leotrs Oct 15, 2020
91587d1
special handling of dry_run and delete unnecessary file
leotrs Oct 26, 2020
e69f3fe
delete repeated line and restore original skipping status correctly
leotrs Oct 26, 2020
151ac77
if there is no partial_movie_directory, then we cannot check if anyth…
leotrs Oct 26, 2020
694077c
add test for the -s flag
leotrs Oct 26, 2020
70649b7
use the new "quality" config option
leotrs Oct 26, 2020
1bd4272
why ignore skipping here?
leotrs Oct 26, 2020
e74289e
fix the -s flag when there are no animations
leotrs Oct 26, 2020
a78acba
this should have gone in with the previous commit
leotrs Oct 26, 2020
8d661ce
make the [custom_folders] use the same syntax as the [CLI] section
leotrs Oct 26, 2020
d5b8171
fix handling of background color flag
leotrs Oct 26, 2020
334e2c4
run black
leotrs Oct 26, 2020
0222423
add new test data
leotrs Oct 26, 2020
12e1e52
merge master
leotrs Oct 26, 2020
b15f5fd
fix docs
leotrs Oct 26, 2020
acccf3e
revert a change that caused disable_caching to break
leotrs Oct 26, 2020
d63ad7b
Merge branch 'master' into feat-manim-configdict
leotrs Oct 27, 2020
865d396
blackstreet bois
leotrs Oct 27, 2020
54d4295
remove unnecessary video_quality_config
leotrs Oct 27, 2020
276e0f1
Merge branch 'master' into feat-manim-configdict
leotrs Oct 28, 2020
e1f3a1c
add deepcopy method - this should fix the tests on py3.6
leotrs Oct 28, 2020
7a15349
I'll be black
leotrs Oct 28, 2020
11a020d
Fix -t flag and add a test to it. Also add test for -c flag.
leotrs Oct 28, 2020
6d08e4d
remove unnecessary _QUAL and move its contents to constants.QUALITIES
leotrs Oct 28, 2020
06e7613
clean up
leotrs Oct 28, 2020
4b544e1
blacktrack
leotrs Oct 28, 2020
4b4647d
black
leotrs Oct 28, 2020
73e9356
implement digest_file
leotrs Oct 28, 2020
45980e5
added new test and fixed a couple of things with deepcopy
leotrs Oct 28, 2020
58705ab
prefer Path to raw strings
leotrs Oct 28, 2020
d9b4428
Merge branch 'master' into feat-manim-configdict
leotrs Oct 28, 2020
04d2da4
fix a wrong merge
leotrs Oct 28, 2020
c9a6a83
use Path
leotrs Oct 28, 2020
4e28d1f
black
leotrs Oct 28, 2020
e89a96d
fix test on windows
leotrs Oct 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/source/manim_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,18 @@ def run(self):
video_dir = os.path.join(media_dir, "videos")
output_file = f"{clsname}-{classnamedict[clsname]}"

file_writer_config_code = [
config_code = [
f'config["frame_rate"] = {frame_rate}',
f'config["pixel_height"] = {pixel_height}',
f'config["pixel_width"] = {pixel_width}',
f'file_writer_config["media_dir"] = r"{media_dir}"',
f'file_writer_config["images_dir"] = r"{images_dir}"',
f'file_writer_config["tex_dir"] = r"{tex_dir}"',
f'file_writer_config["text_dir"] = r"{text_dir}"',
f'file_writer_config["video_dir"] = r"{video_dir}"',
f'file_writer_config["save_last_frame"] = {save_last_frame}',
f'file_writer_config["save_as_gif"] = {save_as_gif}',
f'file_writer_config["output_file"] = r"{output_file}"',
f'config["media_dir"] = r"{media_dir}"',
f'config["images_dir"] = r"{images_dir}"',
f'config["tex_dir"] = r"{tex_dir}"',
f'config["text_dir"] = r"{text_dir}"',
f'config["video_dir"] = r"{video_dir}"',
f'config["save_last_frame"] = {save_last_frame}',
f'config["save_as_gif"] = {save_as_gif}',
f'config["output_file"] = r"{output_file}"',
]

user_code = self.content
Expand All @@ -229,7 +229,7 @@ def run(self):

code = [
"from manim import *",
*file_writer_config_code,
*config_code,
*user_code,
f"{clsname}().render()",
]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ Other modules
.. autosummary::
:toctree: reference

_config
config
constants
container
34 changes: 14 additions & 20 deletions manim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import traceback

from manim import constants, logger, console, config, file_writer_config
from manim import constants, logger, console, config
from manim import Scene
from manim.utils.module_ops import (
get_module,
Expand All @@ -12,38 +12,35 @@
)
from manim.utils.file_ops import open_file as open_media_file
from manim.grpc.impl import frame_server_impl
from manim.config.utils import init_dirs
from manim.config.main_utils import *


def open_file_if_needed(file_writer):
if file_writer_config["verbosity"] != "DEBUG":
if config["verbosity"] != "DEBUG":
curr_stdout = sys.stdout
sys.stdout = open(os.devnull, "w")

open_file = any(
[file_writer_config["preview"], file_writer_config["show_in_file_browser"]]
)
open_file = any([config["preview"], config["show_in_file_browser"]])

if open_file:
current_os = platform.system()
file_paths = []

if file_writer_config["save_last_frame"]:
if config["save_last_frame"]:
file_paths.append(file_writer.get_image_file_path())
if (
file_writer_config["write_to_movie"]
and not file_writer_config["save_as_gif"]
):
if config["write_to_movie"] and not config["save_as_gif"]:
file_paths.append(file_writer.get_movie_file_path())
if file_writer_config["save_as_gif"]:
if config["save_as_gif"]:
file_paths.append(file_writer.gif_file_path)

for file_path in file_paths:
if file_writer_config["show_in_file_browser"]:
if config["show_in_file_browser"]:
open_media_file(file_path, True)
if file_writer_config["preview"]:
if config["preview"]:
open_media_file(file_path, False)

if file_writer_config["verbosity"] != "DEBUG":
if config["verbosity"] != "DEBUG":
sys.stdout.close()
sys.stdout = curr_stdout

Expand All @@ -69,13 +66,10 @@ def main():
# something_else_here()

else:
update_config_with_cli(args)
init_dirs(file_writer_config)

if file_writer_config["log_to_file"]:
set_file_logger()
config.digest_args(args)
init_dirs(config)

module = get_module(file_writer_config["input_file"])
module = get_module(config["input_file"])
all_scene_classes = get_scene_classes_from_module(module)
scene_classes_to_render = get_scenes_to_render(all_scene_classes)
for SceneClass in scene_classes_to_render:
Expand Down
10 changes: 4 additions & 6 deletions manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import cairo
import numpy as np

from .. import logger, config, camera_config
from .. import logger, config
from ..constants import *
from ..mobject.types.image_mobject import AbstractImageMobject
from ..mobject.mobject import Mobject
Expand Down Expand Up @@ -53,8 +53,6 @@ class Camera(object):
# Note: frame height and width will be resized to match
# the pixel aspect ratio
"frame_center": ORIGIN,
"background_color": BLACK,
"background_opacity": 1,
# Points in vectorized mobjects with norm greater
# than this value will be rescaled.
"image_mode": "RGBA",
Expand Down Expand Up @@ -91,6 +89,8 @@ def __init__(self, video_quality_config, background=None, **kwargs):
"frame_height",
"frame_width",
"frame_rate",
"background_color",
"background_opacity",
]:
setattr(self, attr, kwargs.get(attr, config[attr]))

Expand Down Expand Up @@ -1039,9 +1039,7 @@ def adjusted_thickness(self, thickness):

"""
# TODO: This seems...unsystematic
big_sum = op.add(
camera_config["default_pixel_height"], camera_config["default_pixel_width"]
)
big_sum = op.add(config["default_pixel_height"], config["default_pixel_width"])
this_sum = op.add(self.pixel_height, self.pixel_width)
factor = fdiv(big_sum, this_sum)
return 1 + (thickness - 1) / factor
Expand Down
11 changes: 5 additions & 6 deletions manim/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from contextlib import contextmanager

from .utils import make_config_parser, make_logger, make_config, make_file_writer_config
from .logger import make_logger
from .utils import make_config_parser, ManimConfig, ManimFrame

__all__ = [
"logger",
"console",
"config",
"file_writer_config",
"camera_config",
"frame",
"tempconfig",
]

Expand All @@ -22,9 +22,8 @@
logging.getLogger("PIL").setLevel(logging.INFO)
logging.getLogger("matplotlib").setLevel(logging.INFO)

config = make_config(parser)
camera_config = config
file_writer_config = make_file_writer_config(parser, config)
config = ManimConfig(parser)
frame = ManimFrame(config)


# This has to go here because it needs access to this module's config
Expand Down
68 changes: 14 additions & 54 deletions manim/config/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,13 @@ upto_animation_number = -1
media_dir = ./media

# --log_dir (by default "/logs", that will be put inside the media dir)
log_dir = logs
log_dir = {media_dir}/logs

# # --video_dir
# video_dir = %(MEDIA_DIR)s/videos

# # --tex_dir
# tex_dir = %(MEDIA_DIR)s/Tex

# # --text_dir
# text_dir = %(MEDIA_DIR)s/texts
# the following do not have CLI arguments but depend on media_dir
video_dir = {media_dir}/videos
tex_dir = {media_dir}/Tex
text_dir = {media_dir}/texts
images_dir = {media_dir}/images

# --use_js_renderer
use_js_renderer = False
Expand Down Expand Up @@ -112,45 +109,6 @@ disable_caching = False
# --tex_template
tex_template =

# These override the previous by using -t, --transparent
[transparent]
png_mode = RGBA
movie_file_extension = .mov
background_opacity = 0

# These override the previous by using -k, --four_k
[fourk_quality]
pixel_height = 2160
pixel_width = 3840
frame_rate = 60

# These override the previous by using -e, --high_quality
[high_quality]
pixel_height = 1440
pixel_width = 2560
frame_rate = 60

# These override the previous by using -m, --medium_quality
[medium_quality]
pixel_height = 720
pixel_width = 1280
frame_rate = 30

# These override the previous by using -l, --low_quality
[low_quality]
pixel_height = 480
pixel_width = 854
frame_rate = 15

# These override the previous by using --dry_run
# Note --dry_run overrides all of -w, -a, -s, -g, -i
[dry_run]
write_to_movie = False
write_all = False
save_last_frame = False
save_pngs = False
save_as_gif = False

# Streaming settings
[streaming]
live_stream_name = LiveStream
Expand All @@ -170,10 +128,11 @@ streaming_console_banner = Manim is now running in streaming mode.
# under media_dir, as is the default.
[custom_folders]
media_dir = videos
video_dir = %(media_dir)s
images_dir = %(media_dir)s
text_dir = %(media_dir)s/temp_files
tex_dir = %(media_dir)s/temp_files
video_dir = {media_dir}
images_dir = {media_dir}
text_dir = {media_dir}/temp_files
tex_dir = {media_dir}/temp_files
log_dir = {media_dir}/temp_files

# Rich settings
[logger]
Expand All @@ -193,5 +152,6 @@ log_height = -1
log_timestamps = True

[ffmpeg]
# Uncomment the following line to manually set the loglevel for ffmpeg. See ffmpeg manpage for accepted values
# loglevel = error
# Uncomment the following line to manually set the loglevel for ffmpeg. See
# ffmpeg manpage for accepted values
loglevel = ERROR
Loading