-
Notifications
You must be signed in to change notification settings - Fork 55
[WIP] Complete package manager command class refactoring #1621
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
720bede
d9f2cf2
d08b7bd
f3bd8f9
5e5c45d
7179cf0
2a80488
5569d50
cf49062
76a598f
1890ef3
83d6bc6
1c0fe0e
790fef6
a0bc056
e5d22c6
1edb7dd
4b9e8d2
7521fcc
279fcd0
5db7455
4264f04
42f9347
8246246
0858f85
15ab7f3
4e2eefb
0157a2a
cae697f
d577bcc
34a1c29
493bc79
52cda03
42e1dde
39984bd
14afd71
b2fe44b
cebca53
3851bdd
cbdbc91
8b0dd64
ada417f
349101c
9b2683e
07e1c68
e036b04
6987058
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { BaseExecuteArgs, PackageManagerCommand } from './packageManagerCommand'; | ||
|
|
||
| /** | ||
| * Arguments for available versions command execution (change per execution). | ||
| */ | ||
| export interface AvailableVersionsExecuteArgs extends BaseExecuteArgs { | ||
| packageName: string; | ||
| pythonVersion: string; | ||
| includePrerelease?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Template class for availableVersions commands. | ||
| * Subclasses implement concrete package-manager-specific logic. | ||
| */ | ||
| export abstract class AvailableVersionsCommand extends PackageManagerCommand { | ||
| protected static readonly configSection = 'availableVersionsCommandArgs'; | ||
|
|
||
| protected abstract buildCommand(executeArgs: AvailableVersionsExecuteArgs): string[]; | ||
|
|
||
| abstract execute(executeArgs: AvailableVersionsExecuteArgs): Promise<string[]>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export { AvailableVersionsCommand, type AvailableVersionsExecuteArgs } from './availableVersions'; | ||
| export { InstallCommand, type InstallExecuteArgs } from './install'; | ||
| export { ListCommand } from './list'; | ||
| export { ListDirectNamesCommand } from './listDirectNames'; | ||
| export { BaseExecuteArgs, CommandConstructorOptions, PackageManagerCommand } from './packageManagerCommand'; | ||
| export { UninstallCommand, type UninstallExecuteArgs } from './uninstall'; | ||
| export { VersionCommand } from './version'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { BaseExecuteArgs, PackageManagerCommand } from './packageManagerCommand'; | ||
|
|
||
| /** | ||
| * Arguments for install command execution (change per execution). | ||
| */ | ||
| export interface InstallExecuteArgs extends BaseExecuteArgs { | ||
| packages: { packageName: string; version?: string }[]; | ||
| upgrade?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Template class for install commands. | ||
| * Subclasses implement concrete package-manager-specific logic. | ||
| */ | ||
| export abstract class InstallCommand extends PackageManagerCommand { | ||
| protected static readonly configSection = 'installCommandArgs'; | ||
|
|
||
| protected abstract buildCommand(executeArgs: InstallExecuteArgs): string[]; | ||
|
|
||
| abstract execute(executeArgs: InstallExecuteArgs): Promise<void>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { PackageInfo } from '../../../api'; | ||
| import { BaseExecuteArgs, PackageManagerCommand } from './packageManagerCommand'; | ||
|
|
||
| /** | ||
| * Template class for list commands. | ||
| * Subclasses implement concrete package-manager-specific logic. | ||
| */ | ||
| export abstract class ListCommand extends PackageManagerCommand { | ||
| protected static readonly configSection = 'listCommandArgs'; | ||
|
|
||
| abstract execute(executeArgs?: BaseExecuteArgs): Promise<PackageInfo[]>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { BaseExecuteArgs, PackageManagerCommand } from './packageManagerCommand'; | ||
|
|
||
| /** | ||
| * Template class for listDirectNames commands. | ||
| * Subclasses implement concrete package-manager-specific logic. | ||
| */ | ||
| export abstract class ListDirectNamesCommand extends PackageManagerCommand { | ||
| protected static readonly configSection = 'listDirectNamesCommandArgs'; | ||
|
|
||
| abstract execute(executeArgs?: BaseExecuteArgs): Promise<string[]>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { CancellationToken, l10n, LogOutputChannel, ProgressLocation, window, WorkspaceConfiguration } from 'vscode'; | ||
| import { getConfiguration } from '../../../common/workspace.apis'; | ||
|
|
||
| /** | ||
| * Base interface for all command execute arguments. | ||
| * Provides optional cancellation token that all commands can use. | ||
| */ | ||
| export interface BaseExecuteArgs { | ||
| cancellationToken?: CancellationToken; | ||
| showProgress?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor options shared by all package manager commands. | ||
| */ | ||
| export interface CommandConstructorOptions { | ||
| pythonExecutable: string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot generated: [verified] |
||
| log?: LogOutputChannel; | ||
| } | ||
|
|
||
| /** | ||
| * Base class for all package manager commands. | ||
| * Provides common properties and minimal interface for subclasses. | ||
| */ | ||
| export abstract class PackageManagerCommand { | ||
| protected static readonly configSection?: string; | ||
|
|
||
| protected pythonExecutable: string; | ||
| protected log?: LogOutputChannel; | ||
| protected timeout: number = 300000; | ||
|
edvilme marked this conversation as resolved.
|
||
| protected config?: WorkspaceConfiguration; | ||
|
|
||
| constructor(options: CommandConstructorOptions) { | ||
| this.pythonExecutable = options.pythonExecutable; | ||
| this.log = options.log; | ||
| const configSection = (this.constructor as typeof PackageManagerCommand).configSection; | ||
| this.config = configSection ? getConfiguration(`python-envs.packageManager.${configSection}`) : undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Executes this command and optionally wraps execution with a progress indicator. | ||
| */ | ||
| public executeWithProgress<T = unknown, A extends BaseExecuteArgs = BaseExecuteArgs>( | ||
| executeArgs?: A, | ||
| title?: string, | ||
| ): Promise<T> { | ||
| if (!executeArgs?.showProgress) { | ||
| return this.execute(executeArgs) as Promise<T>; | ||
| } | ||
|
|
||
| return Promise.resolve( | ||
| window.withProgress( | ||
| { | ||
| location: ProgressLocation.Notification, | ||
| title: title ?? l10n.t('Running package manager command'), | ||
|
edvilme marked this conversation as resolved.
|
||
| cancellable: true, | ||
| }, | ||
|
Copilot marked this conversation as resolved.
|
||
| (_progress, token) => | ||
| this.execute({ | ||
| ...executeArgs, | ||
| cancellationToken: executeArgs.cancellationToken ?? token, | ||
| }) as Promise<T>, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Subclasses implement command execution. | ||
| */ | ||
| abstract execute(executeArgs?: BaseExecuteArgs): Promise<unknown>; | ||
|
|
||
| /** | ||
| * Subclasses implement to build the command arguments. | ||
| */ | ||
| protected abstract buildCommand(executeArgs: BaseExecuteArgs): string[]; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { BaseExecuteArgs, PackageManagerCommand } from './packageManagerCommand'; | ||
|
|
||
| /** | ||
| * Arguments for uninstall command execution (change per execution). | ||
| */ | ||
| export interface UninstallExecuteArgs extends BaseExecuteArgs { | ||
| packages: { packageName: string; version?: string }[]; | ||
| } | ||
|
|
||
| /** | ||
| * Template class for uninstall commands. | ||
| * Subclasses implement concrete package-manager-specific logic. | ||
| */ | ||
| export abstract class UninstallCommand extends PackageManagerCommand { | ||
| protected static readonly configSection = 'uninstallCommandArgs'; | ||
|
|
||
| protected abstract buildCommand(executeArgs: UninstallExecuteArgs): string[]; | ||
|
|
||
| abstract execute(executeArgs: UninstallExecuteArgs): Promise<void>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { Pep440Version } from '@renovatebot/pep440'; | ||
| import { BaseExecuteArgs, PackageManagerCommand } from './packageManagerCommand'; | ||
|
|
||
| /** | ||
| * Template class for version commands. | ||
| * Subclasses implement concrete package-manager-specific logic. | ||
| */ | ||
| export abstract class VersionCommand extends PackageManagerCommand { | ||
| protected static readonly configSection = 'versionCommandArgs'; | ||
|
|
||
| abstract execute(executeArgs?: BaseExecuteArgs): Promise<Pep440Version | undefined>; | ||
| } |
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.
what do you see as the use cases for these commands?