Skip to content

Commit

Permalink
link opinionated creation to cli frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteOtter committed Sep 19, 2023
1 parent 2818cb3 commit 9a7a445
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/nester/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.")
Expand Down
14 changes: 13 additions & 1 deletion src/nester/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions src/nester/core/opinionated/opinionated_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import toml
import yaml

from . import exceptions, supported_linters
from . import exceptions, supported_tools


def set_config_files_for_project(
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 9a7a445

Please sign in to comment.