Skip to content

Commit

Permalink
Some cleanups and api update
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Jul 17, 2024
1 parent 87f4382 commit 854d676
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 20 additions & 14 deletions src/client/pythonEnvironments/nativeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
}
}
}
Expand All @@ -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<PythonEnvInfo | undefined> {
if (envPath === undefined) {
Expand Down

0 comments on commit 854d676

Please sign in to comment.