Skip to content

Configparser setup: figuring out config.py, constants.py, dirs.py, CLI arguments, and more [WIP] #98

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 46 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9cba5f7
move a bunch of variables from constants.py into the config.cfg file,…
leotrs May 25, 2020
b22135f
Prefer the use of COLOR_MAP over PALETTE
leotrs May 25, 2020
97431fc
add initial config.cfg file
leotrs May 25, 2020
61ff836
Merge branch 'master' into configparser-setup
leotrs May 25, 2020
6d0d7a3
WIP setup of configparser
leotrs May 27, 2020
d0a7598
resolve merge conflicts
leotrs May 27, 2020
b86f358
answers some of the requested changes
leotrs May 29, 2020
b162109
solve merge conflicts
leotrs Jun 4, 2020
32f72a0
split config into two dicts
leotrs Jun 5, 2020
b1a7475
fix usage of CONFIG and file_writer_config
leotrs Jun 5, 2020
985e5f8
fix: data_files seems to be deprecated; add the config files to packa…
leotrs Jun 5, 2020
b00a51f
clarify comment
leotrs Jun 5, 2020
fae6927
install ffmpeg on linux
leotrs Jun 6, 2020
dfccf0d
travis setup
leotrs Jun 6, 2020
e6691f2
fix dumb
leotrs Jun 6, 2020
392e26a
fix arg parsing by not passing the first argv to the config parser
leotrs Jun 6, 2020
07c6c29
now try without upgrading the whole system
leotrs Jun 6, 2020
27c12ba
fix: now --dry_run correctly overrides -w, -a, -s, -g, and -ig
leotrs Jun 6, 2020
dd3b780
fix: now support -o flag
leotrs Jun 6, 2020
d5bf02c
fix: move config.file_writer_config["gif_file_extension"] to constant…
leotrs Jun 7, 2020
a6c3165
do not prompt the user
leotrs Jun 7, 2020
aeb20cc
update comment
leotrs Jun 7, 2020
83f0b84
Merge branch 'master' of github.com:ManimCommunity/manim into configp…
leotrs Jun 7, 2020
5c2e085
change loglevel to debug in order to see what is going on in Windows …
leotrs Jun 7, 2020
834063a
Prettier if statement
leotrs Jun 10, 2020
754e50b
More idiomatic for loop
leotrs Jun 10, 2020
7b6b370
Readability
leotrs Jun 10, 2020
7ad6aa9
fix typo
leotrs Jun 10, 2020
cc11fef
Merge branch 'configparser-setup' of github.com:ManimCommunity/manim …
leotrs Jun 10, 2020
1fe4505
reverse debugging changes
leotrs Jun 10, 2020
85e6b79
some fixes by PG
leotrs Jun 11, 2020
a8e2a4e
fix merge conflicts
leotrs Jun 11, 2020
9e5ea50
check for None and for empty string
leotrs Jun 11, 2020
3b962e4
handle more general cases of file names
leotrs Jun 15, 2020
b3ebc9e
make the -s flag invalidate -w
leotrs Jun 15, 2020
bfaffc7
fix: use correct re method
leotrs Jun 15, 2020
a67015f
delete unnecessary code
leotrs Jun 15, 2020
2ef1070
more pythonic
leotrs Jun 18, 2020
f24d9ef
fix merge conflicts from tests (#133)
leotrs Jun 23, 2020
e4837b4
update tests wo new config system
leotrs Jul 4, 2020
b660303
update tests to config system
leotrs Jul 4, 2020
9077542
Loose ends
eulertour Jul 5, 2020
f4c8431
fix deprecatet variables
leotrs Jul 5, 2020
4dfff03
Merge branch 'configparser-setup' of github.com:ManimCommunity/manim …
leotrs Jul 5, 2020
0229f78
Add information to test failures
eulertour Jul 5, 2020
b69f6e8
Update config variables and paths in tests
eulertour Jul 5, 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
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- os: linux
language: python
python: 3.7
python: 3.7
install:
- pip3 install --upgrade pip
- pip3 install -r ./.travis/travis-requirements.txt
Expand All @@ -39,7 +39,7 @@ jobs:
language: sh
python: 3.6
env: PYVER="3.6.10"
before_install:
before_install:
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
- brew install ffmpeg
- brew cask install mactex
Expand All @@ -56,7 +56,7 @@ jobs:
language: sh
python: 3.7
env: PYVER="3.7.7"
before_install:
before_install:
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
- brew install ffmpeg
- brew cask install mactex
Expand All @@ -73,7 +73,7 @@ jobs:
language: sh
python: 3.8
env: PYVER="3.8.0" # Using Python 3.8.0 due to error with rich
before_install:
before_install:
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
- brew install ffmpeg
- brew cask install mactex
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
- python ./scripts/pycairoinstall.py
- cmd.exe //c "RefreshEnv.cmd"
- python -m pip install --user .
script:
script:
- python -m pytest --skip_end_to_end -rs

- os: windows
Expand All @@ -117,7 +117,7 @@ jobs:
- python ./scripts/pycairoinstall.py
- cmd.exe //c "RefreshEnv.cmd"
- python -m pip install --user .
script:
script:
- python -m pytest --skip_end_to_end -rs

- os: windows
Expand All @@ -133,12 +133,13 @@ jobs:
- python ./scripts/pycairoinstall.py
- cmd.exe //c "RefreshEnv.cmd"
- python -m pip install --user .
script:
script:
- python -m pytest --skip_end_to_end -rs

before_install:
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then chmod +x ./.travis/osx.sh; sh ./.travis/osx.sh; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then chmod +x ./.travis/linux.sh; sh ./.travis/linux.sh; fi

branches:
only:
- master
Expand Down
2 changes: 1 addition & 1 deletion .travis/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

sudo apt update
sudo apt install -y ffmpeg
sudo apt-get -y install texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa
sudo apt-get -y install texlive texlive-latex-extra texlive-fonts-extra texlive-latex-recommended texlive-science texlive-fonts-extra tipa
3 changes: 2 additions & 1 deletion .travis/osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
brew update
brew install openssl readline
brew outdated pyenv || brew upgrade pyenv
brew install ffmpeg
brew install pyenv-virtualenv
pyenv install $PYVER
export PYENV_VERSION=$PYVER
export PATH="/Users/travis/.pyenv/shims:${PATH}"
pyenv virtualenv venv
source ~/.pyenv/versions/venv/bin/activate
python --version
python --version
4 changes: 1 addition & 3 deletions .travis/travis-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ Pillow
progressbar
scipy
tqdm
# opencv-python
# pycairo
pydub
pygments
pyreadline; sys_platform == 'win32'
rich
pytest
pytest
2 changes: 1 addition & 1 deletion example_scenes/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def construct(self):
)
group = VGroup(example_text, example_tex)
group.arrange(DOWN)
group.set_width(FRAME_WIDTH - 2 * LARGE_BUFF)
group.set_width(config['frame_width'] - 2 * LARGE_BUFF)

