Skip to content
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

Always use environment path when running conda environment commands #24807

Merged
merged 2 commits into from
Feb 14, 2025
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 @@ -564,11 +564,8 @@ export class Conda {
return undefined;
}
const args = [];
if (env.name) {
args.push('-n', env.name);
} else {
args.push('-p', env.prefix);
}
args.push('-p', env.prefix);

const python = [
forShellExecution ? this.shellCommand : this.command,
'run',
Expand Down
12 changes: 6 additions & 6 deletions src/test/common/process/pythonEnvironment.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,16 @@ suite('CondaEnvironment', () => {

teardown(() => sinon.restore());

test('getExecutionInfo with a named environment should return execution info using the environment name', async () => {
test('getExecutionInfo with a named environment should return execution info using the environment path', async () => {
const condaInfo = { name: 'foo', path: 'bar' };
const env = await createCondaEnv(condaInfo, processService.object, fileSystem.object);

const result = env?.getExecutionInfo(args, pythonPath);

expect(result).to.deep.equal({
command: condaFile,
args: ['run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
python: [condaFile, 'run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
args: ['run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
python: [condaFile, 'run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
pythonExecutable: pythonPath,
});
});
Expand All @@ -312,12 +312,12 @@ suite('CondaEnvironment', () => {
});
});

test('getExecutionObservableInfo with a named environment should return execution info using conda full path with the name', async () => {
test('getExecutionObservableInfo with a named environment should return execution info using conda full path with the path', async () => {
const condaInfo = { name: 'foo', path: 'bar' };
const expected = {
command: condaFile,
args: ['run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
python: [condaFile, 'run', '-n', condaInfo.name, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
args: ['run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT, ...args],
python: [condaFile, 'run', '-p', condaInfo.path, '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
pythonExecutable: pythonPath,
};
const env = await createCondaEnv(condaInfo, processService.object, fileSystem.object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ suite('Conda and its environments are located correctly', () => {
expect(args).to.not.equal(undefined);
assert.deepStrictEqual(
args,
['conda', 'run', '-n', 'envName', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
['conda', 'run', '-p', 'envPrefix', '--no-capture-output', 'python', OUTPUT_MARKER_SCRIPT],
'Incorrect args for case 1',
);

Expand Down