Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/common/childProcess.apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ export function spawnProcess(
args: string[],
options?: cp.SpawnOptions,
): cp.ChildProcess | cp.ChildProcessWithoutNullStreams {
return cp.spawn(command, args, options ?? {});
// Set PYTHONUTF8=1; user-provided PYTHONUTF8 values take precedence.
const env = {
PYTHONUTF8: '1',
...(options?.env ?? process.env),
};
return cp.spawn(command, args, { ...options, env });
}
4 changes: 2 additions & 2 deletions src/managers/common/nativePythonFinder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as ch from 'child_process';
import * as fs from 'fs-extra';
import * as path from 'path';
import { PassThrough } from 'stream';
import { Disposable, ExtensionContext, LogOutputChannel, Uri } from 'vscode';
import * as rpc from 'vscode-jsonrpc/node';
import { PythonProjectApi } from '../../api';
import { spawnProcess } from '../../common/childProcess.apis';
import { ENVS_EXTENSION_ID, PYTHON_EXTENSION_ID } from '../../common/constants';
import { getExtension } from '../../common/extension.apis';
import { traceError, traceLog, traceVerbose, traceWarn } from '../../common/logging';
Expand Down Expand Up @@ -213,7 +213,7 @@ class NativePythonFinderImpl implements NativePythonFinder {
const writable = new PassThrough();
const disposables: Disposable[] = [];
try {
const proc = ch.spawn(this.toolPath, ['server'], { env: process.env });
const proc = spawnProcess(this.toolPath, ['server'], { env: process.env, stdio: 'pipe' });
proc.stdout.pipe(readable, { end: false });
proc.stderr.on('data', (data) => this.outputChannel.error(`[pet] ${data.toString()}`));
writable.pipe(proc.stdin, { end: false });
Expand Down
4 changes: 2 additions & 2 deletions src/managers/conda/condaUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ch from 'child_process';
import * as fse from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
Expand All @@ -25,6 +24,7 @@ import {
PythonEnvironmentInfo,
PythonProject,
} from '../../api';
import { spawnProcess } from '../../common/childProcess.apis';
import { ENVS_EXTENSION_ID, EXTENSION_ROOT_DIR } from '../../common/constants';
import { showErrorMessageWithLogs } from '../../common/errors/utils';
import { Common, CondaStrings, PackageManagement, Pickers } from '../../common/localize';
Expand Down Expand Up @@ -206,7 +206,7 @@ async function _runConda(
const quotedConda = quoteStringIfNecessary(conda);
const timer = new StopWatch();
deferred.promise.finally(() => traceInfo(`Ran conda in ${timer.elapsedTime}: ${quotedConda} ${args.join(' ')}`));
const proc = ch.spawn(quotedConda, args, { shell: true });
const proc = spawnProcess(quotedConda, args, { shell: true });

token?.onCancellationRequested(() => {
proc.kill();
Expand Down
4 changes: 2 additions & 2 deletions src/managers/poetry/poetryPackageManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ch from 'child_process';
import * as fsapi from 'fs-extra';
import * as path from 'path';
import {
Expand All @@ -22,6 +21,7 @@ import {
PythonEnvironment,
PythonEnvironmentApi,
} from '../../api';
import { spawnProcess } from '../../common/childProcess.apis';
import { showErrorMessage, showInputBox, withProgress } from '../../common/window.apis';
import { PoetryManager } from './poetryManager';
import { getPoetry } from './poetryUtils';
Expand Down Expand Up @@ -271,7 +271,7 @@ export async function runPoetry(
log?.info(`Running: ${poetry} ${args.join(' ')}`);

return new Promise<string>((resolve, reject) => {
const proc = ch.spawn(poetry, args, { cwd });
const proc = spawnProcess(poetry, args, { cwd });
token?.onCancellationRequested(() => {
proc.kill();
reject(new CancellationError());
Expand Down