"""cPanel / Passenger WSGI entry point.

Loads Django's WSGI application straight from core/wsgi.py by file path — the
pattern cPanel's "Setup Python App" generates — so it does not depend on
cPanel's auto-generated stub correctly guessing the project package name.
"""
import importlib.machinery
import importlib.util
import os
import sys

APP_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, APP_DIR)

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')


def load_source(modname, filename):
    loader = importlib.machinery.SourceFileLoader(modname, filename)
    spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
    module = importlib.util.module_from_spec(spec)
    loader.exec_module(module)
    return module


wsgi = load_source('wsgi', os.path.join(APP_DIR, 'core', 'wsgi.py'))
application = wsgi.application
