From 3f118e4921ef7754b678118acd0493e1b308af69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Manr=C3=ADquez=20Novoa?= <49853152+chopan050@users.noreply.github.com> Date: Sun, 10 Dec 2023 20:05:32 +0100 Subject: [PATCH] Removed deprecated new command (#3512) Co-authored-by: Naveen M K --- manim/__main__.py | 2 - manim/cli/new/__init__.py | 0 manim/cli/new/group.py | 189 ------------------------------- tests/interface/test_commands.py | 21 ---- 4 files changed, 212 deletions(-) delete mode 100644 manim/cli/new/__init__.py delete mode 100644 manim/cli/new/group.py diff --git a/manim/__main__.py b/manim/__main__.py index 18de91a411..7b57cc54aa 100644 --- a/manim/__main__.py +++ b/manim/__main__.py @@ -9,7 +9,6 @@ from .cli.checkhealth.commands import checkhealth from .cli.default_group import DefaultGroup from .cli.init.commands import init -from .cli.new.group import new from .cli.plugins.commands import plugins from .cli.render.commands import render from .constants import EPILOG @@ -52,7 +51,6 @@ def main(ctx): 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__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/manim/cli/new/group.py b/manim/cli/new/group.py deleted file mode 100644 index 2907c62017..0000000000 --- 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) - - -@cloup.command( - context_settings=CONTEXT_SETTINGS, - epilog=EPILOG, -) -@cloup.argument("project_name", type=Path, required=False) -@cloup.option( - "-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) - - -@cloup.command( - context_settings=CONTEXT_SETTINGS, - no_args_is_help=True, - epilog=EPILOG, -) -@cloup.argument("scene_name", type=str, required=True) -@cloup.argument("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) - - -@cloup.group( - 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, -) -@cloup.pass_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.py index f2f68857e8..92444f703d 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