Esempio n. 1
0
def main():
    console.print(f"Manim Community [green]v{__version__}[/green]")
    args = parse_args(sys.argv)

    if hasattr(args, "cmd"):
        if args.cmd == "cfg":
            if args.subcmd:
                from manim._config import cfg_subcmds

                if args.subcmd == "write":
                    cfg_subcmds.write(args.level, args.open)
                elif args.subcmd == "show":
                    cfg_subcmds.show()
                elif args.subcmd == "export":
                    cfg_subcmds.export(args.dir)
            else:
                logger.error("No subcommand provided; Exiting...")

        elif args.cmd == "plugins":
            from manim.plugins import plugins_flags

            if args.list:
                plugins_flags.list_plugins()
            elif not args.list:
                logger.error("No flag provided; Exiting...")

        # elif args.cmd == "some_other_cmd":
        #     something_else_here()

    else:
        config.digest_args(args)
        input_file = config.get_dir("input_file")
        if config["use_webgl_renderer"]:
            try:
                from manim.grpc.impl import frame_server_impl

                server = frame_server_impl.get(input_file)
                server.start()
                server.wait_for_termination()
            except ModuleNotFoundError as e:
                print("\n\n")
                print("Dependencies for the WebGL render are missing. Run "
                      "pip install manim[webgl_renderer] to install them.")
                print(e)
                print("\n\n")
        else:
            for SceneClass in scene_classes_from_file(input_file):
                try:
                    scene = SceneClass()
                    scene.render()
                    open_file_if_needed(scene.renderer.file_writer)
                except Exception:
                    print("\n\n")
                    traceback.print_exc()
                    print("\n\n")
Esempio n. 2
0
def main():
    args = parse_args(sys.argv)

    if hasattr(args, "cmd"):
        if args.cmd == "cfg":
            if args.subcmd:
                from manim._config import cfg_subcmds

                if args.subcmd == "write":
                    cfg_subcmds.write(args.level, args.open)
                elif args.subcmd == "show":
                    cfg_subcmds.show()
                elif args.subcmd == "export":
                    cfg_subcmds.export(args.dir)
            else:
                logger.error("No subcommand provided; Exiting...")

        elif args.cmd == "plugins":
            from manim.plugins import plugins_flags

            if args.list:
                plugins_flags.list_plugins()
            elif not args.list:
                logger.error("No flag provided; Exiting...")

        # elif args.cmd == "some_other_cmd":
        #     something_else_here()

    else:
        config.digest_args(args)
        input_file = config.get_dir("input_file")
        if config["use_js_renderer"]:
            try:
                if frame_server_impl is None:
                    raise ImportError(
                        "Dependencies for JS renderer is not installed.")
                server = frame_server_impl.get(input_file)
                server.start()
                server.wait_for_termination()
            except Exception:
                print("\n\n")
                traceback.print_exc()
                print("\n\n")
        else:
            for SceneClass in scene_classes_from_file(input_file):
                try:
                    scene = SceneClass()
                    scene.render()
                    open_file_if_needed(scene.renderer.file_writer)
                except Exception:
                    print("\n\n")
                    traceback.print_exc()
                    print("\n\n")
Esempio n. 3
0
def main():
    args = parse_args(sys.argv)

    if hasattr(args, "cmd"):
        if args.cmd == "cfg":
            if args.subcmd:
                from manim.config import cfg_subcmds

                if args.subcmd == "write":
                    cfg_subcmds.write(args.level, args.open)
                elif args.subcmd == "show":
                    cfg_subcmds.show()
                elif args.subcmd == "export":
                    cfg_subcmds.export(args.dir)
            else:
                logger.error("No subcommand provided; Exiting...")

        # elif args.cmd == "some_other_cmd":
        #     something_else_here()

    else:
        config.digest_args(args)

        module = get_module(config.get_dir("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:
            try:
                if config["use_js_renderer"]:
                    if frame_server_impl is None:
                        raise ImportError(
                            "Dependencies for JS renderer is not installed.")
                    frame_server_impl.get(SceneClass).start()
                else:
                    scene = SceneClass()
                    scene.render()
                    open_file_if_needed(scene.renderer.file_writer)
            except Exception:
                print("\n\n")
                traceback.print_exc()
                print("\n\n")
Esempio n. 4
0
def test_quality_flags():
    # Assert that quality is the default when not specifying it
    parsed = parse_args("manim dummy_filename".split())

    assert parsed.quality == constants.DEFAULT_QUALITY_SHORT
    assert _determine_quality(parsed) == constants.DEFAULT_QUALITY

    for quality in constants.QUALITIES.keys():
        if not constants.QUALITIES[quality]["flag"]:
            continue

        flag = constants.QUALITIES[quality]["flag"]
        # Assert that quality is properly set when using -q*
        arguments = f"manim -q{flag} dummy_filename".split()
        parsed = parse_args(arguments)

        assert parsed.quality == flag
        assert quality == _determine_quality(parsed)

        # Assert that quality is properly set when using -q *
        arguments = f"manim -q {flag} dummy_filename".split()
        parsed = parse_args(arguments)

        assert parsed.quality == flag
        assert quality == _determine_quality(parsed)

        # Assert that quality is properly set when using --quality *
        arguments = f"manim --quality {flag} dummy_filename".split()
        parsed = parse_args(arguments)

        assert parsed.quality == flag
        assert quality == _determine_quality(parsed)

        # Assert that quality is properly set when using -*_quality
        arguments = f"manim --{quality} dummy_filename".split()
        parsed = parse_args(arguments)

        assert getattr(parsed, quality)
        assert quality == _determine_quality(parsed)

        # Assert that *_quality is False when not specifying it
        parsed = parse_args("manim dummy_filename".split())

        assert not getattr(parsed, quality)
        assert _determine_quality(parsed) == constants.DEFAULT_QUALITY