Skip to content

Commit deb3e66

Browse files
Copilotedvilme
andauthored
Fix environmentPath to use Python executable
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
1 parent 52196e8 commit deb3e66

15 files changed

Lines changed: 131 additions & 20 deletions

‎api/CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to the `@vscode/python-environments` API package are documen
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.4.1]
9+
10+
### Fixed
11+
12+
- Clarified that `PythonEnvironmentInfo.environmentPath` always identifies the Python executable.
13+
814
## [1.4.0]
915

1016
### Changed

‎api/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vscode/python-environments",
33
"description": "An API facade for the Python Environments extension in VS Code",
4-
"version": "1.4.0",
4+
"version": "1.4.1",
55
"author": {
66
"name": "Microsoft Corporation"
77
},

‎src/managers/builtin/venvUtils.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ async function getPythonInfo(env: NativeEnvInfo, nameStyle: VenvNameStyle = 'def
173173
version: env.version ?? 'Unknown',
174174
description: env.error,
175175
tooltip: env.error,
176-
environmentPath: Uri.file(env.prefix ?? env.executable ?? ''),
176+
environmentPath: Uri.file(
177+
env.executable ?? (env.prefix ? getVenvPythonPath(env.prefix) : ''),
178+
),
177179
iconPath: new ThemeIcon('warning'),
178180
sysPrefix: env.prefix ?? '',
179181
execInfo: {

‎src/managers/conda/condaEnvManager.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
248248
// If the environment is inside the workspace, add a .gitignore file
249249
try {
250250
const projectUris = this.api.getPythonProjects().map((p) => p.uri.fsPath);
251-
const envPath = result.environmentPath?.fsPath;
251+
const envPath = result.sysPrefix;
252252
if (envPath && projectUris.some((root) => envPath.startsWith(root))) {
253253
const gitignorePath = path.join(envPath, '.gitignore');
254254
await fs.writeFile(gitignorePath, '*\n', { flag: 'w' });
@@ -394,7 +394,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
394394
// Notify user if CONDA_PREFIX is set and they're trying to select a different environment
395395
if (process.env.CONDA_PREFIX && checkedEnv) {
396396
const condaPrefixPath = process.env.CONDA_PREFIX;
397-
const selectedPath = checkedEnv.environmentPath.fsPath;
397+
const selectedPath = checkedEnv.sysPrefix;
398398
// Only show notification if they selected a different environment
399399
if (condaPrefixPath !== selectedPath) {
400400
showInformationMessage(CondaStrings.condaCondaPrefixActive);

‎src/managers/conda/condaPackageManager.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class CondaPackageManager implements PackageManager, Disposable {
8080
try {
8181
const commandOptions = {
8282
pythonExecutable: 'conda',
83-
condaEnvironmentPath: environment.environmentPath.fsPath,
83+
condaEnvironmentPath: environment.sysPrefix,
8484
log: this.log,
8585
};
8686

@@ -172,7 +172,7 @@ export class CondaPackageManager implements PackageManager, Disposable {
172172
private async fetchPackages(environment: PythonEnvironment): Promise<Package[] | undefined> {
173173
const listCmd = new CondaListCommand({
174174
pythonExecutable: 'conda',
175-
condaEnvironmentPath: environment.environmentPath.fsPath,
175+
condaEnvironmentPath: environment.sysPrefix,
176176
log: this.log,
177177
});
178178
try {

‎src/managers/conda/condaUtils.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export async function getNamedCondaPythonInfo(
331331

332332
return {
333333
name: name,
334-
environmentPath: Uri.file(prefix),
334+
environmentPath: Uri.file(executable),
335335
displayName: `${name} (${sv})`,
336336
shortDisplayName: `${name}:${sv}`,
337337
displayPath: prefix,
@@ -376,7 +376,7 @@ export async function getPrefixesCondaPythonInfo(
376376
const basename = path.basename(prefix);
377377
return {
378378
name: basename,
379-
environmentPath: Uri.file(prefix),
379+
environmentPath: Uri.file(executable),
380380
displayName: `${basename} (${sv})`,
381381
shortDisplayName: `${basename}:${sv}`,
382382
displayPath: prefix,
@@ -749,7 +749,9 @@ export function nonWindowsGenerateConfig(
749749
function getCondaWithoutPython(name: string, prefix: string, conda: string): PythonEnvironmentInfo {
750750
return {
751751
name: name,
752-
environmentPath: Uri.file(prefix),
752+
environmentPath: Uri.file(
753+
isWindows() ? path.join(prefix, 'python.exe') : path.join(prefix, 'bin', 'python'),
754+
),
753755
displayName: `${name} (no-python)`,
754756
shortDisplayName: `${name} (no-python)`,
755757
displayPath: prefix,
@@ -1224,11 +1226,11 @@ export async function quickCreateConda(
12241226
}
12251227

12261228
export async function deleteCondaEnvironment(environment: PythonEnvironment, log: LogOutputChannel): Promise<boolean> {
1227-
let args = ['env', 'remove', '--yes', '--prefix', environment.environmentPath.fsPath];
1229+
let args = ['env', 'remove', '--yes', '--prefix', environment.sysPrefix];
12281230
return await withProgress(
12291231
{
12301232
location: ProgressLocation.Notification,
1231-
title: l10n.t('Deleting conda environment: {0}', environment.environmentPath.fsPath),
1233+
title: l10n.t('Deleting conda environment: {0}', environment.sysPrefix),
12321234
},
12331235
async () => {
12341236
try {

‎src/managers/pipenv/pipenvManager.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export class PipenvManager implements EnvironmentManager, Disposable {
166166
return this.collection.find(
167167
(env) =>
168168
normalizePath(env.environmentPath.fsPath) === normalized ||
169+
normalizePath(env.sysPrefix) === normalized ||
169170
(env.execInfo?.run.executable && normalizePath(env.execInfo.run.executable) === normalized),
170171
);
171172
}

‎src/managers/pipenv/pipenvUtils.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export async function getPipenv(): Promise<string | undefined> {
105105
}
106106
}
107107

108-
async function nativeToPythonEnv(
108+
/** Converts native finder data to a Pipenv environment. @internal Exported for testing. */
109+
export async function nativeToPythonEnv(
109110
info: NativeEnvInfo,
110111
api: PythonEnvironmentApi,
111112
manager: EnvironmentManager,
@@ -139,7 +140,7 @@ async function nativeToPythonEnv(
139140
shortDisplayName: displayName,
140141
displayPath: info.prefix,
141142
version: info.version,
142-
environmentPath: Uri.file(info.prefix),
143+
environmentPath: Uri.file(info.executable),
143144
description: undefined,
144145
tooltip: info.prefix,
145146
execInfo: {

‎src/managers/poetry/poetryUtils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export async function nativeToPythonEnv(
381381
shortDisplayName: displayName,
382382
displayPath: info.prefix,
383383
version: info.version,
384-
environmentPath: Uri.file(info.prefix),
384+
environmentPath: Uri.file(info.executable),
385385
description: undefined,
386386
tooltip: info.prefix,
387387
execInfo: {

0 commit comments

Comments
 (0)