Repository navigation
feat: add python.terminal.commandPrefix setting for custom file runners - #26321
Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
With Python Environments enabled, unescaped shell substitutions in script filenames can execute unintended commands rather than pass the filename literally.
4 open issues
What changed in this PR
Adds python.terminal.commandPrefix so Run Python File and the editor Play button can use custom runners such as uv run, addressing #26319 while preserving interpreter execution when the setting is empty.
Changes:
- Defines a resource-scoped runner-prefix setting with an empty default.
- Adds prefix normalization and execution routing, including when Python Environments is enabled.
- Adds unit tests for custom prefixes, whitespace handling, interpreter fallback, and execution delegation.
| File | Description |
|---|---|
src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts |
Tests custom runners, normalization, and fallback. |
src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts |
Tests delegation when a prefix is configured. |
src/client/terminals/codeExecution/terminalCodeExecution.ts |
Normalizes prefixes and builds custom-runner commands. |
src/client/terminals/codeExecution/codeExecutionManager.ts |
Routes configured runners through the standard execution service. |
src/client/common/types.ts |
Adds the optional terminal prefix property. |
src/client/common/configSettings.ts |
Initializes the fallback prefix to an empty array. |
package.nls.json |
Adds the setting’s localized description. |
package.json |
Registers the resource-scoped string-array setting. |
Review effort: Balanced
| ICodeExecutionService, | ||
| 'standard', | ||
| ); | ||
| await executionService.executeFile(fileToExecute, { newTerminalPerFile: dedicated }); |
|
|
||
| // Check on setting terminal.executeInFileDir | ||
| // Check on setting terminal.commandPrefix | ||
| const pythonSettings = this.configSettings.getSettings(file); |
| ICodeExecutionService, | ||
| 'standard', | ||
| ); | ||
| await executionService.executeFile(fileToExecute, { newTerminalPerFile: dedicated }); |
| ICodeExecutionService, | ||
| 'standard', | ||
| ); | ||
| await executionService.executeFile(fileToExecute, { newTerminalPerFile: dedicated }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes #26319
Summary
Adds the
python.terminal.commandPrefixresource-scoped setting (default[]) so users can configure a custom runner prefix such as["uv", "run"]or["poetry", "run"]when executing Python files via the Run Python File command / Play button.Changes
package.json&package.nls.json: Addedpython.terminal.commandPrefix(string[], resource-scoped) and its localization description.src/client/common/types.ts&src/client/common/configSettings.ts: AddedcommandPrefix?: string[]toITerminalSettingsand fallback initialization.src/client/terminals/codeExecution/terminalCodeExecution.ts: AddedgetNormalizedCommandPrefix()and updatedTerminalCodeExecutionProvider.getExecuteFileArgs()to invoke the configured runner prefix (followed byterminal.launchArgsand the target file) when non-empty, falling back to the active Python interpreter when unset or blank.src/client/terminals/codeExecution/codeExecutionManager.ts: UpdatedCodeExecutionManager.executeUsingExtension()to delegate to the standardICodeExecutionServicewhenpython.terminal.commandPrefixis configured so custom runners also work when the Python Environments extension is enabled.terminalCodeExec.unit.test.tsandcodeExecutionManager.unit.test.ts.Verification
npx tsc -p tsconfig.json: passed (0 errors)npx eslinton all modified TS files: passed (0 errors)npx mocha --require out/test/unittests.js --ui tdd --timeout 180000 out/test/terminals/codeExecution/terminalCodeExec.unit.test.js out/test/terminals/codeExecution/codeExecutionManager.unit.test.js: 113 passing (113/113)