Apply review comments

This commit is contained in:
2025-02-20 18:38:15 +01:00
parent 7f8304e407
commit aa66fc61ab
8 changed files with 42 additions and 20 deletions

26
sith/composer.py Normal file
View File

@ -0,0 +1,26 @@
import os
import signal
import subprocess
import sys
import psutil
COMPOSER_PID = "COMPOSER_PID"
def start_composer(procfile: str):
"""Starts the composer and stores the PID as an environment variable
This allows for running smoothly with the django reloader
"""
process = subprocess.Popen(
[sys.executable, "-m", "honcho", "-f", procfile, "start"],
)
os.environ[COMPOSER_PID] = str(process.pid)
def stop_composer():
"""Stops the composer if it was started before"""
if (pid := os.environ.get(COMPOSER_PID, None)) is not None:
process = psutil.Process(int(pid))
process.send_signal(signal.SIGTERM)
process.wait()

View File

@ -1,4 +0,0 @@
from environs import Env
env = Env()
_ = env.read_env()

View File

@ -1,10 +1,8 @@
import pytest
from processes.composer import start_composer, stop_composer
from .composer import start_composer, stop_composer
from .settings import PROCFILE_PYTEST
from .environ import env
# pytest-django uses the load_initial_conftest hook
# it's the first hook loaded by pytest and can only
# be defined in a proper pytest plugin
# To use the composer before pytest-django loads
@ -15,8 +13,8 @@ from .environ import env
@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 := env.str("PROCFILE_PYTEST", None)) is not None:
start_composer(procfile)
if PROCFILE_PYTEST is not None:
start_composer(PROCFILE_PYTEST)
def pytest_unconfigure(config):

View File

@ -42,13 +42,20 @@ from pathlib import Path
import sentry_sdk
from dateutil.relativedelta import relativedelta
from django.utils.translation import gettext_lazy as _
from environs import Env
from sentry_sdk.integrations.django import DjangoIntegration
from .environ import env
from .honeypot import custom_honeypot_error
env = Env()
env.read_env()
BASE_DIR = Path(__file__).parent.parent.resolve()
# Composer settings
PROCFILE_RUNSERVER = env.str("PROCFILE_RUNSERVER", None)
PROCFILE_PYTEST = env.str("PROCFILE_PYTEST", None)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/