diff --git a/kitchenai/cli/__init__.py b/kitchenai/cli/__init__.py new file mode 100644 index 0000000..b28b04f --- /dev/null +++ b/kitchenai/cli/__init__.py @@ -0,0 +1,3 @@ + + + diff --git a/kitchenai/cli/main.py b/kitchenai/cli/main.py index e5a67e4..ce2e77d 100644 --- a/kitchenai/cli/main.py +++ b/kitchenai/cli/main.py @@ -6,9 +6,13 @@ from django.conf import settings from cookiecutter.main import cookiecutter from typing_extensions import Annotated +from rich.console import Console +from rich.spinner import Spinner +console = Console() logger = logging.getLogger(__name__) + app = typer.Typer() @app.command() @@ -18,10 +22,30 @@ def add(module: str = typer.Argument("app.kitchen:kitchen")): execute_from_command_line(["manage", "add_module", module]) @app.command() -def init(): +def init(verbose: Annotated[int, typer.Option(help="verbosity level. default 0")] = 0): + django.setup() from django.core.management import execute_from_command_line - execute_from_command_line(["manage", "migrate"]) - execute_from_command_line(["manage", "init"]) + from kitchenai.core.models import KitchenAIManagement + from django.conf import settings + + cmd = ["manage", "migrate","--verbosity", f"{verbose}"] + + if not verbose == 1: + with console.status("Applying migrations...", spinner="dots"): + execute_from_command_line(cmd) + else: + execute_from_command_line(cmd) + + + KitchenAIManagement.objects.all().delete() + try: + mgmt = KitchenAIManagement.objects.create( + version = settings.VERSION, + project_name = "default" + ) + except Exception as e: + logger.error(e) + return @app.command() diff --git a/kitchenai/settings.py b/kitchenai/settings.py index d52a984..3f3f2f0 100644 --- a/kitchenai/settings.py +++ b/kitchenai/settings.py @@ -17,10 +17,17 @@ # 0. Setup # -------------------------------------------------------------------------------------------- + +VERSION = "0.0.1" + BASE_DIR = Path(__file__).resolve(strict=True).parent.parent APPS_DIR = BASE_DIR / "kitchenai" +KITCHENAI_DB_DIR = BASE_DIR / '.kitchenai' + +KITCHENAI_DB_DIR.mkdir(exist_ok=True) + env = Env() env.read_env(Path(BASE_DIR, ".env").as_posix()) @@ -56,7 +63,7 @@ CSRF_COOKIE_SECURE = not DEBUG DATABASES = { - "default": env.dj_db_url("DATABASE_URL", default="sqlite:///db.sqlite3"), + "default": env.dj_db_url("DATABASE_URL", default=f"sqlite:///{KITCHENAI_DB_DIR / 'db.sqlite3'}"), } DATABASES["default"]["ATOMIC_REQUESTS"] = False diff --git a/pyproject.toml b/pyproject.toml index 3c19890..361b1c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,8 @@ dependencies = [ "sentry-sdk", "typer", "whitenoise", - "cookiecutter" + "cookiecutter", + "rich" ] scripts.kitchenai = "kitchenai.__main__:main" diff --git a/requirements-dev.txt b/requirements-dev.txt index 8d3cf90..e69f1a0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,8 +1,7 @@ - # # This file is autogenerated by hatch-pip-compile with Python 3.11 # -# [constraints] requirements.txt (SHA256: 618a6a537aaab456e4811a335eee5e07ba29c910e1e1c050340cac2c611907c3) +# [constraints] requirements.txt (SHA256: 9ea184c46b3b5c6a9cd0638530342b4fba7ac2fccf2b5472412447ae35303083) # # - django-browser-reload # - django-debug-toolbar @@ -56,6 +55,7 @@ # - psycopg[binary] # - pyyaml # - refreshcss +# - rich # - sentry-sdk # - slippers # - typer @@ -1204,7 +1204,10 @@ pyzmq==26.2.0 # jupyter-server questionary==1.10.0 # via bump-my-version - +rcssmin==1.1.2 + # via + # -c requirements.txt + # django-compressor referencing==0.35.1 # via # jsonschema @@ -1250,6 +1253,7 @@ rfc3986-validator==0.1.1 rich==13.9.2 # via # -c requirements.txt + # hatch.envs.dev # bump-my-version # cappa # chromadb diff --git a/requirements.txt b/requirements.txt index b3caa69..1ff603f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,6 +36,7 @@ # - psycopg[binary] # - pyyaml # - refreshcss +# - rich # - sentry-sdk # - slippers # - typer @@ -552,6 +553,7 @@ pyyaml==6.0.2 # llama-index-core # slippers # uvicorn +rcssmin==1.1.2 # via django-compressor refreshcss==0.5.1 # via hatch.envs.default @@ -577,6 +579,7 @@ requests-oauthlib==2.0.0 # kubernetes rich==13.9.2 # via + # hatch.envs.default # chromadb # cookiecutter # falco-app