A community-maintained Python framework for creating mathematical animations.
Removed deprecated new command (#3512)
Francisco Manríquez Novoa3f118e4921ef
diff --git a/manim/__main__.py b/manim/__main__.pyindex 18de91a41..7b57cc54a 100644--- a/manim/__main__.py+++ b/manim/__main__.py@@ -9,7 +9,6 @@ from .cli.cfg.group import cfgfrom .cli.checkhealth.commands import checkhealthfrom .cli.default_group import DefaultGroupfrom .cli.init.commands import init-from .cli.new.group import newfrom .cli.plugins.commands import pluginsfrom .cli.render.commands import renderfrom .constants import EPILOG@@ -52,7 +51,6 @@ main.add_command(checkhealth)main.add_command(cfg)main.add_command(plugins)main.add_command(init)-main.add_command(new)main.add_command(render)if __name__ == "__main__":diff --git a/manim/cli/new/__init__.py b/manim/cli/new/__init__.pydeleted file mode 100644index e69de29bb..000000000diff --git a/manim/cli/new/group.py b/manim/cli/new/group.pydeleted file mode 100644index 2907c6201..000000000--- a/manim/cli/new/group.py+++ /dev/null@@ -1,189 +0,0 @@-from __future__ import annotations--import configparser-from pathlib import Path--import click-import cloup--from ... import console-from ...constants import CONTEXT_SETTINGS, EPILOG, QUALITIES-from ...utils.file_ops import (- add_import_statement,- copy_template_files,- get_template_names,- get_template_path,-)--CFG_DEFAULTS = {- "frame_rate": 30,- "background_color": "BLACK",- "background_opacity": 1,- "scene_names": "Default",- "resolution": (854, 480),-}---def select_resolution():- """Prompts input of type click.Choice from user. Presents options from QUALITIES constant.-- Returns- -------- :class:`tuple`- Tuple containing height and width.- """- resolution_options = []- for quality in QUALITIES.items():- resolution_options.append(- (quality[1]["pixel_height"], quality[1]["pixel_width"]),- )- resolution_options.pop()- choice = click.prompt(- "\nSelect resolution:\n",- type=cloup.Choice([f"{i[0]}p" for i in resolution_options]),- show_default=False,- default="480p",- )- return [res for res in resolution_options if f"{res[0]}p" == choice][0]---def update_cfg(cfg_dict: dict, project_cfg_path: Path):- """Updates the manim.cfg file after reading it from the project_cfg_path.-- Parameters- ----------- cfg_dict- values used to update manim.cfg found project_cfg_path.- project_cfg_path- Path of manim.cfg file.- """- config = configparser.ConfigParser()- config.read(project_cfg_path)- cli_config = config["CLI"]- for key, value in cfg_dict.items():- if key == "resolution":- cli_config["pixel_height"] = str(value[0])- cli_config["pixel_width"] = str(value[1])- else:- cli_config[key] = str(value)-- with project_cfg_path.open("w") as conf:- config.write(conf)--- context_settings=CONTEXT_SETTINGS,- epilog=EPILOG,-)[email protected]("project_name", type=Path, required=False)- "-d",- "--default",- "default_settings",- is_flag=True,- help="Default settings for project creation.",- nargs=1,-)-def project(default_settings, **args):- """Creates a new project.-- PROJECT_NAME is the name of the folder in which the new project will be initialized.- """- if args["project_name"]:- project_name = args["project_name"]- else:- project_name = click.prompt("Project Name", type=Path)-- # in the future when implementing a full template system. Choices are going to be saved in some sort of config file for templates- template_name = click.prompt(- "Template",- type=click.Choice(get_template_names(), False),- default="Default",- )-- if project_name.is_dir():- console.print(- f"\nFolder [red]{project_name}[/red] exists. Please type another name\n",- )- else:- project_name.mkdir()- new_cfg = {}- new_cfg_path = Path.resolve(project_name / "manim.cfg")-- if not default_settings:- for key, value in CFG_DEFAULTS.items():- if key == "scene_names":- new_cfg[key] = template_name + "Template"- elif key == "resolution":- new_cfg[key] = select_resolution()- else:- new_cfg[key] = click.prompt(f"\n{key}", default=value)-- console.print("\n", new_cfg)- if click.confirm("Do you want to continue?", default=True, abort=True):- copy_template_files(project_name, template_name)- update_cfg(new_cfg, new_cfg_path)- else:- copy_template_files(project_name, template_name)- update_cfg(CFG_DEFAULTS, new_cfg_path)--- context_settings=CONTEXT_SETTINGS,- no_args_is_help=True,- epilog=EPILOG,-)[email protected]("scene_name", type=str, required=True)[email protected]("file_name", type=str, required=False)-def scene(**args):- """Inserts a SCENE to an existing FILE or creates a new FILE.-- SCENE is the name of the scene that will be inserted.-- FILE is the name of file in which the SCENE will be inserted.- """- if not Path("main.py").exists():- raise FileNotFoundError(f"{Path('main.py')} : Not a valid project directory.")-- template_name = click.prompt(- "template",- type=click.Choice(get_template_names(), False),- default="Default",- )- scene = (get_template_path() / f"{template_name}.mtp").resolve().read_text()- scene = scene.replace(template_name + "Template", args["scene_name"], 1)-- if args["file_name"]:- file_name = Path(args["file_name"] + ".py")-- if file_name.is_file():- # file exists so we are going to append new scene to that file- with file_name.open("a") as f:- f.write("\n\n\n" + scene)- else:- # file does not exist so we create a new file, append the scene and prepend the import statement- file_name.write_text("\n\n\n" + scene)-- add_import_statement(file_name)- else:- # file name is not provided so we assume it is main.py- # if main.py does not exist we do not continue- with Path("main.py").open("a") as f:- f.write("\n\n\n" + scene)--- context_settings=CONTEXT_SETTINGS,- invoke_without_command=True,- no_args_is_help=True,- epilog=EPILOG,- help="Create a new project or insert a new scene.",- deprecated=True,-)[email protected]_context-def new(ctx):- pass---new.add_command(project)-new.add_command(scene)diff --git a/tests/interface/test_commands.py b/tests/interface/test_commands.pyindex f2f68857e..92444f703 100644--- a/tests/interface/test_commands.py+++ b/tests/interface/test_commands.py@@ -135,24 +135,3 @@ def test_manim_init_scene(tmp_path):assert (Path(tmp_dir) / "main.py").exists()file_content = (Path(tmp_dir) / "main.py").read_text()assert "DefaultFileTestScene(Scene):" in file_content---def test_manim_new_command():- command = ["new"]- runner = CliRunner()- result = runner.invoke(main, command, prog_name="manim")- expected_output = """\-Usage: manim new [OPTIONS] COMMAND [ARGS]...-- (Deprecated) Create a new project or insert a new scene.--Options:- --help Show this message and exit.--Commands:- project Creates a new project.- scene Inserts a SCENE to an existing FILE or creates a new FILE.--Made with <3 by Manim Community developers.-"""- assert dedent(expected_output) == result.output