Skip to content

Commit

Permalink
Refactor #1637 (#1650)
Browse files Browse the repository at this point in the history
* Refactor #1637

* Refactor #1637

* Refactor #1637

* Refactor #1637

* Refactor #1637

* Refactor #1637

* Update config.py

Co-authored-by: 鹤翔万里 <tonycrane@foxmail.com>
  • Loading branch information
YishiMichael and TonyCrane authored Oct 16, 2021
1 parent bee3470 commit 0e57488
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
6 changes: 3 additions & 3 deletions manimlib/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


def main():
args = manimlib.config.parse_cli()

print(f"ManimGL \033[32mv{__version__}\033[0m")

args = manimlib.config.parse_cli()
if args.version and args.file == None:
return

Expand All @@ -21,5 +21,5 @@ def main():
for scene in scenes:
scene.run()

if __name__ == '__main__':
if __name__ == "__main__":
main()
12 changes: 6 additions & 6 deletions manimlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def get_custom_config():

def check_temporary_storage(config):
if config["directories"]["temporary_storage"] == "" and sys.platform == "win32":
log.warning("You may be using Windows platform and have not specified the `temporary\
_storage` path, which may cause OSError. So it is recommended that you specify the `temporary\
_storage` in the config file (.yml)")
log.warning("You may be using Windows platform and have not specified the path of"
" `temporary_storage`, which may cause OSError. So it is recommended"
" to specify the `temporary_storage` in the config file (.yml)")


def get_configuration(args):
Expand All @@ -220,13 +220,13 @@ def get_configuration(args):
global_defaults_file = os.path.join(get_manim_dir(), "manimlib", "default_config.yml")

if not (os.path.exists(global_defaults_file) or os.path.exists(__config_file__)):
log.info("There is no configuration file detected. Initial configuration:\n")
log.info("There is no configuration file detected. Switch to the config file initializer:")
init_customization()

elif not os.path.exists(__config_file__):
log.info(f"Using the default configuration file, which you can modify in `{global_defaults_file}`")
log.info(f"If you want to create a local configuration file, you can create a file named \
`{__config_file__}`, or run `manimgl --config`")
log.info("If you want to create a local configuration file, you can create a file named"
f" `{__config_file__}`, or run `manimgl --config`")

custom_config = get_custom_config()
check_temporary_storage(custom_config)
Expand Down
5 changes: 4 additions & 1 deletion manimlib/logger.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
from rich.logging import RichHandler

__all__ = ["log"]


FORMAT = "%(message)s"
logging.basicConfig(
level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)

log = logging.getLogger("rich")
log = logging.getLogger("rich")
14 changes: 6 additions & 8 deletions manimlib/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

from manimlib.animation.animation import prepare_animation
from manimlib.animation.transform import MoveToTarget
from manimlib.mobject.mobject import Point
from manimlib.camera.camera import Camera
from manimlib.constants import DEFAULT_WAIT_TIME
from manimlib.mobject.mobject import Mobject
from manimlib.mobject.mobject import Point
from manimlib.scene.scene_file_writer import SceneFileWriter
from manimlib.utils.config_ops import digest_config
from manimlib.utils.family_ops import extract_mobject_family_members
Expand Down Expand Up @@ -101,8 +101,8 @@ def interact(self):
# If there is a window, enter a loop
# which updates the frame while under
# the hood calling the pyglet event loop
log.info("Tips: You are now in the interactive mode. Now you can use the keyboard\
and the mouse to interact with the scene. Just press `q` if you want to quit.")
log.info("Tips: You are now in the interactive mode. Now you can use the keyboard"
" and the mouse to interact with the scene. Just press `q` if you want to quit.")
self.quit_interaction = False
self.lock_static_mobject_data()
while not (self.window.is_closing or self.quit_interaction):
Expand Down Expand Up @@ -134,8 +134,8 @@ def embed(self):
local_ns["touch"] = self.interact
for term in ("play", "wait", "add", "remove", "clear", "save_state", "restore"):
local_ns[term] = getattr(self, term)
log.info("Tips: Now the embed iPython terminal is open. But you can't interact with \
the window directly. To do so, you need to type `touch()` or `self.interact()`")
log.info("Tips: Now the embed iPython terminal is open. But you can't interact with"
" the window directly. To do so, you need to type `touch()` or `self.interact()`")
shell(local_ns=local_ns, stack_depth=2)
# End scene when exiting an embed.
raise EndSceneEarlyException()
Expand Down Expand Up @@ -463,9 +463,7 @@ def finish_animations(self, animations):
@handle_play_like_call
def play(self, *args, **kwargs):
if len(args) == 0:
log.warning(
"Called Scene.play with no animations"
)
log.warning("Called Scene.play with no animations")
return
animations = self.anims_from_play_args(*args, **kwargs)
self.lock_static_mobject_data(*animations)
Expand Down
2 changes: 1 addition & 1 deletion manimlib/scene/scene_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def save_final_image(self, image):
self.print_file_ready_message(file_path)

def print_file_ready_message(self, file_path):
log.info(f"\nFile ready at {file_path}\n")
log.info(f"File ready at {file_path}")

def should_open_file(self):
return any([
Expand Down
6 changes: 3 additions & 3 deletions manimlib/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def interpolate(start, end, alpha):
try:
return (1 - alpha) * start + alpha * end
except TypeError:
log.debug(type(start), start.dtype)
log.debug(type(end), start.dtype)
log.debug(alpha)
log.debug(f"`start` parameter with type `{type(start)}` and dtype `{start.dtype}`")
log.debug(f"`end` parameter with type `{type(end)}` and dtype `{end.dtype}`")
log.debug(f"`alpha` parameter with value `{alpha}`")
import sys
sys.exit(2)

Expand Down
1 change: 1 addition & 0 deletions manimlib/utils/init_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def init_customization():
}
}

print("Initialize configuration")
scope = input(" Please select the scope of the configuration [global/local]: ")
if scope == "global":
from manimlib.config import get_manim_dir
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ moderngl_window
pydub
pygments
pyyaml
rich
screeninfo
pyreadline; sys_platform == 'win32'
validators
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ install_requires =
moderngl
moderngl_window
pydub
pygments
pyyaml
rich
screeninfo
pyreadline; sys_platform == 'win32'
validators
Expand Down

0 comments on commit 0e57488

Please sign in to comment.