Skip to content

Commit

Permalink
runserver
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Nov 3, 2022
1 parent 0c007f7 commit dbef190
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/whitenoise/runserver_nostatic/management/commands/runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@
"""
from __future__ import annotations

import argparse
from importlib import import_module
from typing import Generator

from django.apps import apps
from django.core.management import BaseCommand


def get_next_runserver_command():
def get_next_runserver_command() -> type[BaseCommand]:
"""
Return the next highest priority "runserver" command class
"""
for app_name in get_lower_priority_apps():
module_path = "%s.management.commands.runserver" % app_name
try:
return import_module(module_path).Command
klass: type[BaseCommand] = import_module(module_path).Command
return klass
except (ImportError, AttributeError):
pass
raise ValueError("No lower priority app has a 'runserver' command")


def get_lower_priority_apps():
def get_lower_priority_apps() -> Generator[str, None, None]:
"""
Yield all app module names below the current app in the INSTALLED_APPS list
"""
Expand All @@ -42,11 +47,12 @@ def get_lower_priority_apps():
RunserverCommand = get_next_runserver_command()


class Command(RunserverCommand):
def add_arguments(self, parser):
class Command(RunserverCommand): # type: ignore [misc,valid-type]
def add_arguments(self, parser: argparse.ArgumentParser) -> None:
super().add_arguments(parser)
if parser.get_default("use_static_handler") is True:
parser.set_defaults(use_static_handler=False)
assert parser.description is not None
parser.description += (
"\n(Wrapped by 'whitenoise.runserver_nostatic' to always"
" enable '--nostatic')"
Expand Down

0 comments on commit dbef190

Please sign in to comment.