feature: cd around as needed to import our ASGI application properly

This commit is contained in:
Ash Plunkett 2023-03-21 10:32:49 +11:00
parent 91565d014b
commit 7ef8d12e3c

View File

@ -1,5 +1,6 @@
import argparse
import logging
import os
import sys
from argparse import ArgumentError, Namespace
@ -228,11 +229,24 @@ class CommandLineInterface:
elif args.verbosity >= 1:
access_log_stream = sys.stdout
# ----- Custom fork code start -----
# default directory on Heroku is /app/, but we want to import the application from within /app/django-root/
original_working_dir = os.getcwd()
os.chdir("django-root")
sys.path.insert(0, os.getcwd())
# ----- Custom fork code end -----
# Import application
sys.path.insert(0, ".")
# sys.path.insert(0, ".") # Custom fork: commented out this line, moved to below
application = import_by_path(args.application)
application = guarantee_single_callable(application)
# ----- Custom fork code start -----
# Change back out of django-root so that everything else runs as daphne expects
os.chdir(original_working_dir)
sys.path.insert(0, ".")
# ----- Custom fork code end -----
# Set up port/host bindings
if not any(
[