self.play(Write(example_text))
self.play(Write(example_tex))
Expand Down
7 changes: 4 additions & 3 deletions example_scenes/customtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

class ExampleFileScene(Scene):
def construct(self):
text=TexMobject(r"\vv{vb}")
text = TexMobject(r"\vv{vb}")
#text=TextMobject(r"$\vv{vb}$")
self.play(Write(text))


class ExampleClassScene(Scene):
def construct(self):
tpl=TexTemplate()
tpl = TexTemplate()
tpl.append_package(["esvect",["f"]])
config.register_tex_template(tpl)

#text=TextMobject(r"$\vv{vb}$")
text=TexMobject(r"\vv{vb}")
text = TexMobject(r"\vv{vb}")
self.play(Write(text))
3 changes: 3 additions & 0 deletions manim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env python

# Importing config should be the first thing since other modules use it
from .config import config
from .constants import *

from .animation.animation import *
Expand Down
167 changes: 160 additions & 7 deletions manim/__main__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,167 @@
from . import extract_scene
from . import config
import inspect
import os
import platform
import subprocess as sp
import sys
import re
import traceback
import importlib.util

from .config import file_writer_config
from .scene.scene import Scene
from .utils.sounds import play_error_sound
from .utils.sounds import play_finish_sound
from . import constants
from .logger import logger


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

open_file = any([
file_writer_config["preview"],
file_writer_config["show_file_in_finder"]
])
if open_file:
current_os = platform.system()
file_paths = []

if file_writer_config["save_last_frame"]:
file_paths.append(file_writer.get_image_file_path())
if file_writer_config["write_to_movie"]:
file_paths.append(file_writer.get_movie_file_path())

for file_path in file_paths:
if current_os == "Windows":
os.startfile(file_path)
else:
commands = []
if current_os == "Linux":
commands.append("xdg-open")
elif current_os.startswith("CYGWIN"):
commands.append("cygstart")
else: # Assume macOS
commands.append("open")

if file_writer_config["show_file_in_finder"]:
commands.append("-R")

commands.append(file_path)

# commands.append("-g")
FNULL = open(os.devnull, 'w')
sp.call(commands, stdout=FNULL, stderr=sp.STDOUT)
FNULL.close()

if file_writer_config["quiet"]:
sys.stdout.close()
sys.stdout = curr_stdout


def is_child_scene(obj, module):
return (inspect.isclass(obj)
and issubclass(obj, Scene)
and obj != Scene
and obj.__module__.startswith(module.__name__))


