Python tasks #9834
Replies: 6 comments 18 replies
-
Beta Was this translation helpful? Give feedback.
-
I wrote a Nu task to initialize a Python project. It create a
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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"
}
}
] |
Beta Was this translation helpful? Give feedback.
-
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
} |
Beta Was this translation helpful? Give feedback.
-
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
}
|
Beta Was this translation helpful? Give feedback.
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.json
file. Swap outpython3
for whatever interpreter/alias you are using. Usetasks: spawn
in the command palette to pick a task and then relaunch the same task viaopt-t
(task: rerun
).Executing code
Managing venvs (utilizing
uv
)For more general info on tasks, see the docs.
Beta Was this translation helpful? Give feedback.
All reactions