Python tasks #9834
Replies: 6 comments 18 replies
|
I wrote a Nu task to initialize a Python project. It create a |
|
I am trying this with a simple java file, swapping python3 with java. It works in the terminal but the same command doesn't work with the task runner. Even though there is a The problem seems to be that with |
|
Some more useful tasks: [
// run python file using uv
{
"label": "Run File: $ZED_FILENAME",
"command": "uv run $ZED_FILENAME"
},
// run selected code using uv
{
"label": "Run Code",
"command": "cat <<'EOF' > temp_run.py\n$ZED_SELECTED_TEXT\nEOF\nuv run temp_run.py && rm temp_run.py"
},
// push config to github
{
"label": "Push Config",
"command": "cd ~/.config/zed && git add . && git commit -m 'Update Config' && git push"
}
]The keymap: [
{
"context": "Workspace",
"bindings": {
"f4": ["task::Spawn", { "task_name": "Run Code" }],
"f5": ["task::Spawn", { "task_name": "Run File: $ZED_FILENAME" }],
"f7": "task::Spawn",
"f6": "task::Rerun"
}
}
] |
|
This gets you pretty close to VS Code's "Python: Run Python File" command. Keybinding: {
"context": "Editor && mode == full && !(ContextEditor > Editor) || Terminal",
"use_key_equivalents": true,
"bindings": {
"cmd-r": ["task::Spawn", { "task_name": "Python: $ZED_STEM" }]
}
}Task: {
"label": "Python: $ZED_STEM",
"command": "python3",
"args": ["$ZED_FILE"],
"allow_concurrent_runs": true
} |
|
If you want to run with a venv python, this may be useful. {
"label": "Python: Run File",
"command": "source $ZED_WORKTREE_ROOT/.venv/bin/activate; python3 || python3",
"args": ["$ZED_FILE"],
"use_new_terminal": false
},
{
"label": "Python: Run Selection",
"command": "source $ZED_WORKTREE_ROOT/.venv/bin/activate; python3 || python3",
"args": ["-c", "\"$ZED_SELECTED_TEXT\""],
"use_new_terminal": false
}
|









Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
A couple of simple tasks to enable faster python execution. Add these to your
tasks.jsonfile. Swap outpython3for whatever interpreter/alias you are using. Usetasks: spawnin the command palette to pick a task and then relaunch the same task viaopt-t(task: rerun).Executing code
{ "label": "Run python selection", "command": "python3", "args": ["-c", "\"$ZED_SELECTED_TEXT\""], "use_new_terminal": false },{ "label": "Run python file", "command": "python3", "args": ["$ZED_FILE"], "use_new_terminal": false }Managing venvs (utilizing
uv){ "label": "Create venv", "command": "uv", "args": ["venv", "$ZED_WORKTREE_ROOT/.venv"], "use_new_terminal": false },{ "label": "Delete venv", "command": "rm", "args": ["-rf", "$ZED_WORKTREE_ROOT/.venv"], "use_new_terminal": false }For more general info on tasks, see the docs.
All reactions