Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Vs code version 2.0.0 Build Task for python

I need help in configuring my Vs code to run scripts in python using Cntrl Shift B, I was working fine until Vs code upgraded to version 2.0.0 now it wants me to configure the Build. And I am clueless what Build is all about.

In the past it worked well when I only needed to configure the task runner. There are youtube videos for the task runner. I cant seem to lay my finger on what the Build is all about.

like image 586
Tungata Avatar asked Nov 27 '22 20:11

Tungata


1 Answers

In VS Code go Tasks -> Configure Tasks

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Run File",
            "command": "python ${file}",
            "type": "shell",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "new",
                "focus": true
            }
        },
        {
            "taskName": "nosetest",
            "command": "nosetests -v",
            "type": "shell",
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "new",
                "focus": true
            }
        }
    ]
}

command: runs current python file

group: 'build'

presentation:

  • always shows the shell when run
  • uses a new shell
  • focuses the shell (i.e. keyboard is captured in shell window)

2nd Task is configured as the default test and just runs nosetest -v in the folder that's currently open in VS Code.

The "Run Build Task" (the one that's bound to Ctrl+Shift+B) is the one that's configured as the default build task, task 1 in this example (see the group entry).

EDIT:
Suggested by @RafaelZayas in the comments (this will use the Python interpreter that's specified in VS Code's settings rather than the system default; see his comment for more info):

"command": "${command:python.interpreterPath} ${file}"

like image 129
orangeInk Avatar answered Jan 03 '23 22:01

orangeInk