Skip to content

Commit

Permalink
Roll back the debug modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorescu committed Nov 26, 2024
1 parent cfc41b0 commit 6d3eafd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 56 deletions.
25 changes: 23 additions & 2 deletions config/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,31 @@
# TODO: from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application

from scram.utils import debug
from config import cfg

logger = logging.getLogger(__name__)
debug.setup(base_port=56730)

# Here we setup a debugger if this is desired. This obviously should not be run in production.
if cfg.debugger:
logger.info("Django is set to use a debugger. Provided debug mode: %s", cfg.debugger)
if cfg.debugger == "pycharm-pydevd":
logger.info("Entering debug mode for pycharm, make sure the debug server is running in PyCharm!")

import pydevd_pycharm

pydevd_pycharm.settrace("host.docker.internal", port=56783, stdoutToServer=True, stderrToServer=True)

logger.info("Debugger started.")
elif cfg.debugger == "debugpy":
logger.info("Entering debug mode for debugpy (VSCode)")

import debugpy

debugpy.listen(("0.0.0.0", 56780)) # noqa S104 (doesn't like binding to all interfaces)

logger.info("Debugger listening on port 56780.")
else:
logger.warning("Invalid debug mode given: %s. Debugger not started", cfg.debugger)

# This allows easy placement of apps within the interior
# scram directory.
Expand Down
52 changes: 0 additions & 52 deletions scram/utils/debug.py

This file was deleted.

49 changes: 47 additions & 2 deletions translator/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import websockets
from gobgp import GoBGP

from scram.utils import debug
from config import cfg

logger = logging.getLogger(__name__)
debug.setup(base_port=56732)

KNOWN_MESSAGES = {
"translator_add",
Expand All @@ -23,6 +22,52 @@
"translator_check",
}

# Here we setup a debugger if this is desired. This obviously should not be run in production.
if cfg.debugger:

def install_deps():
"""Install necessary dependencies for debuggers.
Because of how we build translator currently, we don't have a great way to selectively
install things at build, so we just do it here! Right now this also includes base.txt,
which is unecessary, but in the future when we build a little better, it'll already be
setup.
"""
logger.info("Installing dependencies for debuggers")

import subprocess # noqa: S404, PLC0415
import sys # noqa: PLC0415

subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "/requirements/local.txt"]) # noqa: S603 TODO: add this to the container build

logger.info("Done installing dependencies for debuggers")

logger.info("Translator is set to use a debugger. Provided debug mode: %s", cfg.debugger)
# We have to setup the debugger appropriately for various IDEs. It'd be nice if they all used the same thing but
# sadly, we live in a fallen world.
if cfg.debugger == "pycharm-pydevd":
logger.info("Entering debug mode for pycharm, make sure the debug server is running in PyCharm!")

install_deps()

import pydevd_pycharm

pydevd_pycharm.settrace("host.docker.internal", port=56782, stdoutToServer=True, stderrToServer=True)

logger.info("Debugger started.")
elif cfg.debugger == "debugpy":
logger.info("Entering debug mode for debugpy (VSCode)")

install_deps()

import debugpy

debugpy.listen(("0.0.0.0", 56781)) # noqa S104 (doesn't like binding to all interfaces)

logger.info("Debugger listening on port 56781.")
else:
logger.warning("Invalid debug mode given: %s. Debugger not started", cfg.debugger)

# Must match the URL in asgi.py, and needs a trailing slash
hostname = os.environ.get("SCRAM_HOSTNAME", "scram_hostname_not_set")
url = os.environ.get("SCRAM_EVENTS_URL", "ws://django:8000/ws/route_manager/translator_block/")
Expand Down

0 comments on commit 6d3eafd

Please sign in to comment.