Skip to content

Commit 44f84dd

Browse files
committed
add uv to more strings when being used
1 parent a232ff5 commit 44f84dd

File tree

5 files changed

+116
-57
lines changed

5 files changed

+116
-57
lines changed

src/common/localize.ts

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,74 @@ export namespace ProjectViews {
7777
export const noPackages = l10n.t('No packages found');
7878
}
7979

80-
export namespace VenvManagerStrings {
81-
export const venvManagerDescription = l10n.t('Manages virtual environments created using `venv`');
82-
export const venvInitialize = l10n.t('Initializing virtual environments');
83-
export const venvRefreshing = l10n.t('Refreshing virtual environments');
84-
export const venvGlobalFolder = l10n.t('Select a folder to create a global virtual environment');
85-
export const venvGlobalFoldersSetting = l10n.t('Venv Folders Setting');
80+
export class VenvManagerStringsNoUv {
81+
static venvManagerDescription = l10n.t('Manages virtual environments created using `venv`');
82+
static venvInitialize = l10n.t('Initializing virtual environments');
83+
static venvRefreshing = l10n.t('Refreshing virtual environments');
84+
static venvGlobalFolder = l10n.t('Select a folder to create a global virtual environment');
85+
static venvGlobalFoldersSetting = l10n.t('Venv Folders Setting');
86+
87+
static venvErrorNoBasePython = l10n.t('No base Python found');
88+
static venvErrorNoPython3 = l10n.t('Did not find any base Python 3');
89+
90+
static venvName = l10n.t('Enter a name for the virtual environment');
91+
static venvNameErrorEmpty = l10n.t('Name cannot be empty');
92+
static venvNameErrorExists = l10n.t('A folder with the same name already exists');
93+
static venvCreateFailed = l10n.t('Failed to create virtual environment');
94+
95+
static venvRemoving = l10n.t('Removing virtual environment');
96+
static venvRemoveFailed = l10n.t('Failed to remove virtual environment');
97+
98+
static installEditable = l10n.t('Install project as editable');
99+
static searchingDependencies = l10n.t('Searching for dependencies');
100+
101+
static selectQuickOrCustomize = l10n.t('Select environment creation mode');
102+
static quickCreate = l10n.t('Quick Create');
103+
static quickCreateDescription = l10n.t('Create a virtual environment in the workspace root');
104+
static customize = l10n.t('Custom');
105+
static customizeDescription = l10n.t('Choose python version, location, packages, name, etc.');
106+
}
86107

87-
export const venvErrorNoBasePython = l10n.t('No base Python found');
88-
export const venvErrorNoPython3 = l10n.t('Did not find any base Python 3');
108+
export class VenvManagerStringsWithUv {
109+
static venvManagerDescription = l10n.t('Manages virtual environments created using `venv [uv]`');
110+
static venvInitialize = l10n.t('Initializing virtual environments');
111+
static venvRefreshing = l10n.t('Refreshing virtual environments');
112+
static venvGlobalFolder = l10n.t('Select a folder to create a global virtual environment');
113+
static venvGlobalFoldersSetting = l10n.t('Venv Folders Setting');
89114

90-
export const venvName = l10n.t('Enter a name for the virtual environment');
91-
export const venvNameErrorEmpty = l10n.t('Name cannot be empty');
92-
export const venvNameErrorExists = l10n.t('A folder with the same name already exists');
93-
export const venvCreateFailed = l10n.t('Failed to create virtual environment');
115+
static venvErrorNoBasePython = l10n.t('No base Python found');
116+
static venvErrorNoPython3 = l10n.t('Did not find any base Python 3');
94117

95-
export const venvRemoving = l10n.t('Removing virtual environment');
96-
export const venvRemoveFailed = l10n.t('Failed to remove virtual environment');
118+
static venvName = l10n.t('Enter a name for the virtual environment');
119+
static venvNameErrorEmpty = l10n.t('Name cannot be empty');
120+
static venvNameErrorExists = l10n.t('A folder with the same name already exists');
121+
static venvCreateFailed = l10n.t('Failed to create virtual environment');
97122

98-
export const installEditable = l10n.t('Install project as editable');
99-
export const searchingDependencies = l10n.t('Searching for dependencies');
123+
static venvRemoving = l10n.t('Removing virtual environment');
124+
static venvRemoveFailed = l10n.t('Failed to remove virtual environment');
100125

101-
export const selectQuickOrCustomize = l10n.t('Select environment creation mode');
102-
export const quickCreate = l10n.t('Quick Create');
103-
export const quickCreateDescription = l10n.t('Create a virtual environment in the workspace root');
104-
export const customize = l10n.t('Custom');
105-
export const customizeDescription = l10n.t('Choose python version, location, packages, name, etc.');
126+
static installEditable = l10n.t('Install project as editable');
127+
static searchingDependencies = l10n.t('Searching for dependencies');
128+
129+
static selectQuickOrCustomize = l10n.t('Select environment creation mode');
130+
static quickCreate = l10n.t('Quick Create');
131+
static quickCreateDescription = l10n.t(
132+
'Create a virtual environment in the workspace root using uv for fast installs',
133+
);
134+
static customize = l10n.t('Custom');
135+
static customizeDescription = l10n.t(
136+
'Choose python version, location, packages, name, etc. (uses uv for installs)',
137+
);
138+
}
139+
140+
/**
141+
* VenvManagerStrings is assigned to either VenvManagerStringsNoUv or VenvManagerStringsWithUv
142+
* depending on which environment manager is active. This variable can be reassigned at runtime.
143+
*/
144+
export let VenvManagerStrings: typeof VenvManagerStringsNoUv | typeof VenvManagerStringsWithUv = VenvManagerStringsNoUv;
145+
146+
export function setVenvManagerStrings(val: typeof VenvManagerStringsNoUv | typeof VenvManagerStringsWithUv) {
147+
VenvManagerStrings = val;
106148
}
107149

108150
export namespace SysManagerStrings {

src/managers/builtin/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Disposable, LogOutputChannel } from 'vscode';
22
import { PythonEnvironmentApi } from '../../api';
3+
import { setVenvManagerStrings, VenvManagerStringsWithUv } from '../../common/localize';
34
import { createSimpleDebounce } from '../../common/utils/debounce';
45
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
56
import { createFileSystemWatcher, onDidDeleteFiles } from '../../common/workspace.apis';
@@ -25,6 +26,8 @@ export async function registerSystemPythonFeatures(
2526
if (uvAvailable) {
2627
venvManager.setDisplayName('venv [uv]');
2728
log.info('uv detected - updating venv manager display name');
29+
// Switch all venv-related UI strings to uv versions
30+
setVenvManagerStrings(VenvManagerStringsWithUv);
2831
}
2932

3033
disposables.push(

src/managers/builtin/pipUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import { LogOutputChannel, ProgressLocation, QuickInputButtons, QuickPickItem, Uri } from 'vscode';
55
import { PackageManagementOptions, PythonEnvironment, PythonEnvironmentApi, PythonProject } from '../../api';
66
import { EXTENSION_ROOT_DIR } from '../../common/constants';
7-
import { PackageManagement, Pickers, VenvManagerStrings } from '../../common/localize';
7+
import { PackageManagement, Pickers, VenvManagerStringsNoUv } from '../../common/localize';
88
import { traceInfo } from '../../common/logging';
99
import { showQuickPickWithButtons, withProgress } from '../../common/window.apis';
1010
import { findFiles } from '../../common/workspace.apis';
@@ -36,7 +36,7 @@ function getTomlInstallable(toml: tomljs.JsonMap, tomlPath: Uri): Installable[]
3636
extras.push({
3737
name,
3838
displayName: name,
39-
description: VenvManagerStrings.installEditable,
39+
description: VenvManagerStringsNoUv.installEditable,
4040
group: 'TOML',
4141
args: ['-e', projectDir],
4242
uri: tomlPath,
@@ -177,7 +177,7 @@ export async function getProjectInstallable(
177177
await withProgress(
178178
{
179179
location: ProgressLocation.Notification,
180-
title: VenvManagerStrings.searchingDependencies,
180+
title: VenvManagerStringsNoUv.searchingDependencies,
181181
},
182182
async (_progress, token) => {
183183
const results: Uri[] = (

src/managers/builtin/venvManager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
SetEnvironmentScope,
3030
} from '../../api';
3131
import { PYTHON_EXTENSION_ID } from '../../common/constants';
32-
import { VenvManagerStrings } from '../../common/localize';
32+
import { VenvManagerStringsNoUv } from '../../common/localize';
3333
import { traceError, traceWarn } from '../../common/logging';
3434
import { createDeferred, Deferred } from '../../common/utils/deferred';
3535
import { showErrorMessage, withProgress } from '../../common/window.apis';
@@ -83,7 +83,7 @@ export class VenvManager implements EnvironmentManager {
8383
// Descriptions were a bit too visually noisy
8484
// https://github.com/microsoft/vscode-python-environments/issues/167
8585
this.description = undefined;
86-
this.tooltip = new MarkdownString(VenvManagerStrings.venvManagerDescription, true);
86+
this.tooltip = new MarkdownString(VenvManagerStringsNoUv.venvManagerDescription, true);
8787
this.preferredPackageManagerId = 'ms-python.python:pip';
8888
this.iconPath = new ThemeIcon('python');
8989
}
@@ -97,7 +97,7 @@ export class VenvManager implements EnvironmentManager {
9797
this._initialized = createDeferred();
9898

9999
try {
100-
await this.internalRefresh(undefined, false, VenvManagerStrings.venvInitialize);
100+
await this.internalRefresh(undefined, false, VenvManagerStringsNoUv.venvInitialize);
101101
} finally {
102102
this._initialized.resolve();
103103
}
@@ -156,15 +156,15 @@ export class VenvManager implements EnvironmentManager {
156156
// error on missing information
157157
if (!this.globalEnv) {
158158
this.log.error('No base python found');
159-
showErrorMessage(VenvManagerStrings.venvErrorNoBasePython);
159+
showErrorMessage(VenvManagerStringsNoUv.venvErrorNoBasePython);
160160
throw new Error('No base python found');
161161
}
162162
if (!this.globalEnv.version.startsWith('3.')) {
163163
this.log.error('Did not find any base python 3.*');
164164
globals.forEach((e, i) => {
165165
this.log.error(`${i}: ${e.version} : ${e.environmentPath.fsPath}`);
166166
});
167-
showErrorMessage(VenvManagerStrings.venvErrorNoPython3);
167+
showErrorMessage(VenvManagerStringsNoUv.venvErrorNoPython3);
168168
throw new Error('Did not find any base python 3.*');
169169
}
170170
if (this.globalEnv && this.globalEnv.version.startsWith('3.')) {
@@ -292,14 +292,14 @@ export class VenvManager implements EnvironmentManager {
292292
}
293293

294294
async refresh(scope: RefreshEnvironmentsScope): Promise<void> {
295-
return this.internalRefresh(scope, true, VenvManagerStrings.venvRefreshing);
295+
return this.internalRefresh(scope, true, VenvManagerStringsNoUv.venvRefreshing);
296296
}
297297

298298
async watcherRefresh(): Promise<void> {
299299
if (this.skipWatcherRefresh) {
300300
return;
301301
}
302-
return this.internalRefresh(undefined, true, VenvManagerStrings.venvRefreshing);
302+
return this.internalRefresh(undefined, true, VenvManagerStringsNoUv.venvRefreshing);
303303
}
304304

305305
private async internalRefresh(

src/managers/builtin/venvUtils.ts

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import { l10n, LogOutputChannel, ProgressLocation, QuickPickItem, QuickPickItemKind, ThemeIcon, Uri } from 'vscode';
55
import { EnvironmentManager, PythonEnvironment, PythonEnvironmentApi, PythonEnvironmentInfo } from '../../api';
66
import { ENVS_EXTENSION_ID } from '../../common/constants';
7-
import { Common, VenvManagerStrings } from '../../common/localize';
7+
import { Common, VenvManagerStringsNoUv } from '../../common/localize';
88
import { traceInfo } from '../../common/logging';
99
import { getWorkspacePersistentState } from '../../common/persistentState';
1010
import { pickEnvironmentFrom } from '../../common/pickers/environments';
@@ -209,15 +209,15 @@ export async function getGlobalVenvLocation(): Promise<Uri | undefined> {
209209
const items: FolderQuickPickItem[] = [
210210
{
211211
label: Common.browse,
212-
description: VenvManagerStrings.venvGlobalFolder,
212+
description: VenvManagerStringsNoUv.venvGlobalFolder,
213213
},
214214
];
215215

216216
const venvPaths = getVenvFoldersSetting();
217217
if (venvPaths.length > 0) {
218218
items.push(
219219
{
220-
label: VenvManagerStrings.venvGlobalFoldersSetting,
220+
label: VenvManagerStringsNoUv.venvGlobalFoldersSetting,
221221
kind: QuickPickItemKind.Separator,
222222
},
223223
...venvPaths.map((p) => ({
@@ -243,7 +243,7 @@ export async function getGlobalVenvLocation(): Promise<Uri | undefined> {
243243
}
244244

245245
const selected = await showQuickPick(items, {
246-
placeHolder: VenvManagerStrings.venvGlobalFolder,
246+
placeHolder: VenvManagerStringsNoUv.venvGlobalFolder,
247247
ignoreFocusOut: true,
248248
});
249249

@@ -269,24 +269,24 @@ async function createWithCustomization(version: string): Promise<boolean | undef
269269
const selection: QuickPickItem | undefined = await showQuickPick(
270270
[
271271
{
272-
label: VenvManagerStrings.quickCreate,
273-
description: VenvManagerStrings.quickCreateDescription,
272+
label: VenvManagerStringsNoUv.quickCreate,
273+
description: VenvManagerStringsNoUv.quickCreateDescription,
274274
detail: l10n.t('Uses Python version {0} and installs workspace dependencies.', version),
275275
},
276276
{
277-
label: VenvManagerStrings.customize,
278-
description: VenvManagerStrings.customizeDescription,
277+
label: VenvManagerStringsNoUv.customize,
278+
description: VenvManagerStringsNoUv.customizeDescription,
279279
},
280280
],
281281
{
282-
placeHolder: VenvManagerStrings.selectQuickOrCustomize,
282+
placeHolder: VenvManagerStringsNoUv.selectQuickOrCustomize,
283283
ignoreFocusOut: true,
284284
},
285285
);
286286

287287
if (selection === undefined) {
288288
return undefined;
289-
} else if (selection.label === VenvManagerStrings.quickCreate) {
289+
} else if (selection.label === VenvManagerStringsNoUv.quickCreate) {
290290
return false;
291291
}
292292
return true;
@@ -305,19 +305,27 @@ async function createWithProgress(
305305
const pythonPath =
306306
os.platform() === 'win32' ? path.join(envPath, 'Scripts', 'python.exe') : path.join(envPath, 'bin', 'python');
307307

308+
const useUv = await isUvInstalled(log);
309+
const progressTitle = useUv
310+
? l10n.t(
311+
'Creating virtual environment named {0} using python version {1} [uv].',
312+
path.basename(envPath),
313+
basePython.version,
314+
)
315+
: l10n.t(
316+
'Creating virtual environment named {0} using python version {1}.',
317+
path.basename(envPath),
318+
basePython.version,
319+
);
320+
308321
return await withProgress(
309322
{
310323
location: ProgressLocation.Notification,
311-
title: l10n.t(
312-
'Creating virtual environment named {0} using python version {1}.',
313-
path.basename(envPath),
314-
basePython.version,
315-
),
324+
title: progressTitle,
316325
},
317326
async () => {
318327
const result: CreateEnvironmentResult = {};
319328
try {
320-
const useUv = await isUvInstalled(log);
321329
// env creation
322330
if (basePython.execInfo?.run.executable) {
323331
if (useUv) {
@@ -353,13 +361,19 @@ async function createWithProgress(
353361
});
354362
} catch (e) {
355363
// error occurred while installing packages
356-
result.pkgInstallationErr = e instanceof Error ? e.message : String(e);
364+
result.pkgInstallationErr = useUv
365+
? `Failed to install packages with uv: ${e instanceof Error ? e.message : String(e)}`
366+
: e instanceof Error
367+
? e.message
368+
: String(e);
357369
}
358370
}
359371
result.environment = env;
360372
} catch (e) {
361-
log.error(`Failed to create virtual environment: ${e}`);
362-
result.envCreationErr = `Failed to create virtual environment: ${e}`;
373+
result.envCreationErr = useUv
374+
? `Failed to create virtual environment with uv: ${e}`
375+
: `Failed to create virtual environment: ${e}`;
376+
log.error(result.envCreationErr);
363377
}
364378
return result;
365379
},
@@ -369,14 +383,14 @@ async function createWithProgress(
369383
export function ensureGlobalEnv(basePythons: PythonEnvironment[], log: LogOutputChannel): PythonEnvironment[] {
370384
if (basePythons.length === 0) {
371385
log.error('No base python found');
372-
showErrorMessage(VenvManagerStrings.venvErrorNoBasePython);
386+
showErrorMessage(VenvManagerStringsNoUv.venvErrorNoBasePython);
373387
throw new Error('No base python found');
374388
}
375389

376390
const filtered = basePythons.filter((e) => e.version.startsWith('3.'));
377391
if (filtered.length === 0) {
378392
log.error('Did not find any base python 3.*');
379-
showErrorMessage(VenvManagerStrings.venvErrorNoPython3);
393+
showErrorMessage(VenvManagerStringsNoUv.venvErrorNoPython3);
380394
basePythons.forEach((e, i) => {
381395
log.error(`${i}: ${e.version} : ${e.environmentPath.fsPath}`);
382396
});
@@ -457,15 +471,15 @@ export async function createPythonVenv(
457471
}
458472

459473
const name = await showInputBox({
460-
prompt: VenvManagerStrings.venvName,
474+
prompt: VenvManagerStringsNoUv.venvName,
461475
value: '.venv',
462476
ignoreFocusOut: true,
463477
validateInput: async (value) => {
464478
if (!value) {
465-
return VenvManagerStrings.venvNameErrorEmpty;
479+
return VenvManagerStringsNoUv.venvNameErrorEmpty;
466480
}
467481
if (await fsapi.pathExists(path.join(venvRoot.fsPath, value))) {
468-
return VenvManagerStrings.venvNameErrorExists;
482+
return VenvManagerStringsNoUv.venvNameErrorExists;
469483
}
470484
},
471485
});
@@ -513,15 +527,15 @@ export async function removeVenv(environment: PythonEnvironment, log: LogOutputC
513527
const result = await withProgress(
514528
{
515529
location: ProgressLocation.Notification,
516-
title: VenvManagerStrings.venvRemoving,
530+
title: VenvManagerStringsNoUv.venvRemoving,
517531
},
518532
async () => {
519533
try {
520534
await fsapi.remove(envPath);
521535
return true;
522536
} catch (e) {
523537
log.error(`Failed to remove virtual environment: ${e}`);
524-
showErrorMessage(VenvManagerStrings.venvRemoveFailed);
538+
showErrorMessage(VenvManagerStringsNoUv.venvRemoveFailed);
525539
return false;
526540
}
527541
},

0 commit comments

Comments
 (0)