jxramos
jxramos

Reputation: 8266

How to specify startup file in VSCode Python Extension

In Visual Studio's Python Tools for Visual Studio (url) when you have a Python project file there's this notion of a Startup File.

Each Python project has one assigned start-up file, shown in boldface in Solution Explorer. The startup file is the file that's run when you start debugging (F5 or Debug > Start Debugging) or when you run your project in the Interactive window (Shift+Alt+F5 or Debug > Execute Project in Python Interactive). To change it, right-click the new file and select Set as Startup File. Solution Explorer showing Startup File

What's the equivalent in VSCode's Python Extension? How to I target a specific file in my directory to run with the current debug settings selected from my launch.json file

Upvotes: 8

Views: 6208

Answers (1)

jxramos
jxramos

Reputation: 8266

Turns out it's the program attribute.

program - executable or file to run when launching the debugger https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes

As an example...

{
    "name": "python launch foo",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}/d1/d2/foo.py",
    "cwd": "${workspaceFolder}",
    "args": [ "${env:USERNAME}", "--optionX", "x1000" ]
    "console": "integratedTerminal"
}

Previously I was just duplicating launch configs with the default file variable which would always just run whatever active file was open in the workspace.

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "cwd": "${workspaceFolder}",
}

Upvotes: 4

Related Questions