-
Notifications
You must be signed in to change notification settings - Fork 37
Implement Python installation via uv #1198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
caa182e
0cc1ea6
b027038
e8a157f
924d7ca
639c1cc
6f116b0
bb78c7b
fb299bf
48d1161
49de5f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| import { Task, TaskExecution, tasks } from 'vscode'; | ||
| import { Disposable, Task, TaskExecution, TaskProcessEndEvent, tasks } from 'vscode'; | ||
|
|
||
| export async function executeTask(task: Task): Promise<TaskExecution> { | ||
| return tasks.executeTask(task); | ||
| } | ||
|
|
||
| export function onDidEndTaskProcess( | ||
| listener: (e: TaskProcessEndEvent) => unknown, | ||
| thisArgs?: unknown, | ||
| disposables?: Disposable[], | ||
| ): Disposable { | ||
| return tasks.onDidEndTaskProcess(listener, thisArgs, disposables); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import * as path from 'path'; | ||
| import { EventEmitter, LogOutputChannel, MarkdownString, ProgressLocation, ThemeIcon, Uri, window } from 'vscode'; | ||
| import { | ||
| CreateEnvironmentOptions, | ||
| CreateEnvironmentScope, | ||
| DidChangeEnvironmentEventArgs, | ||
| DidChangeEnvironmentsEventArgs, | ||
| EnvironmentChangeKind, | ||
|
|
@@ -28,6 +30,7 @@ import { | |
| setSystemEnvForWorkspaces, | ||
| } from './cache'; | ||
| import { refreshPythons, resolveSystemPythonEnvironmentPath } from './utils'; | ||
| import { installPythonWithUv, promptInstallPythonViaUv, selectPythonVersionToInstall } from './uvPythonInstaller'; | ||
|
|
||
| export class SysPythonManager implements EnvironmentManager { | ||
| private collection: PythonEnvironment[] = []; | ||
|
|
@@ -70,6 +73,23 @@ export class SysPythonManager implements EnvironmentManager { | |
|
|
||
| await this.internalRefresh(false, SysManagerStrings.sysManagerDiscovering); | ||
|
|
||
| // If no Python environments were found, offer to install via uv | ||
| if (this.collection.length === 0) { | ||
| const pythonPath = await promptInstallPythonViaUv('activation', this.log); | ||
| if (pythonPath) { | ||
| const resolved = await resolveSystemPythonEnvironmentPath( | ||
| pythonPath, | ||
| this.nativeFinder, | ||
| this.api, | ||
| this, | ||
| ); | ||
| if (resolved) { | ||
| this.collection.push(resolved); | ||
| this._onDidChangeEnvironments.fire([{ environment: resolved, kind: EnvironmentChangeKind.add }]); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+76
to
+91
|
||
|
|
||
| this._initialized.resolve(); | ||
| } | ||
|
|
||
|
|
@@ -218,6 +238,37 @@ export class SysPythonManager implements EnvironmentManager { | |
| return resolved; | ||
| } | ||
|
|
||
| /** | ||
| * Installs a global Python using uv. | ||
| * This method shows a QuickPick to select the Python version, then installs it. | ||
| */ | ||
| async create( | ||
| _scope: CreateEnvironmentScope, | ||
| _options?: CreateEnvironmentOptions, | ||
| ): Promise<PythonEnvironment | undefined> { | ||
| // Show QuickPick to select Python version | ||
| const selectedVersion = await selectPythonVersionToInstall(); | ||
| if (!selectedVersion) { | ||
| // User cancelled | ||
| return undefined; | ||
| } | ||
|
|
||
| const pythonPath = await installPythonWithUv(this.log, selectedVersion); | ||
|
|
||
| if (pythonPath) { | ||
| // Resolve the installed Python using NativePythonFinder instead of full refresh | ||
| const resolved = await resolveSystemPythonEnvironmentPath(pythonPath, this.nativeFinder, this.api, this); | ||
| if (resolved) { | ||
| // Add to collection and fire change event | ||
| this.collection.push(resolved); | ||
| this._onDidChangeEnvironments.fire([{ environment: resolved, kind: EnvironmentChangeKind.add }]); | ||
| return resolved; | ||
| } | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| async clearCache(): Promise<void> { | ||
| await clearSystemEnvCache(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NoPythonEnvTreeItemnow has conditional labeling/command title for the system manager (install Python via uv) vs other managers (create env). There are existing unit tests for this file, but none cover this new branch. Please add tests that assert the label and command title for bothmanager.name === 'system'and non-system managers whensupportsCreateis true/false.