Skip to content

Commit 00f1d2f

Browse files
authored
Include native finder conda when searching (#133)
Fixes #132
1 parent 46e133b commit 00f1d2f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/managers/conda/condaUtils.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { showErrorMessage } from '../../common/errors/utils';
3232
import { showInputBox, showQuickPick, withProgress } from '../../common/window.apis';
3333
import { Installable, selectFromCommonPackagesToInstall } from '../common/pickers';
3434
import { quoteArgs } from '../../features/execution/execUtils';
35+
import { traceInfo } from '../../common/logging';
3536

3637
export const CONDA_PATH_KEY = `${ENVS_EXTENSION_ID}:conda:CONDA_PATH`;
3738
export const CONDA_PREFIXES_KEY = `${ENVS_EXTENSION_ID}:conda:CONDA_PREFIXES`;
@@ -55,7 +56,7 @@ async function setConda(conda: string): Promise<void> {
5556
export function getCondaPathSetting(): string | undefined {
5657
const config = getConfiguration('python');
5758
const value = config.get<string>('condaPath');
58-
return (value && typeof value === 'string') ? untildify(value) : value;
59+
return value && typeof value === 'string' ? untildify(value) : value;
5960
}
6061

6162
export async function getCondaForWorkspace(fsPath: string): Promise<string | undefined> {
@@ -113,29 +114,47 @@ async function findConda(): Promise<readonly string[] | undefined> {
113114
}
114115
}
115116

116-
export async function getConda(): Promise<string> {
117+
export async function getConda(native?: NativePythonFinder): Promise<string> {
117118
const conda = getCondaPathSetting();
118119
if (conda) {
120+
traceInfo(`Using conda from settings: ${conda}`);
119121
return conda;
120122
}
121123

122124
if (condaPath) {
125+
traceInfo(`Using conda from cache: ${condaPath}`);
123126
return untildify(condaPath);
124127
}
125128

126129
const state = await getWorkspacePersistentState();
127130
condaPath = await state.get<string>(CONDA_PATH_KEY);
128131
if (condaPath) {
132+
traceInfo(`Using conda from persistent state: ${condaPath}`);
129133
return untildify(condaPath);
130134
}
131135

132136
const paths = await findConda();
133137
if (paths && paths.length > 0) {
134138
condaPath = paths[0];
139+
traceInfo(`Using conda from PATH: ${condaPath}`);
135140
await state.set(CONDA_PATH_KEY, condaPath);
136141
return condaPath;
137142
}
138143

144+
if (native) {
145+
const data = await native.refresh(false);
146+
const managers = data
147+
.filter((e) => !isNativeEnvInfo(e))
148+
.map((e) => e as NativeEnvManagerInfo)
149+
.filter((e) => e.tool.toLowerCase() === 'conda');
150+
if (managers.length > 0) {
151+
condaPath = managers[0].executable;
152+
traceInfo(`Using conda from native finder: ${condaPath}`);
153+
await state.set(CONDA_PATH_KEY, condaPath);
154+
return condaPath;
155+
}
156+
}
157+
139158
throw new Error('Conda not found');
140159
}
141160

src/managers/conda/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function registerCondaFeatures(
1515
const api: PythonEnvironmentApi = await getPythonApi();
1616

1717
try {
18-
await getConda();
18+
await getConda(nativeFinder);
1919
const envManager = new CondaEnvManager(nativeFinder, api, log);
2020
const packageManager = new CondaPackageManager(api, log);
2121

0 commit comments

Comments
 (0)