Skip to content

runner

dev_tool.services.django.runner

log = logging.getLogger(__name__) module-attribute

ServerRunner

Bases: Protocol

A protocol for server runners.

run

A method that starts the server.

Source code in dev_tool/services/django/runner.py
def run(self) -> None:
    """A method that starts the server."""
    ...

stop

A method that stops the server.

Source code in dev_tool/services/django/runner.py
def stop(self) -> None:
    """A method that stops the server."""
    ...

DjangoServerRunner

Bases: BaseProcessRunner

A class for running a Django development server.

This class handles starting, monitoring, and stopping a Django server process in both local and containerized environments.

The constructor for the DjangoServerRunner class.

Parameters:

  • project_name (str) –

    The project name for container naming.

  • ip_address (str) –

    The IP address to bind to.

  • port (int) –

    The port number to bind to.

Source code in dev_tool/services/django/runner.py
def __init__(self, project_name: str, ip_address: str, port: int) -> None:
    """
    The constructor for the DjangoServerRunner class.

    :param project_name: The project name for container naming.
    :param ip_address: The IP address to bind to.
    :param port: The port number to bind to.
    """

    super().__init__(project_name=project_name)

    self.ip_address = ip_address
    self.port = port

ip_address = ip_address instance-attribute

port = port instance-attribute

GunicornServerRunner

Bases: BaseProcessRunner

A class for running a Gunicorn server inside a container.

This class handles starting, monitoring, and stopping a Gunicorn process using the project's gunicorn.conf.py configuration file. A temporary WSGI wrapper module is created in the container to serve static files via Django's StaticFilesHandler.

The constructor for the GunicornServerRunner class.

Parameters:

  • project_name (str) –

    The project name for container naming.

  • port (int) –

    The port number to bind to.

  • wsgi_app (str) –

    The WSGI application module path in gunicorn format.

  • wrapper_content (str) –

    The rendered WSGI wrapper module content.

Source code in dev_tool/services/django/runner.py
def __init__(self, project_name: str, port: int, wsgi_app: str, wrapper_content: str) -> None:
    """
    The constructor for the GunicornServerRunner class.

    :param project_name: The project name for container naming.
    :param port: The port number to bind to.
    :param wsgi_app: The WSGI application module path in gunicorn format.
    :param wrapper_content: The rendered WSGI wrapper module content.
    """

    super().__init__(project_name=project_name)

    self.port = port
    self.wrapper_content = wrapper_content
    self.wsgi_app = wsgi_app

WRAPPER_FILENAME = '_gunicorn_wsgi.py' class-attribute instance-attribute

WRAPPER_MODULE = '_gunicorn_wsgi:application' class-attribute instance-attribute

WRAPPER_PATH = f'/app/{WRAPPER_FILENAME}' class-attribute instance-attribute

port = port instance-attribute

wrapper_content = wrapper_content instance-attribute

wsgi_app = wsgi_app instance-attribute

run

A method that creates the WSGI wrapper and starts the subprocess.

Source code in dev_tool/services/django/runner.py
def run(self) -> None:
    """A method that creates the WSGI wrapper and starts the subprocess."""

    if not self._create_wsgi_wrapper():
        return

    super().run()

stop

A method that stops the subprocess and removes the WSGI wrapper.

Source code in dev_tool/services/django/runner.py
def stop(self) -> None:
    """A method that stops the subprocess and removes the WSGI wrapper."""

    super().stop()
    self._remove_wsgi_wrapper()