From 9a7a4459750842ecd6cf6148133110363c9a713e Mon Sep 17 00:00:00 2001 From: ByteOtter Date: Fri, 4 Aug 2023 13:24:46 +0200 Subject: [PATCH] link opinionated creation to cli frontend --- src/nester/cli.py | 13 +++++++++++-- src/nester/core/commands.py | 14 +++++++++++++- .../core/opinionated/opinionated_creation.py | 7 ++++--- .../{supported_linters.py => supported_tools.py} | 0 4 files changed, 28 insertions(+), 6 deletions(-) rename src/nester/core/opinionated/{supported_linters.py => supported_tools.py} (100%) diff --git a/src/nester/cli.py b/src/nester/cli.py index 405567e..73ddb52 100644 --- a/src/nester/cli.py +++ b/src/nester/cli.py @@ -39,7 +39,16 @@ def cli(ctx): "--git", "-g", is_flag=True, default=False, help="Set up git repository as well." ) @click.option("--no-log", is_flag=True, default=False, help="Do not log this project.") -def create(language: str, project_name: str, git: bool, no_log: bool) -> None: +@click.option( + "--opinionated", + "-o", + is_flag=True, + default=False, + help="Configure supported linters and build tools for your project.", +) +def create( + language: str, project_name: str, git: bool, no_log: bool, opinionated: bool +) -> None: """ Create new project structure within current directory. @@ -53,7 +62,7 @@ def create(language: str, project_name: str, git: bool, no_log: bool) -> None: "Starting Nester.\nCopyright (c) 2023 ByteOtter.(github.com/ByteOtter)\nLicensed under the terms of GPL-3.0. Check github.com/ByteOtter/nester/LICENSE for more information.\nNo warranty or liability are included with the use of this software." ) - commands.create_project(language, project_name, git, no_log) + commands.create_project(language, project_name, git, no_log, opinionated) @click.command(help="Validate current structure against Nester's JSON schemas.") diff --git a/src/nester/core/commands.py b/src/nester/core/commands.py index 67ebf33..78b421f 100644 --- a/src/nester/core/commands.py +++ b/src/nester/core/commands.py @@ -8,9 +8,12 @@ from pathlib import Path from . import nester_log, utils +from .opinionated import opinionated_creation -def create_project(language: str, project_name: str, git: bool, no_log: bool) -> None: +def create_project( + language: str, project_name: str, git: bool, no_log: bool, opinionated: bool +) -> None: """ Create a new project. @@ -34,6 +37,15 @@ def create_project(language: str, project_name: str, git: bool, no_log: bool) -> print(f"Creating file structure for your {language} project '{project_name}'...") + if opinionated: + if language is not "py": + print( + "\033[31mSorry, Nester currently only supports opinionated creation for Python projects.\033[0m\nStay tuned on updates for your language." + ) + else: + opinionated_creation.install_build_system(language) + opinionated_creation.install_linters(language) + if git: utils.initialize_git_repository(project_dir) diff --git a/src/nester/core/opinionated/opinionated_creation.py b/src/nester/core/opinionated/opinionated_creation.py index eb18ce1..94b3b93 100644 --- a/src/nester/core/opinionated/opinionated_creation.py +++ b/src/nester/core/opinionated/opinionated_creation.py @@ -10,7 +10,7 @@ import toml import yaml -from . import exceptions, supported_linters +from . import exceptions, supported_tools def set_config_files_for_project( @@ -68,6 +68,7 @@ def set_config_files_for_project( "pre-commit": "*", } + # Add isort profile config to pyproject toml to avoid conflicts between isort and black pyproject_config["tool"]["isort"] = {"profile": "black"} with open("pyproject.toml", "w") as project_toml: @@ -92,7 +93,7 @@ def install_build_system(language: str) -> None: """ match language: case "py": - for tool in supported_linters.py_build: + for tool in supported_tools.py_build: subprocess.run(["pip", "install", tool]) case _: raise exceptions.UnsupportedLanguageException @@ -109,7 +110,7 @@ def install_linters(language: str) -> None: match language: case "py": try: - for linter in supported_linters.py_linters: + for linter in supported_tools.py_linters: subprocess.run(["pip", "install", linter]) except subprocess.CalledProcessError as exc: print( diff --git a/src/nester/core/opinionated/supported_linters.py b/src/nester/core/opinionated/supported_tools.py similarity index 100% rename from src/nester/core/opinionated/supported_linters.py rename to src/nester/core/opinionated/supported_tools.py