Skip to content

Debugging DVC interactively

Saugat Pachhai edited this page Sep 29, 2021 · 5 revisions

While debugging DVC, being a command-line application, you may need to change the command quite often. This might need you to change the arguments repeatedly which is cumbersome. The following guide walks you through how to debug it interactively in VSCode with minimal effort.

Setting up configurations

  1. Install Python Extension for VSCode if you haven't already.
  2. Run pip install debugpy. Please understand that debugpy should be installed in the same environment as DVC is installed in.
  3. Open "Run and Debug" in the VSCode from the sidebar.
  4. Select "Python" and then "Remote Attach".
  5. Enter the hostname as it is (i.e. "localhost") and then set the port.

This should create a .vscode/launch.json file similar to the following.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        }
    ]
}

Debugging

  1. Set the breakpoints you want. If you are unsure where to set, set it at the top-level with the command-runner.

  2. Run the command that you want to debug in the terminal (any terminal, not just vscode :) ).

    python -m debugpy --wait-for-client --listen {port} -m dvc {command} 

    eg: for debugging dvc push and debugger running in port 5678:

    python -m debugpy --wait-for-client --listen 5678 -m dvc push

    It won't start running till we start the debugger.

  3. From the "Run and Debug", run the appropriate debugger config ("Python: Remote Attach" in above).

Happy debugging!!!

Clone this wiki locally