mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Apply review comments
This commit is contained in:
26
sith/composer.py
Normal file
26
sith/composer.py
Normal 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()
|
@ -1,4 +0,0 @@
|
||||
from environs import Env
|
||||
|
||||
env = Env()
|
||||
_ = env.read_env()
|
@ -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):
|
||||
|
@ -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/
|
||||
|
||||
|
Reference in New Issue
Block a user