-
Notifications
You must be signed in to change notification settings - Fork 22
Improve shell command formatting #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
} from './common/window.apis'; | ||
import { getConfiguration } from './common/workspace.apis'; | ||
import { createManagerReady } from './features/common/managerReady'; | ||
import { identifyTerminalShell } from './features/common/shellDetector'; | ||
import { AutoFindProjects } from './features/creators/autoFindProjects'; | ||
import { ExistingProjects } from './features/creators/existingProjects'; | ||
import { NewPackageProject } from './features/creators/newPackageProject'; | ||
|
@@ -49,7 +50,7 @@ import { PythonProjectManagerImpl } from './features/projectManager'; | |
import { getPythonApi, setPythonApi } from './features/pythonApi'; | ||
import { registerCompletionProvider } from './features/settings/settingCompletions'; | ||
import { setActivateMenuButtonContext } from './features/terminal/activateMenuButton'; | ||
import { normalizeShellPath } from './features/terminal/shells/common/shellUtils'; | ||
import { getShellCommandAsString, normalizeShellPath } from './features/terminal/shells/common/shellUtils'; | ||
import { | ||
clearShellProfileCache, | ||
createShellEnvProviders, | ||
|
@@ -435,6 +436,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron | |
commands.registerCommand('python-envs.runPetInTerminal', async () => { | ||
try { | ||
const petPath = await getNativePythonToolsPath(); | ||
let command: { subcommand: string; args?: string[] } | undefined; | ||
|
||
// Show quick pick menu for PET operation selection | ||
const selectedOption = await window.showQuickPick( | ||
|
@@ -467,8 +469,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron | |
|
||
if (selectedOption.label === 'Find All Environments') { | ||
// Run pet find --verbose | ||
terminal.sendText(`"${petPath}" find --verbose`, true); | ||
traceInfo(`Running PET find command: ${petPath} find --verbose`); | ||
command = { subcommand: 'find', args: ['--verbose'] }; | ||
} else if (selectedOption.label === 'Resolve Environment...') { | ||
// Show input box for path | ||
const placeholder = isWindows() ? 'C:\\path\\to\\python\\executable' : '/path/to/python/executable'; | ||
|
@@ -489,8 +490,15 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron | |
} | ||
|
||
// Run pet resolve with the provided path | ||
terminal.sendText(`"${petPath}" resolve "${inputPath.trim()}"`, true); | ||
traceInfo(`Running PET resolve command: ${petPath} resolve "${inputPath.trim()}"`); | ||
command = { subcommand: 'resolve', args: [inputPath.trim()] }; | ||
} | ||
|
||
if (command) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See reply to previous comment. |
||
const execString = getShellCommandAsString(identifyTerminalShell(terminal), [ | ||
{ executable: petPath, args: [command.subcommand, ...(command.args || [])] }, | ||
]); | ||
terminal.sendText(execString); | ||
traceInfo(`Running PET ${command.subcommand} command: ${execString}`); | ||
} | ||
} catch (error) { | ||
traceError('Error running PET in terminal', error); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||||||
export function quoteStringIfNecessary(arg: string): string { | ||||||||||||||||||||||||||||||||
arg = arg.trim(); | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if we really need this. Seems like the only places we call this are: vscode-python-environments/src/features/execution/runAsTask.ts Lines 29 to 35 in e0eedd3
and vscode-python-environments/src/features/execution/runInBackground.ts Lines 10 to 16 in e0eedd3
And the executable string that is passed in seems like its path to Python binary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here: vscode-python-environments/src/extension.ts Line 492 in e0eedd3
|
||||||||||||||||||||||||||||||||
if (arg.indexOf(' ') >= 0 && !(arg.startsWith('"') && arg.endsWith('"'))) { | ||||||||||||||||||||||||||||||||
return `"${arg}"`; | ||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Looks like command will never be undefined here, we could probably remove the
| undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined
is required here since theif ... else
tests onselectedOption.label
below don't have a defaultelse
, therefore the ts compiler will complain withts(2454)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm thinking can we just simplify the second
else if (...Resolve Environment)
intoelse
?There is only two options that
selectionOption.label
can take.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true but I didn't want to introduce any unrelated changes with possibly undesirable effects, keeping the PR context relevant and minimal. Should I still change it?