Skip to content

Commit 760aa0e

Browse files
authored
Changes to conda paths not detected (#18725)
* Changes to conda paths not detected * oops
1 parent b0746af commit 760aa0e

3 files changed

Lines changed: 15 additions & 39 deletions

File tree

src/client/pythonEnvironments/common/environmentManagers/conda.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
pathExists,
1111
readFile,
1212
shellExecute,
13+
onDidChangePythonSetting,
1314
} from '../externalDependencies';
1415

1516
import { PythonVersion, UNKNOWN_PYTHON_VERSION } from '../../base/info';
@@ -25,7 +26,7 @@ import { buildPythonExecInfo } from '../../exec';
2526
import { getExecutablePath } from '../../info/executable';
2627

2728
export const AnacondaCompanyName = 'Anaconda, Inc.';
28-
29+
export const CONDAPATH_SETTING_KEY = 'condaPath';
2930
export type CondaEnvironmentInfo = {
3031
name: string;
3132
path: string;
@@ -247,13 +248,17 @@ export class Conda {
247248
* @param command - Command used to spawn conda. This has the same meaning as the
248249
* first argument of spawn() - i.e. it can be a full path, or just a binary name.
249250
*/
250-
constructor(readonly command: string) {}
251+
constructor(readonly command: string) {
252+
onDidChangePythonSetting(CONDAPATH_SETTING_KEY, () => {
253+
Conda.condaPromise = undefined;
254+
});
255+
}
251256

252257
public static async getConda(): Promise<Conda | undefined> {
253-
if (this.condaPromise === undefined || isTestExecution()) {
254-
this.condaPromise = Conda.locate();
258+
if (Conda.condaPromise === undefined || isTestExecution()) {
259+
Conda.condaPromise = Conda.locate();
255260
}
256-
return this.condaPromise;
261+
return Conda.condaPromise;
257262
}
258263

259264
/**
@@ -269,7 +274,7 @@ export class Conda {
269274

270275
// Produce a list of candidate binaries to be probed by exec'ing them.
271276
async function* getCandidates() {
272-
const customCondaPath = getPythonSetting<string>('condaPath');
277+
const customCondaPath = getPythonSetting<string>(CONDAPATH_SETTING_KEY);
273278
if (customCondaPath && customCondaPath !== 'conda') {
274279
// If user has specified a custom conda path, use it first.
275280
yield customCondaPath;

src/client/pythonEnvironments/common/environmentManagers/condaService.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { inject, injectable } from 'inversify';
22
import * as path from 'path';
33
import { SemVer } from 'semver';
4-
import { ConfigurationChangeEvent, Uri } from 'vscode';
5-
import { IWorkspaceService } from '../../../common/application/types';
64
import { IFileSystem, IPlatformService } from '../../../common/platform/types';
7-
import { IDisposableRegistry } from '../../../common/types';
85
import { cache } from '../../../common/utils/decorators';
96
import { ICondaService } from '../../../interpreter/contracts';
107
import { traceDecoratorVerbose } from '../../../logging';
@@ -17,25 +14,17 @@ import { Conda, CondaEnvironmentInfo, CondaInfo } from './conda';
1714
export class CondaService implements ICondaService {
1815
private isAvailable: boolean | undefined;
1916

20-
private condaFile: Promise<string> | undefined;
21-
2217
constructor(
2318
@inject(IPlatformService) private platform: IPlatformService,
2419
@inject(IFileSystem) private fileSystem: IFileSystem,
25-
@inject(IDisposableRegistry) private disposableRegistry: IDisposableRegistry,
26-
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
27-
) {
28-
this.addCondaPathChangedHandler();
29-
}
20+
) {}
3021

3122
/**
3223
* Return the path to the "conda file".
3324
*/
25+
// eslint-disable-next-line class-methods-use-this
3426
public async getCondaFile(): Promise<string> {
35-
if (!this.condaFile) {
36-
this.condaFile = Conda.getConda().then((conda) => conda?.command ?? 'conda');
37-
}
38-
return this.condaFile;
27+
return Conda.getConda().then((conda) => conda?.command ?? 'conda');
3928
}
4029

4130
// eslint-disable-next-line class-methods-use-this
@@ -123,19 +112,4 @@ export class CondaService implements ICondaService {
123112
const conda = await Conda.getConda();
124113
return conda?.getInfo();
125114
}
126-
127-
private addCondaPathChangedHandler() {
128-
const disposable = this.workspaceService.onDidChangeConfiguration(this.onDidChangeConfiguration.bind(this));
129-
this.disposableRegistry.push(disposable);
130-
}
131-
132-
private async onDidChangeConfiguration(event: ConfigurationChangeEvent) {
133-
const workspacesUris: (Uri | undefined)[] = this.workspaceService.hasWorkspaceFolders
134-
? this.workspaceService.workspaceFolders!.map((workspace) => workspace.uri)
135-
: [undefined];
136-
if (workspacesUris.findIndex((uri) => event.affectsConfiguration('python.condaPath', uri)) === -1) {
137-
return;
138-
}
139-
this.condaFile = undefined;
140-
}
141115
}

src/test/pythonEnvironments/discovery/locators/condaService.unit.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as assert from 'assert';
22
import * as path from 'path';
33
import * as TypeMoq from 'typemoq';
44
import * as sinon from 'sinon';
5-
import { IWorkspaceService } from '../../../../client/common/application/types';
65
import { FileSystemPaths, FileSystemPathUtils } from '../../../../client/common/platform/fs-paths';
76
import { IFileSystem, IPlatformService } from '../../../../client/common/platform/types';
87
import { CondaService } from '../../../../client/pythonEnvironments/common/environmentManagers/condaService';
@@ -12,9 +11,7 @@ suite('Interpreters Conda Service', () => {
1211
let platformService: TypeMoq.IMock<IPlatformService>;
1312
let condaService: CondaService;
1413
let fileSystem: TypeMoq.IMock<IFileSystem>;
15-
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
1614
setup(async () => {
17-
workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>();
1815
platformService = TypeMoq.Mock.ofType<IPlatformService>();
1916
fileSystem = TypeMoq.Mock.ofType<IFileSystem>();
2017

@@ -27,7 +24,7 @@ suite('Interpreters Conda Service', () => {
2724
return utils.arePathsSame(p1, p2);
2825
});
2926

30-
condaService = new CondaService(platformService.object, fileSystem.object, [], workspaceService.object);
27+
condaService = new CondaService(platformService.object, fileSystem.object);
3128
sinon.stub(Conda, 'getConda').callsFake(() => Promise.resolve(undefined));
3229
});
3330
teardown(() => sinon.restore());

0 commit comments

Comments
 (0)