Run bundler through honcho

This commit is contained in:
Antoine Bartuccio 2025-02-15 12:15:08 +01:00
parent 2c9b72fe1d
commit 8528820d89
5 changed files with 25 additions and 11 deletions

1
Procfile Normal file
View File

@ -0,0 +1 @@
bundler: npm run serve

View File

@ -47,6 +47,7 @@ dependencies = [
"redis[hiredis]<6.0.0,>=5.2.0", "redis[hiredis]<6.0.0,>=5.2.0",
"environs[django]<15.0.0,>=14.1.0", "environs[django]<15.0.0,>=14.1.0",
"requests>=2.32.3", "requests>=2.32.3",
"honcho>=2.0.0",
] ]
[project.urls] [project.urls]

View File

@ -1,4 +1,7 @@
import logging
import os import os
import subprocess
import sys
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.management.commands.runserver import ( from django.contrib.staticfiles.management.commands.runserver import (
@ -6,7 +9,7 @@ from django.contrib.staticfiles.management.commands.runserver import (
) )
from django.utils.autoreload import DJANGO_AUTORELOAD_ENV from django.utils.autoreload import DJANGO_AUTORELOAD_ENV
from staticfiles.processors import JSBundler, OpenApi from staticfiles.processors import OpenApi
class Command(Runserver): class Command(Runserver):
@ -15,10 +18,11 @@ class Command(Runserver):
def run(self, **options): def run(self, **options):
# OpenApi generation needs to be before the bundler # OpenApi generation needs to be before the bundler
OpenApi.compile() OpenApi.compile()
# Only run the bundling server when debug is enabled # Run all other web processes but only if debug mode is enabled
# Also protects from re-launching the server if django reloads it # Also protects from re-launching the server if django reloads it
if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and settings.DEBUG: if os.environ.get(DJANGO_AUTORELOAD_ENV) is None and settings.DEBUG:
with JSBundler.runserver(): logging.getLogger("django").info("Running complementary processes")
with subprocess.Popen([sys.executable, "-m", "honcho", "start"]):
super().run(**options) super().run(**options)
return return
super().run(**options) super().run(**options)

View File

@ -99,12 +99,6 @@ class JSBundler:
if process.returncode: if process.returncode:
raise RuntimeError(f"Bundler failed with returncode {process.returncode}") raise RuntimeError(f"Bundler failed with returncode {process.returncode}")
@staticmethod
def runserver() -> subprocess.Popen:
"""Bundle js files automatically in background when called in debug mode."""
logging.getLogger("django").info("Running javascript bundling server")
return subprocess.Popen(["npm", "run", "serve"])
@staticmethod @staticmethod
def get_manifest() -> JSBundlerManifest: def get_manifest() -> JSBundlerManifest:
return JSBundlerManifest(BUNDLED_ROOT / ".vite" / "manifest.json") return JSBundlerManifest(BUNDLED_ROOT / ".vite" / "manifest.json")

18
uv.lock generated
View File

@ -155,7 +155,7 @@ name = "click"
version = "8.1.8" version = "8.1.8"
source = { registry = "https://pypi.org/simple" } source = { registry = "https://pypi.org/simple" }
dependencies = [ dependencies = [
{ name = "colorama", marker = "platform_system == 'Windows'" }, { name = "colorama", marker = "sys_platform == 'win32'" },
] ]
sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 } sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 }
wheels = [ wheels = [
@ -595,6 +595,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/cc/04/eaa88433249ddfc282018d3da4198d0b0018e48768e137bfad304aacb1ec/hiredis-3.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:9020fd7e58f489fda6a928c31355add0e665fd6b87b21954e675cf9943eafa32", size = 22004 }, { url = "https://files.pythonhosted.org/packages/cc/04/eaa88433249ddfc282018d3da4198d0b0018e48768e137bfad304aacb1ec/hiredis-3.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:9020fd7e58f489fda6a928c31355add0e665fd6b87b21954e675cf9943eafa32", size = 22004 },
] ]
[[package]]
name = "honcho"
version = "2.0.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "colorama", marker = "sys_platform == 'win32'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/65/c8/d860888358bf5c8a6e7d78d1b508b59b0e255afd5655f243b8f65166dafd/honcho-2.0.0.tar.gz", hash = "sha256:af3815c03c634bf67d50f114253ea9fef72ecff26e4fd06b29234789ac5b8b2e", size = 45618 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/48/1c/25631fc359955569e63f5446dbb7022c320edf9846cbe892ee5113433a7e/honcho-2.0.0-py3-none-any.whl", hash = "sha256:56dcd04fc72d362a4befb9303b1a1a812cba5da283526fbc6509be122918ddf3", size = 22093 },
]
[[package]] [[package]]
name = "ical" name = "ical"
version = "8.3.1" version = "8.3.1"
@ -807,7 +819,7 @@ version = "1.6.1"
source = { registry = "https://pypi.org/simple" } source = { registry = "https://pypi.org/simple" }
dependencies = [ dependencies = [
{ name = "click" }, { name = "click" },
{ name = "colorama", marker = "platform_system == 'Windows'" }, { name = "colorama", marker = "sys_platform == 'win32'" },
{ name = "ghp-import" }, { name = "ghp-import" },
{ name = "jinja2" }, { name = "jinja2" },
{ name = "markdown" }, { name = "markdown" },
@ -1501,6 +1513,7 @@ dependencies = [
{ name = "django-phonenumber-field" }, { name = "django-phonenumber-field" },
{ name = "django-simple-captcha" }, { name = "django-simple-captcha" },
{ name = "environs", extra = ["django"] }, { name = "environs", extra = ["django"] },
{ name = "honcho" },
{ name = "ical" }, { name = "ical" },
{ name = "jinja2" }, { name = "jinja2" },
{ name = "libsass" }, { name = "libsass" },
@ -1561,6 +1574,7 @@ requires-dist = [
{ name = "django-phonenumber-field", specifier = ">=8.0.0,<9.0.0" }, { name = "django-phonenumber-field", specifier = ">=8.0.0,<9.0.0" },
{ name = "django-simple-captcha", specifier = ">=0.6.0,<1.0.0" }, { name = "django-simple-captcha", specifier = ">=0.6.0,<1.0.0" },
{ name = "environs", extras = ["django"], specifier = ">=14.1.0,<15.0.0" }, { name = "environs", extras = ["django"], specifier = ">=14.1.0,<15.0.0" },
{ name = "honcho", specifier = ">=2.0.0" },
{ name = "ical", specifier = ">=8.3.0,<9.0.0" }, { name = "ical", specifier = ">=8.3.0,<9.0.0" },
{ name = "jinja2", specifier = ">=3.1.4,<4.0.0" }, { name = "jinja2", specifier = ">=3.1.4,<4.0.0" },
{ name = "libsass", specifier = ">=0.23.0,<1.0.0" }, { name = "libsass", specifier = ">=0.23.0,<1.0.0" },