This commit is contained in:
retoor 2025-05-09 09:56:23 +02:00
parent e5d155e124
commit 7e8ae1632d
2 changed files with 29 additions and 33 deletions

View File

@ -5,17 +5,21 @@ GUNICORN=./.venv/bin/gunicorn
GUNICORN_WORKERS = 1 GUNICORN_WORKERS = 1
PORT = 8081 PORT = 8081
python:
$(PYTHON)
shell:
.venv/bin/snek shell
dump: dump:
@$(PYTHON) -m snek.dump @$(PYTHON) -m snek.dump
build: build:
serve: run
run: run:
.venv/usr/bin/snek .venv/bin/snek serve
#$(GUNICORN) -w $(GUNICORN_WORKERS) -k aiohttp.worker.GunicornWebWorker snek.gunicorn:app --bind 0.0.0.0:$(PORT) --reload #$(GUNICORN) -w $(GUNICORN_WORKERS) -k aiohttp.worker.GunicornWebWorker snek.gunicorn:app --bind 0.0.0.0:$(PORT) --reload
install: ubuntu install: ubuntu

View File

@ -1,40 +1,32 @@
import argparse import click
import uvloop import uvloop
from aiohttp import web from aiohttp import web
import asyncio import asyncio
from snek.app import Application from snek.app import Application
from IPython import start_ipython
@click.group()
def cli():
pass
@cli.command()
@click.option('--port', default=8081, show_default=True, help='Port to run the application on')
@click.option('--host', default='0.0.0.0', show_default=True, help='Host to run the application on')
@click.option('--db_path', default='snek.db', show_default=True, help='Database path for the application')
def serve(port, host, db_path):
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
web.run_app(
Application(db_path=f"sqlite:///{db_path}"), port=port, host=host
)
@cli.command()
@click.option('--db_path', default='snek.db', show_default=True, help='Database path for the application')
def shell(db_path):
app = Application(db_path=f"sqlite:///{db_path}")
start_ipython(argv=[], user_ns={'app': app})
def main(): def main():
cli()
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
parser = argparse.ArgumentParser(description="Run the web application.")
parser.add_argument(
"--port",
type=int,
default=8081,
help="Port to run the application on (default: 8081)",
)
parser.add_argument(
"--host",
type=str,
default="0.0.0.0",
help="Host to run the application on (default: 0.0.0.0)",
)
parser.add_argument(
"--db_path",
type=str,
default="snek.db",
help="Database path for the application (default: sqlite:///snek.db)",
)
args = parser.parse_args()
web.run_app(
Application(db_path="sqlite:///" + args.db_path), port=args.port, host=args.host
)
if __name__ == "__main__": if __name__ == "__main__":
main() main()