-
Notifications
You must be signed in to change notification settings - Fork 4
/
quotera_cli.py
executable file
·78 lines (59 loc) · 1.97 KB
/
quotera_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import typer
from typing import Optional
from enum import Enum
from termcolor import cprint
from pyfiglet import figlet_format
app = typer.Typer()
class Environment(str, Enum):
dev = "dev"
staging = "staging"
production = "production"
@app.command()
def serve(env: Optional[Environment] = Environment.dev, host: str = "0.0.0.0"):
typer.echo(f"\nRunning Quotera API | Environment: {env} 🚀 \n")
typer.echo(cprint(figlet_format("Quotera", font="doom"), "green", attrs=["bold"]))
os.system(
f"ENV_FILE='.env.{env}' GUNICORN_CMD_ARGS='--keep-alive 0' uvicorn src.main:quotera --reload --host {host}"
)
# In case of need to run workers
@app.command()
def serve_gunicorn(
env: Optional[Environment] = Environment.dev,
workers: int = 4,
host: str = "0.0.0.0",
):
typer.echo(f"\nRunning Quotera API with gunicorn | Environment: {env} 🚀 \n")
os.system(
f"ENV_FILE='.env.{env}' gunicorn -w {workers} -k uvicorn.workers.UvicornWorker --bind {host} src.main:quotera"
)
@app.command("venv")
def create_venv():
typer.echo("\nCreating virtual environment...")
os.system("python -m venv .venv")
command = typer.style(
"`source ./.venv/bin/activate`", fg=typer.colors.GREEN, bold=True
)
typer.echo(f"\nActivate with: {command}.")
@app.command()
def install():
# typer.echo("\nInstalling packages 🚀")
os.system("pip install -r requirements.txt ")
typer.echo(f"\nPackages installed")
@app.command()
def test(watch: bool = False):
typer.echo("\nTesting package 🚀")
if watch:
os.system("ENV_FILE='.env.test' ptw")
return
os.system("ENV_FILE='.env.test' pytest")
@app.command("activate")
def activate_venv():
typer.echo("\nActivate enviroment 🚀")
os.system("source ./.venv/bin/activate")
@app.command("deactivate")
def deactivate_venv():
typer.echo("\nDeactivate enviroment 🚀")
os.system("deactivate")
if __name__ == "__main__":
app()