Spaces:
Sleeping
Sleeping
| """Commande ``serve`` : lance l'interface web FastAPI Picarones. | |
| Sous-module CLI extrait de l'ancien ``picarones/cli.py`` (1519 lignes) | |
| lors du chantier 5 post-Sprint 97. Les commandes ici s'enregistrent | |
| automatiquement sur le groupe ``cli`` à l'import. | |
| Comportement et signatures inchangés — uniquement de la modularisation. | |
| """ | |
| from __future__ import annotations | |
| import sys | |
| import click | |
| from picarones.cli import cli, _setup_logging | |
| # --------------------------------------------------------------------------- | |
| # picarones serve | |
| # --------------------------------------------------------------------------- | |
| def serve_cmd(host: str, port: int, reload: bool, verbose: bool) -> None: | |
| """Lance l'interface web locale Picarones sur localhost. | |
| Accessible dans le navigateur à l'adresse : http://HOST:PORT | |
| \b | |
| Exemples : | |
| picarones serve | |
| picarones serve --port 8080 | |
| picarones serve --host 0.0.0.0 --port 8000 | |
| """ | |
| _setup_logging(verbose) | |
| try: | |
| import uvicorn | |
| except ImportError: | |
| click.echo( | |
| "uvicorn n'est pas installé. Installez-le avec :\n" | |
| " pip install uvicorn[standard]\n" | |
| "ou :\n" | |
| " pip install picarones[web]", | |
| err=True, | |
| ) | |
| sys.exit(1) | |
| url = f"http://{host}:{port}" | |
| click.echo("Picarones — Interface web locale") | |
| click.echo(f"Démarrage du serveur sur {url}") | |
| click.echo("Appuyez sur Ctrl+C pour arrêter.\n") | |
| log_level = "debug" if verbose else "info" | |
| uvicorn.run( | |
| "picarones.web.app:app", | |
| host=host, | |
| port=port, | |
| reload=reload, | |
| log_level=log_level, | |
| ) | |