From 75c4c55a32d86b014178b0ed123bf9b0174d3ef5 Mon Sep 17 00:00:00 2001 From: Sli Date: Tue, 4 Mar 2025 11:59:35 +0100 Subject: [PATCH] Only run full procfile on runserver --- .env.example | 6 +++--- .gitignore | 1 + Procfile.dev => Procfile.full | 0 Procfile.pytest => Procfile.minimal | 0 docs/tutorial/install-advanced.md | 4 ++-- docs/tutorial/structure.md | 8 ++++---- manage.py | 7 ++++--- sith/pytest.py | 6 +++--- sith/settings.py | 4 ++-- 9 files changed, 19 insertions(+), 17 deletions(-) rename Procfile.dev => Procfile.full (100%) rename Procfile.pytest => Procfile.minimal (100%) diff --git a/.env.example b/.env.example index da4d2ac8..1f050d4a 100644 --- a/.env.example +++ b/.env.example @@ -12,6 +12,6 @@ REDIS_PORT=7963 CACHE_URL=redis://127.0.0.1:${REDIS_PORT}/0 # Used to select which other services to run alongside -# runserver and pytest -PROCFILE_RUNSERVER=Procfile.dev -PROCFILE_PYTEST=Procfile.pytest +# manage.py, pytest and runserver +PROCFILE_FULL=Procfile.full +PROCFILE_MINIMAL=Procfile.minimal diff --git a/.gitignore b/.gitignore index 65bd0e2e..ecda5902 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ sith/search_indexes/ coverage_report/ node_modules/ .env +*.pid # compiled documentation site/ diff --git a/Procfile.dev b/Procfile.full similarity index 100% rename from Procfile.dev rename to Procfile.full diff --git a/Procfile.pytest b/Procfile.minimal similarity index 100% rename from Procfile.pytest rename to Procfile.minimal diff --git a/docs/tutorial/install-advanced.md b/docs/tutorial/install-advanced.md index 9fc54a8a..b5630d2b 100644 --- a/docs/tutorial/install-advanced.md +++ b/docs/tutorial/install-advanced.md @@ -88,8 +88,8 @@ tous ces services sont déjà configurés. Pour désactiver Honcho il suffit de ne sélectionner aucun `PROCFILE_` dans la config. ```dotenv -PROCFILE_RUNSERVER= -PROCFILE_PYTEST= +PROCFILE_FULL= +PROCFILE_MINIMAL= ``` !!! note diff --git a/docs/tutorial/structure.md b/docs/tutorial/structure.md index 6ab36c6c..6af76354 100644 --- a/docs/tutorial/structure.md +++ b/docs/tutorial/structure.md @@ -82,8 +82,8 @@ sith/ ├── pyproject.toml (31) ├── .venv/ (32) ├── .python-version (33) -├── Procfile.dev (34) -├── Procfile.pytest (35) +├── Procfile.full (34) +├── Procfile.minimal (35) └── README.md ``` @@ -143,9 +143,9 @@ sith/ 32. Dossier d'environnement virtuel généré par uv 33. Fichier qui contrôle quelle version de python utiliser pour le projet 34. Fichier qui contrôle les services additionnels à lancer - avec le serveur de développement + avec le serveur de développement. Serveurs + gestion des statics. 35. Fichier qui contrôle les services additionnels à lancer - avec pytest + avec les autres commandes (pytest, shell…). Serveurs uniquement. ## L'application principale diff --git a/manage.py b/manage.py index 05877790..cb26d55d 100755 --- a/manage.py +++ b/manage.py @@ -21,7 +21,7 @@ import sys from django.utils.autoreload import DJANGO_AUTORELOAD_ENV from sith.composer import start_composer, stop_composer -from sith.settings import PROCFILE_RUNSERVER +from sith.settings import PROCFILE_FULL, PROCFILE_MINIMAL if __name__ == "__main__": logging.basicConfig(encoding="utf-8", level=logging.INFO) @@ -30,8 +30,9 @@ if __name__ == "__main__": from django.core.management import execute_from_command_line - if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and PROCFILE_RUNSERVER is not None: - start_composer(PROCFILE_RUNSERVER) + procfile = PROCFILE_FULL if sys.argv[1] == "runserver" else PROCFILE_MINIMAL + if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and procfile is not None: + start_composer(procfile) _ = atexit.register(stop_composer) execute_from_command_line(sys.argv) diff --git a/sith/pytest.py b/sith/pytest.py index 731cd584..844f49d2 100644 --- a/sith/pytest.py +++ b/sith/pytest.py @@ -3,7 +3,7 @@ import atexit import pytest from .composer import start_composer, stop_composer -from .settings import PROCFILE_PYTEST +from .settings import PROCFILE_MINIMAL # it's the first hook loaded by pytest and can only # be defined in a proper pytest plugin @@ -15,6 +15,6 @@ from .settings import PROCFILE_PYTEST @pytest.hookimpl(tryfirst=True) def pytest_load_initial_conftests(early_config, parser, args): """Hook that loads the composer before the pytest-django plugin""" - if PROCFILE_PYTEST is not None: - start_composer(PROCFILE_PYTEST) + if PROCFILE_MINIMAL is not None: + start_composer(PROCFILE_MINIMAL) _ = atexit.register(stop_composer) diff --git a/sith/settings.py b/sith/settings.py index a95f6725..dab15139 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -64,8 +64,8 @@ def optional_file_parser(value: str) -> Path | None: BASE_DIR = Path(__file__).parent.parent.resolve() # Composer settings -PROCFILE_RUNSERVER = env.optional_file("PROCFILE_RUNSERVER", None) -PROCFILE_PYTEST = env.optional_file("PROCFILE_PYTEST", None) +PROCFILE_FULL = env.optional_file("PROCFILE_FULL", None) +PROCFILE_MINIMAL = env.optional_file("PROCFILE_MINIMAL", None) ## File path used to avoid running the composer multiple times at the same time COMPOSER_PID_PATH = env.path("COMPOSER_PID_PATH", BASE_DIR / "composer.pid")