From 854d6767494b2bafe7b3107a9259b21930c9f347 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Mon, 15 Jul 2024 18:55:49 -0700 Subject: [PATCH] Some cleanups and api update --- .../locators/common/nativePythonFinder.ts | 2 +- src/client/pythonEnvironments/nativeAPI.ts | 34 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts index dd80a9da8a79..6e83742c27b3 100644 --- a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts +++ b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts @@ -23,7 +23,7 @@ const untildify = require('untildify'); const PYTHON_ENV_TOOLS_PATH = isWindows() ? path.join(EXTENSION_ROOT_DIR, 'python-env-tools', 'bin', 'pet.exe') - : '/Users/donjayamanne/Development/vsc/python-environment-tools/target/debug/pet'; + : path.join(EXTENSION_ROOT_DIR, 'python-env-tools', 'bin', 'pet'); export interface NativeEnvInfo { displayName?: string; diff --git a/src/client/pythonEnvironments/nativeAPI.ts b/src/client/pythonEnvironments/nativeAPI.ts index 041d4ddfda85..c1a0e9e48a6f 100644 --- a/src/client/pythonEnvironments/nativeAPI.ts +++ b/src/client/pythonEnvironments/nativeAPI.ts @@ -235,19 +235,12 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable { !native.executable ) { // This is a conda env without python, no point trying to resolve this. - // TODO: we still need to add this to this._envs - traceError(`Unhandled Conda environment without python: ${native.prefix}`); + // There is nothing to resolve + this.addEnv(native); } else { this.resolveEnv(native.executable ?? native.prefix) .then(() => { - const env = toPythonEnvInfo(this.finder, native); - if (env) { - this._envs.push(env); - this._onChanged.fire({ - type: FileChangeType.Created, - new: env, - }); - } + this.addEnv(native); }) .ignoreErrors(); } @@ -256,10 +249,7 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable { if (version.micro < 0 || version.minor < 0 || version.major < 0) { this.resolveEnv(native.executable ?? native.prefix).ignoreErrors(); } else { - const env = toPythonEnvInfo(this.finder, native); - if (env) { - this._envs.push(env); - } + this.addEnv(native); } } } @@ -285,6 +275,22 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable { return this._envs; } + addEnv(native: NativeEnvInfo): void { + const info = toPythonEnvInfo(this.finder, native); + if (!info) { + return; + } + const old = this._envs.find((item) => item.executable.filename === info.executable.filename); + if (old) { + this._envs = this._envs.filter((item) => item.executable.filename !== info.executable.filename); + this._envs.push(info); + this._onChanged.fire({ type: FileChangeType.Changed, old, new: info }); + } else { + this._envs.push(info); + this._onChanged.fire({ type: FileChangeType.Created, new: info }); + } + } + @cache(30_000, true) async resolveEnv(envPath?: string): Promise { if (envPath === undefined) {