Skip to content

Commit 0ba6bfe

Browse files
authored
Merge branch 'main' into anthonykim1/cleanOld
2 parents 69569c3 + 23fdb5a commit 0ba6bfe

7 files changed

Lines changed: 50 additions & 16 deletions

File tree

src/features/envCommands.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,10 @@ export async function runInTerminalCommand(
574574
const project = api.getPythonProject(uri);
575575
const environment = await api.getEnvironment(uri);
576576
if (environment && project) {
577-
const terminal = await tm.getProjectTerminal(project, environment);
578-
await runInTerminal(environment, terminal, {
577+
const resolvedEnv = await api.resolveEnvironment(environment.environmentPath);
578+
const envFinal = resolvedEnv ?? environment;
579+
const terminal = await tm.getProjectTerminal(project, envFinal);
580+
await runInTerminal(envFinal, terminal, {
579581
cwd: project.uri,
580582
args: [item.fsPath],
581583
show: true,
@@ -594,9 +596,12 @@ export async function runInDedicatedTerminalCommand(
594596
const uri = item as Uri;
595597
const project = api.getPythonProject(uri);
596598
const environment = await api.getEnvironment(uri);
599+
597600
if (environment && project) {
598-
const terminal = await tm.getDedicatedTerminal(item, project, environment);
599-
await runInTerminal(environment, terminal, {
601+
const resolvedEnv = await api.resolveEnvironment(environment.environmentPath);
602+
const envFinal = resolvedEnv ?? environment;
603+
const terminal = await tm.getDedicatedTerminal(item, project, envFinal);
604+
await runInTerminal(envFinal, terminal, {
600605
cwd: project.uri,
601606
args: [item.fsPath],
602607
show: true,
@@ -612,8 +617,10 @@ export async function runAsTaskCommand(item: unknown, api: PythonEnvironmentApi)
612617
const project = api.getPythonProject(uri);
613618
const environment = await api.getEnvironment(uri);
614619
if (environment) {
620+
const resolvedEnv = await api.resolveEnvironment(environment.environmentPath);
621+
const envFinal = resolvedEnv ?? environment;
615622
return await runAsTask(
616-
environment,
623+
envFinal,
617624
{
618625
project,
619626
args: [item.fsPath],
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export function quoteArg(arg: string): string {
1+
export function quoteStringIfNecessary(arg: string): string {
22
if (arg.indexOf(' ') >= 0 && !(arg.startsWith('"') && arg.endsWith('"'))) {
33
return `"${arg}"`;
44
}
55
return arg;
66
}
77

88
export function quoteArgs(args: string[]): string[] {
9-
return args.map(quoteArg);
9+
return args.map(quoteStringIfNecessary);
1010
}

src/features/execution/runAsTask.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
WorkspaceFolder,
1010
} from 'vscode';
1111
import { PythonEnvironment, PythonTaskExecutionOptions } from '../../api';
12+
import { traceInfo, traceWarn } from '../../common/logging';
1213
import { executeTask } from '../../common/tasks.apis';
1314
import { getWorkspaceFolder } from '../../common/workspace.apis';
14-
import { quoteArg } from './execUtils';
15+
import { quoteStringIfNecessary } from './execUtils';
1516

1617
function getWorkspaceFolderOrDefault(uri?: Uri): WorkspaceFolder | TaskScope {
1718
const workspace = uri ? getWorkspaceFolder(uri) : undefined;
@@ -25,10 +26,17 @@ export async function runAsTask(
2526
): Promise<TaskExecution> {
2627
const workspace: WorkspaceFolder | TaskScope = getWorkspaceFolderOrDefault(options.project?.uri);
2728

28-
let executable = environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
29-
executable = quoteArg(executable);
29+
let executable = environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable;
30+
if (!executable) {
31+
traceWarn('No Python executable found in environment; falling back to "python".');
32+
executable = 'python';
33+
}
34+
// Check and quote the executable path if necessary
35+
executable = quoteStringIfNecessary(executable);
36+
3037
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
3138
const allArgs = [...args, ...options.args];
39+
traceInfo(`Running as task: ${executable} ${allArgs.join(' ')}`);
3240

3341
const task = new Task(
3442
{ type: 'python' },

src/features/execution/runInBackground.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import * as cp from 'child_process';
2-
import { PythonEnvironment, PythonBackgroundRunOptions, PythonProcess } from '../../api';
2+
import { PythonBackgroundRunOptions, PythonEnvironment, PythonProcess } from '../../api';
3+
import { traceError, traceInfo, traceWarn } from '../../common/logging';
4+
import { quoteStringIfNecessary } from './execUtils';
35

46
export async function runInBackground(
57
environment: PythonEnvironment,
68
options: PythonBackgroundRunOptions,
79
): Promise<PythonProcess> {
8-
const executable =
9-
environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
10+
let executable = environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable;
11+
if (!executable) {
12+
traceWarn('No Python executable found in environment; falling back to "python".');
13+
executable = 'python';
14+
}
15+
// Check and quote the executable path if necessary
16+
executable = quoteStringIfNecessary(executable);
1017
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
1118
const allArgs = [...args, ...options.args];
19+
traceInfo(`Running in background: ${executable} ${allArgs.join(' ')}`);
1220

1321
const proc = cp.spawn(executable, allArgs, { stdio: 'pipe', cwd: options.cwd, env: options.env });
1422

@@ -22,8 +30,17 @@ export async function runInBackground(
2230
proc.kill();
2331
}
2432
},
25-
onExit: (listener: (code: number | null, signal: NodeJS.Signals | null) => void) => {
26-
proc.on('exit', listener);
33+
onExit: (listener: (code: number | null, signal: NodeJS.Signals | null, error?: Error | null) => void) => {
34+
proc.on('exit', (code, signal) => {
35+
if (code && code !== 0) {
36+
traceError(`Process exited with error code: ${code}, signal: ${signal}`);
37+
}
38+
listener(code, signal, null);
39+
});
40+
proc.on('error', (error) => {
41+
traceError(`Process error: ${error?.message || error}${error?.stack ? '\n' + error.stack : ''}`);
42+
listener(null, null, error);
43+
});
2744
},
2845
};
2946
}

src/features/terminal/shells/bash/bashStartup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ async function isStartupSetup(profile: string, key: string): Promise<ShellSetupS
7171

7272
async function setupStartup(profile: string, key: string, name: string): Promise<boolean> {
7373
if (shellIntegrationForActiveTerminal(name, profile)) {
74+
removeStartup(profile, key);
7475
return true;
7576
}
7677
const activationContent = getActivationContent(key);
77-
7878
try {
7979
if (await fs.pathExists(profile)) {
8080
const content = await fs.readFile(profile, 'utf8');

src/features/terminal/shells/fish/fishStartup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async function isStartupSetup(profilePath: string, key: string): Promise<boolean
5959
async function setupStartup(profilePath: string, key: string): Promise<boolean> {
6060
try {
6161
if (shellIntegrationForActiveTerminal('fish', profilePath)) {
62+
removeFishStartup(profilePath, key);
6263
return true;
6364
}
6465
const activationContent = getActivationContent(key);

src/features/terminal/shells/pwsh/pwshStartup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ async function isPowerShellStartupSetup(shell: string, profile: string): Promise
146146

147147
async function setupPowerShellStartup(shell: string, profile: string): Promise<boolean> {
148148
if (shellIntegrationForActiveTerminal(shell, profile)) {
149+
removePowerShellStartup(shell, profile);
149150
return true;
150151
}
151152
const activationContent = getActivationContent();

0 commit comments

Comments
 (0)