35 lines
1.1 KiB
Python
Raw Normal View History

2025-02-15 12:15:08 +01:00
import logging
import os
2025-02-15 12:15:08 +01:00
import subprocess
import sys
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
class Command(Runserver):
"""Light wrapper around default runserver that integrates javascirpt auto bundling."""
def run(self, **options):
# OpenApi generation needs to be before the bundler
OpenApi.compile()
2025-02-15 12:15:08 +01:00
# Run all other web processes but only if debug mode is enabled
# 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"},
},
):
super().run(**options)
return
super().run(**options)