def prompt_user_for_choice(scene_classes):
num_to_class = {}
for count, scene_class in enumerate(scene_classes):
count += 1 # start with 1 instead of 0
name = scene_class.__name__
print("%d: %s" % (count, name))
num_to_class[count] = scene_class
try:
user_input = input(constants.CHOOSE_NUMBER_MESSAGE)
return [num_to_class[int(num_str)]
for num_str in re.split(r"\s*,\s*", user_input.strip())]
except KeyError:
logger.error(constants.INVALID_NUMBER_MESSAGE)
sys.exit(2)
except EOFError:
sys.exit(1)


def get_scenes_to_render(scene_classes):
if not scene_classes:
logger.error(constants.NO_SCENE_MESSAGE)
return []
if file_writer_config["write_all"]:
return scene_classes
result = []
for scene_name in file_writer_config["scene_names"]:
found = False
for scene_class in scene_classes:
if scene_class.__name__ == scene_name:
result.append(scene_class)
found = True
break
if not found and (scene_name != ""):
logger.error(
constants.SCENE_NOT_FOUND_MESSAGE.format(
scene_name
)
)
if result:
return result
return [scene_classes[0]] if len(scene_classes) == 1 else prompt_user_for_choice(scene_classes)


def get_scene_classes_from_module(module):
if hasattr(module, "SCENES_IN_ORDER"):
return module.SCENES_IN_ORDER
else:
return [
member[1]
for member in inspect.getmembers(
module,
lambda x: is_child_scene(x, module)
)
]


def get_module(file_name):
if file_name == "-":
module = types.ModuleType("input_scenes")
code = sys.stdin.read()
try:
exec(code, module.__dict__)
return module
except Exception as e:
logger.error(f"Failed to render scene: {str(e)}")
sys.exit(2)
else:
if os.path.exists(file_name):
module_name = re.sub(r"\..+$", "", file_name.replace(os.sep, "."))
spec = importlib.util.spec_from_file_location(module_name, file_name)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
else:
raise FileNotFoundError(f'{file_name} not found')


def main():
args = config.parse_cli()
cfg = config.get_configuration(args)
config.initialize_directories(cfg)
config.initialize_tex(cfg)
extract_scene.main(cfg)
module = get_module(file_writer_config["input_file"])
all_scene_classes = get_scene_classes_from_module(module)
scene_classes_to_render = get_scenes_to_render(all_scene_classes)
sound_on = file_writer_config["sound"]
for SceneClass in scene_classes_to_render:
try:
# By invoking, this renders the full scene
scene = SceneClass()
open_file_if_needed(scene.file_writer)
if sound_on:
play_finish_sound()
except Exception:
print("\n\n")
traceback.print_exc()
print("\n\n")
if sound_on:
play_error_sound()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion manim/animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,4 @@ def __init__(self, start_anim, end_anim, **kwargs):
def interpolate(self, alpha):
self.start_anim.interpolate(alpha)
self.end_anim.interpolate(alpha)
Transform.interpolate(self, alpha)
Transform.interpolate(self, alpha)
19 changes: 10 additions & 9 deletions manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numpy as np

from ..constants import *
from ..config import config
from ..logger import logger
from ..mobject.types.image_mobject import AbstractImageMobject
from ..mobject.mobject import Mobject
Expand All @@ -36,24 +37,24 @@ class Camera(object):
self.background_image : str, optional
The path to an image that should be the background image.
If not set, the background is filled with `self.background_color`

self.pixel_height
"""
CONFIG = {
"background_image": None,
"pixel_height": DEFAULT_PIXEL_HEIGHT,
"pixel_width": DEFAULT_PIXEL_WIDTH,
"frame_rate": DEFAULT_FRAME_RATE,
"pixel_height": config['pixel_height'],
"pixel_width": config['pixel_width'],
"frame_rate": config['frame_rate'],
# Note: frame height and width will be resized to match
# the pixel aspect ratio
"frame_height": FRAME_HEIGHT,
"frame_width": FRAME_WIDTH,
"frame_height": config['frame_height'],
"frame_width": config['frame_width'],
"frame_center": ORIGIN,
"background_color": BLACK,
"background_opacity": 1,
# Points in vectorized mobjects with norm greater
# than this value will be rescaled.
"max_allowable_norm": FRAME_WIDTH,
"max_allowable_norm": config['frame_width'],
"image_mode": "RGBA",
"n_channels": 4,
"pixel_array_dtype": 'uint8',
Expand Down Expand Up @@ -767,7 +768,7 @@ def apply_stroke(self, ctx, vmobject, background=False):
width * self.cairo_line_width_multiple *
# This ensures lines have constant width
# as you zoom in on them.
(self.get_frame_width() / FRAME_WIDTH)
(self.get_frame_width() / self.frame_width)
)
ctx.stroke_preserve()
return self
Expand Down Expand Up @@ -1331,4 +1332,4 @@ def display(self, *cvmobjects):
else:
curr_array = np.maximum(curr_array, new_array)
self.reset_pixel_array()
return curr_array
return curr_array
Loading