2025-02-15 12:15:08 +01:00
|
|
|
import logging
|
2024-09-17 23:42:05 +02:00
|
|
|
import os
|
2025-02-15 12:15:08 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2024-09-17 23:42:05 +02:00
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
from django.contrib.staticfiles.management.commands.runserver import (
|
|
|
|
Command as Runserver,
|
|
|
|
)
|
|
|
|
from django.utils.autoreload import DJANGO_AUTORELOAD_ENV
|
|
|
|
|
2025-02-15 12:15:08 +01:00
|
|
|
from staticfiles.processors import OpenApi
|
2024-09-17 23:42:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Command(Runserver):
|
2024-11-18 15:36:05 +01:00
|
|
|
"""Light wrapper around default runserver that integrates javascirpt auto bundling."""
|
2024-09-17 23:42:05 +02:00
|
|
|
|
|
|
|
def run(self, **options):
|
2024-11-18 15:36:05 +01:00
|
|
|
# OpenApi generation needs to be before the bundler
|
2024-10-09 16:28:54 +02:00
|
|
|
OpenApi.compile()
|
2025-02-15 12:15:08 +01:00
|
|
|
# Run all other web processes but only if debug mode is enabled
|
2024-09-17 23:42:05 +02:00
|
|
|
# Also protects from re-launching the server if django reloads it
|
2025-02-15 17:58:07 +01:00
|
|
|
if os.environ.get(DJANGO_AUTORELOAD_ENV) is None:
|
2025-02-15 12:15:08 +01:00
|
|
|
logging.getLogger("django").info("Running complementary processes")
|
2025-02-15 17:58:07 +01:00
|
|
|
with subprocess.Popen(
|
|
|
|
[sys.executable, "-m", "honcho", "start"],
|
|
|
|
env={
|
|
|
|
**os.environ,
|
|
|
|
**{"BUNDLER_MODE": "serve" if settings.DEBUG else "compile"},
|
|
|
|
},
|
|
|
|
):
|
2024-09-17 23:42:05 +02:00
|
|
|
super().run(**options)
|
|
|
|
return
|
|
|
|
super().run(**options)
|