"""Run this inside interactive Maya (Script Editor, Python tab) to enable
the "Maya: Attach (debugpy)" launch config in .vscode/launch.json.

debugpy is bundled in ../python/ -- no separate pip install needed. Each
Maya session, before attaching from VS Code, run:

    exec(open(r"C:\\workspace\\PoseRenderer\\scripts\\start_debug_server.py").read())

Breakpoints hit in plug-ins/ or python/openpose_renderer/ (e.g. inside
draw_override.py's prepareForDraw, or a command's doIt) will then pause in
VS Code once you run "Maya: Attach (debugpy)".
"""

import sys

# Run via exec(open(path).read()) per the docstring above, so __file__ is
# not defined here (same pitfall as Maya's own .py plugin loader) -- the
# project's python/ dir is hardcoded to match where the exec() call above
# already points. Adjust this if your checkout lives somewhere else.
_PYTHON_DIR = r"C:\workspace\PoseRenderer\python"
if _PYTHON_DIR not in sys.path:
    sys.path.insert(0, _PYTHON_DIR)

import debugpy

_ALREADY_LISTENING_ATTR = "_openpose_renderer_debugpy_listening"

if not getattr(debugpy, _ALREADY_LISTENING_ATTR, False):
    debugpy.listen(("localhost", 5678))
    setattr(debugpy, _ALREADY_LISTENING_ATTR, True)
    print("[openpose_renderer] debugpy listening on localhost:5678 -- "
          "run 'Maya: Attach (debugpy)' in VS Code to connect.")
else:
    print("[openpose_renderer] debugpy already listening on localhost:5678.")
