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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { lt, parse, SemVer } from 'semver';
import { getEnvironmentVariable, getOSType, getUserHomeDir, OSType } from '../../../common/utils/platform';
import {
arePathsSame,
exec,
getPythonSetting,
isParentPath,
pathExists,
Expand Down Expand Up @@ -390,7 +389,9 @@ export class Conda {
@cache(30_000, true, 10_000)
// eslint-disable-next-line class-methods-use-this
private async getInfoCached(command: string): Promise<CondaInfo> {
const result = await exec(command, ['info', '--json'], { timeout: CONDA_GENERAL_TIMEOUT });
const quoted = [command.toCommandArgument(), 'info', '--json'].join(' ');
// Execute in a shell as `conda` on windows refers to `conda.bat`, which requires a shell to work.
const result = await shellExecute(quoted, { timeout: CONDA_GENERAL_TIMEOUT });
traceVerbose(`conda info --json: ${result.stdout}`);
return JSON.parse(result.stdout);
}
Expand Down Expand Up @@ -491,7 +492,9 @@ export class Conda {
if (info && info.conda_version) {
versionString = info.conda_version;
} else {
const stdOut = await exec(this.command, ['--version'], { timeout: CONDA_GENERAL_TIMEOUT })
const quoted = `${this.command.toCommandArgument()} --version`;
// Execute in a shell as `conda` on windows refers to `conda.bat`, which requires a shell to work.
const stdOut = await shellExecute(quoted, { timeout: CONDA_GENERAL_TIMEOUT })
.then((result) => result.stdout.trim())
.catch<string | undefined>(() => undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ suite('Resolver Utils', () => {

test('resolveEnv (Windows)', async () => {
sinon.stub(platformApis, 'getOSType').callsFake(() => platformApis.OSType.Windows);
sinon.stub(externalDependencies, 'exec').callsFake(async (command: string, args: string[]) => {
sinon.stub(externalDependencies, 'shellExecute').callsFake(async (quoted: string) => {
const [command, ...args] = quoted.split(' ');
if (command === 'conda' && args[0] === 'info' && args[1] === '--json') {
return { stdout: JSON.stringify(condaInfo(condaPrefixWindows)) };
}
Expand All @@ -262,7 +263,8 @@ suite('Resolver Utils', () => {

test('resolveEnv (non-Windows)', async () => {
sinon.stub(platformApis, 'getOSType').callsFake(() => platformApis.OSType.Linux);
sinon.stub(externalDependencies, 'exec').callsFake(async (command: string, args: string[]) => {
sinon.stub(externalDependencies, 'shellExecute').callsFake(async (quoted: string) => {
const [command, ...args] = quoted.split(' ');
if (command === 'conda' && args[0] === 'info' && args[1] === '--json') {
return { stdout: JSON.stringify(condaInfo(condaPrefixNonWindows)) };
}
Expand All @@ -280,7 +282,7 @@ suite('Resolver Utils', () => {

test('resolveEnv: If no conda binary found, resolve as a simple environment', async () => {
sinon.stub(platformApis, 'getOSType').callsFake(() => platformApis.OSType.Windows);
sinon.stub(externalDependencies, 'exec').callsFake(async (command: string) => {
sinon.stub(externalDependencies, 'shellExecute').callsFake(async (command: string) => {
throw new Error(`${command} is missing or is not executable`);
});
const actual = await resolveBasicEnv({
Expand Down Expand Up @@ -603,7 +605,7 @@ suite('Resolver Utils', () => {
});

test('If data provided by registry is less informative than kind resolvers, do not use it to update environment', async () => {
sinon.stub(externalDependencies, 'exec').callsFake(async (command: string) => {
sinon.stub(externalDependencies, 'shellExecute').callsFake(async (command: string) => {
throw new Error(`${command} is missing or is not executable`);
});
const interpreterPath = path.join(regTestRoot, 'conda3', 'python.exe');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ suite('Conda and its environments are located correctly', () => {
return contents;
});

sinon.stub(externalDependencies, 'exec').callsFake(async (command: string, args: string[]) => {
sinon.stub(externalDependencies, 'shellExecute').callsFake(async (quoted: string) => {
const [command, ...args] = quoted.split(' ');
for (const prefix of ['', ...execPath]) {
const contents = getFile(path.join(prefix, command));
if (args[0] === 'info' && args[1] === '--json') {
Expand Down