Skip to content

Commit 39345db

Browse files
committed
updates
1 parent 7398ade commit 39345db

5 files changed

Lines changed: 28 additions & 26 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
"type": "boolean",
133133
"description": "%python-envs.alwaysUseUv.description%",
134134
"default": true,
135-
"scope": "machine"
135+
"scope": "resource"
136136
}
137137
}
138138
},

src/managers/builtin/helpers.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as ch from 'child_process';
22
import { CancellationError, CancellationToken, LogOutputChannel } from 'vscode';
3-
import { createDeferred } from '../../common/utils/deferred';
4-
import { sendTelemetryEvent } from '../../common/telemetry/sender';
3+
import { EnvironmentGroupInfo } from '../../api';
54
import { EventNames } from '../../common/telemetry/constants';
5+
import { sendTelemetryEvent } from '../../common/telemetry/sender';
6+
import { createDeferred } from '../../common/utils/deferred';
67
import { getConfiguration } from '../../common/workspace.apis';
7-
import { NativePythonEnvironmentKind } from '../common/nativePythonFinder';
88

99
const available = createDeferred<boolean>();
1010
export async function isUvInstalled(log?: LogOutputChannel): Promise<boolean> {
@@ -28,33 +28,26 @@ export async function isUvInstalled(log?: LogOutputChannel): Promise<boolean> {
2828

2929
/**
3030
* Determines if uv should be used for managing a virtual environment.
31-
* @param envKind - The kind of environment (Venv, VenvUv, etc.)
32-
* @param log - Optional log output channel
33-
* @returns True if uv should be used, false otherwise
31+
* @param group - Optional environment group name (string) or EnvironmentGroupInfo object. If 'uv' or group.name is 'uv', uv will be used if available.
32+
* @param log - Optional log output channel for logging operations
33+
* @returns True if uv should be used, false otherwise. For 'uv' environments, returns true if uv is installed. For other environments, checks the 'python-envs.alwaysUseUv' setting and uv availability.
3434
*/
35-
export async function shouldUseUv(
36-
envKind?: NativePythonEnvironmentKind,
37-
log?: LogOutputChannel,
38-
): Promise<boolean> {
39-
// If the environment is explicitly a VenvUv type, always use uv
40-
if (envKind === NativePythonEnvironmentKind.venvUv) {
35+
export async function shouldUseUv(group?: string | EnvironmentGroupInfo, log?: LogOutputChannel): Promise<boolean> {
36+
if (group === 'uv' || (typeof group === 'object' && group.name === 'uv')) {
37+
// Always use uv for VenvUv environments
4138
return await isUvInstalled(log);
4239
}
4340

44-
// Check the alwaysUseUv setting
41+
// For other environments, check the user setting
4542
const config = getConfiguration('python-envs');
4643
const alwaysUseUv = config.get<boolean>('alwaysUseUv', true);
4744

48-
// If alwaysUseUv is true and uv is installed, use it
4945
if (alwaysUseUv) {
5046
return await isUvInstalled(log);
5147
}
52-
53-
// Otherwise, only use uv for VenvUv environments (already handled above)
5448
return false;
5549
}
5650

57-
5851
export async function runUV(
5952
args: string[],
6053
cwd?: string,

src/managers/builtin/pipManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ThemeIcon,
99
window,
1010
} from 'vscode';
11+
import { Disposable } from 'vscode-jsonrpc';
1112
import {
1213
DidChangePackagesEventArgs,
1314
IconPath,
@@ -18,10 +19,9 @@ import {
1819
PythonEnvironment,
1920
PythonEnvironmentApi,
2021
} from '../../api';
22+
import { getWorkspacePackagesToInstall } from './pipUtils';
2123
import { managePackages, refreshPackages } from './utils';
22-
import { Disposable } from 'vscode-jsonrpc';
2324
import { VenvManager } from './venvManager';
24-
import { getWorkspacePackagesToInstall } from './pipUtils';
2525

2626
function getChanges(before: Package[], after: Package[]): { kind: PackageChangeKind; pkg: Package }[] {
2727
const changes: { kind: PackageChangeKind; pkg: Package }[] = [];

src/managers/builtin/utils.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
NativePythonFinder,
1919
} from '../common/nativePythonFinder';
2020
import { shortVersion, sortEnvironments } from '../common/utils';
21-
import { shouldUseUv, runPython, runUV } from './helpers';
21+
import { runPython, runUV, shouldUseUv } from './helpers';
2222
import { parsePipList, PipPackage } from './pipListUtils';
2323

2424
function asPackageQuickPickItem(name: string, version?: string): QuickPickItem {
@@ -139,11 +139,19 @@ export async function refreshPythons(
139139
}
140140

141141
async function refreshPipPackagesRaw(environment: PythonEnvironment, log?: LogOutputChannel): Promise<string> {
142-
const useUv = await shouldUseUv(undefined, log);
142+
const useUv = await shouldUseUv(environment.group, log);
143143
if (useUv) {
144144
return await runUV(['pip', 'list', '--python', environment.execInfo.run.executable], undefined, log);
145145
}
146-
return await runPython(environment.execInfo.run.executable, ['-m', 'pip', 'list'], undefined, log);
146+
try {
147+
return await runPython(environment.execInfo.run.executable, ['-m', 'pip', 'list'], undefined, log);
148+
} catch (ex) {
149+
log?.error('Error running pip list', ex);
150+
log?.info(
151+
'Installation attempted using pip, action can be done with uv if installed and setting `alwaysUseUv` is enabled.',
152+
);
153+
throw ex;
154+
}
147155
}
148156

149157
export async function refreshPipPackages(
@@ -194,7 +202,7 @@ export async function managePackages(
194202
throw new Error('Python 2.* is not supported (deprecated)');
195203
}
196204

197-
const useUv = await shouldUseUv(undefined, manager.log);
205+
const useUv = await shouldUseUv(environment.group, manager.log);
198206
const uninstallArgs = ['pip', 'uninstall'];
199207
if (options.uninstall && options.uninstall.length > 0) {
200208
if (useUv) {

src/managers/builtin/venvUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
NativePythonFinder,
2626
} from '../common/nativePythonFinder';
2727
import { getShellActivationCommands, shortVersion, sortEnvironments } from '../common/utils';
28-
import { shouldUseUv, runPython, runUV } from './helpers';
28+
import { runPython, runUV, shouldUseUv } from './helpers';
2929
import { getProjectInstallable, PipPackages } from './pipUtils';
3030
import { resolveSystemPythonEnvironmentPath } from './utils';
3131
import { createStepBasedVenvFlow } from './venvStepBasedFlow';
@@ -157,6 +157,7 @@ async function getPythonInfo(env: NativeEnvInfo): Promise<PythonEnvironmentInfo>
157157
shellActivation,
158158
shellDeactivation,
159159
},
160+
group: env.kind === NativePythonEnvironmentKind.venvUv ? 'uv' : 'venv',
160161
};
161162
} else {
162163
throw new Error(`Invalid python info: ${JSON.stringify(env)}`);
@@ -290,7 +291,7 @@ export async function createWithProgress(
290291
async () => {
291292
const result: CreateEnvironmentResult = {};
292293
try {
293-
const useUv = await shouldUseUv(undefined, log);
294+
const useUv = await shouldUseUv(basePython.group, log);
294295
// env creation
295296
if (basePython.execInfo?.run.executable) {
296297
if (useUv) {

0 commit comments

Comments
 (0)