Path: blob/main/extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIPythonEnvironmentApi.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import {6Disposable,7Event,8FileChangeType,9LogOutputChannel,10MarkdownString,11TaskExecution,12Terminal,13TerminalOptions,14ThemeIcon,15Uri,16} from 'vscode';1718/**19* The path to an icon, or a theme-specific configuration of icons.20*/21export type IconPath =22| Uri23| {24/**25* The icon path for the light theme.26*/27light: Uri;28/**29* The icon path for the dark theme.30*/31dark: Uri;32}33| ThemeIcon;3435/**36* Options for executing a Python executable.37*/38export interface PythonCommandRunConfiguration {39/**40* Path to the binary like `python.exe` or `python3` to execute. This should be an absolute path41* to an executable that can be spawned.42*/43executable: string;4445/**46* Arguments to pass to the python executable. These arguments will be passed on all execute calls.47* This is intended for cases where you might want to do interpreter specific flags.48*/49args?: string[];50}5152/**53* Contains details on how to use a particular python environment54*55* Running In Terminal:56* 1. If {@link PythonEnvironmentExecutionInfo.activatedRun} is provided, then that will be used.57* 2. If {@link PythonEnvironmentExecutionInfo.activatedRun} is not provided, then:58* - If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is known, then that will be used.59* - If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is not known, then:60* - 'unknown' will be used if provided.61* - {@link PythonEnvironmentExecutionInfo.activation} will be used otherwise.62* - If {@link PythonEnvironmentExecutionInfo.shellActivation} is not provided, then {@link PythonEnvironmentExecutionInfo.activation} will be used.63* - If {@link PythonEnvironmentExecutionInfo.activation} is not provided, then {@link PythonEnvironmentExecutionInfo.run} will be used.64*65* Creating a Terminal:66* 1. If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is known, then that will be used.67* 2. If {@link PythonEnvironmentExecutionInfo.shellActivation} is provided and shell type is not known, then {@link PythonEnvironmentExecutionInfo.activation} will be used.68* 3. If {@link PythonEnvironmentExecutionInfo.shellActivation} is not provided, then:69* - 'unknown' will be used if provided.70* - {@link PythonEnvironmentExecutionInfo.activation} will be used otherwise.71* 4. If {@link PythonEnvironmentExecutionInfo.activation} is not provided, then {@link PythonEnvironmentExecutionInfo.run} will be used.72*73*/74export interface PythonEnvironmentExecutionInfo {75/**76* Details on how to run the python executable.77*/78run: PythonCommandRunConfiguration;7980/**81* Details on how to run the python executable after activating the environment.82* If set this will overrides the {@link PythonEnvironmentExecutionInfo.run} command.83*/84activatedRun?: PythonCommandRunConfiguration;8586/**87* Details on how to activate an environment.88*/89activation?: PythonCommandRunConfiguration[];9091/**92* Details on how to activate an environment using a shell specific command.93* If set this will override the {@link PythonEnvironmentExecutionInfo.activation}.94* 'unknown' is used if shell type is not known.95* If 'unknown' is not provided and shell type is not known then96* {@link PythonEnvironmentExecutionInfo.activation} if set.97*/98shellActivation?: Map<string, PythonCommandRunConfiguration[]>;99100/**101* Details on how to deactivate an environment.102*/103deactivation?: PythonCommandRunConfiguration[];104105/**106* Details on how to deactivate an environment using a shell specific command.107* If set this will override the {@link PythonEnvironmentExecutionInfo.deactivation} property.108* 'unknown' is used if shell type is not known.109* If 'unknown' is not provided and shell type is not known then110* {@link PythonEnvironmentExecutionInfo.deactivation} if set.111*/112shellDeactivation?: Map<string, PythonCommandRunConfiguration[]>;113}114115/**116* Interface representing the ID of a Python environment.117*/118export interface PythonEnvironmentId {119/**120* The unique identifier of the Python environment.121*/122id: string;123124/**125* The ID of the manager responsible for the Python environment.126*/127managerId: string;128}129130/**131* Display information for an environment group.132*/133export interface EnvironmentGroupInfo {134/**135* The name of the environment group. This is used as an identifier for the group.136*137* Note: The first instance of the group with the given name will be used in the UI.138*/139readonly name: string;140141/**142* The description of the environment group.143*/144readonly description?: string;145146/**147* The tooltip for the environment group, which can be a string or a Markdown string.148*/149readonly tooltip?: string | MarkdownString;150151/**152* The icon path for the environment group, which can be a string, Uri, or an object with light and dark theme paths.153*/154readonly iconPath?: IconPath;155}156157/**158* Interface representing information about a Python environment.159*/160export interface PythonEnvironmentInfo {161/**162* The name of the Python environment.163*/164readonly name: string;165166/**167* The display name of the Python environment.168*/169readonly displayName: string;170171/**172* The short display name of the Python environment.173*/174readonly shortDisplayName?: string;175176/**177* The display path of the Python environment.178*/179readonly displayPath: string;180181/**182* The version of the Python environment.183*/184readonly version: string;185186/**187* Path to the python binary or environment folder.188*/189readonly environmentPath: Uri;190191/**192* The description of the Python environment.193*/194readonly description?: string;195196/**197* The tooltip for the Python environment, which can be a string or a Markdown string.198*/199readonly tooltip?: string | MarkdownString;200201/**202* The icon path for the Python environment, which can be a string, Uri, or an object with light and dark theme paths.203*/204readonly iconPath?: IconPath;205206/**207* Information on how to execute the Python environment. This is required for executing Python code in the environment.208*/209readonly execInfo: PythonEnvironmentExecutionInfo;210211/**212* `sys.prefix` is the path to the base directory of the Python installation. Typically obtained by executing `sys.prefix` in the Python interpreter.213* This is required by extension like Jupyter, Pylance, and other extensions to provide better experience with python.214*/215readonly sysPrefix: string;216217/**218* Optional `group` for this environment. This is used to group environments in the Environment Manager UI.219*/220readonly group?: string | EnvironmentGroupInfo;221}222223/**224* Interface representing a Python environment.225*/226export interface PythonEnvironment extends PythonEnvironmentInfo {227/**228* The ID of the Python environment.229*/230readonly envId: PythonEnvironmentId;231}232233/**234* Type representing the scope for setting a Python environment.235* Can be undefined or a URI.236*/237export type SetEnvironmentScope = undefined | Uri | Uri[];238239/**240* Type representing the scope for getting a Python environment.241* Can be undefined or a URI.242*/243export type GetEnvironmentScope = undefined | Uri;244245/**246* Type representing the scope for creating a Python environment.247* Can be a Python project or 'global'.248*/249export type CreateEnvironmentScope = Uri | Uri[] | 'global';250/**251* The scope for which environments are to be refreshed.252* - `undefined`: Search for environments globally and workspaces.253* - {@link Uri}: Environments in the workspace/folder or associated with the Uri.254*/255export type RefreshEnvironmentsScope = Uri | undefined;256257/**258* The scope for which environments are required.259* - `"all"`: All environments.260* - `"global"`: Python installations that are usually a base for creating virtual environments.261* - {@link Uri}: Environments for the workspace/folder/file pointed to by the Uri.262*/263export type GetEnvironmentsScope = Uri | 'all' | 'global';264265/**266* Event arguments for when the current Python environment changes.267*/268export type DidChangeEnvironmentEventArgs = {269/**270* The URI of the environment that changed.271*/272readonly uri: Uri | undefined;273274/**275* The old Python environment before the change.276*/277readonly old: PythonEnvironment | undefined;278279/**280* The new Python environment after the change.281*/282readonly new: PythonEnvironment | undefined;283};284285/**286* Enum representing the kinds of environment changes.287*/288export enum EnvironmentChangeKind {289/**290* Indicates that an environment was added.291*/292add = 'add',293294/**295* Indicates that an environment was removed.296*/297remove = 'remove',298}299300/**301* Event arguments for when the list of Python environments changes.302*/303export type DidChangeEnvironmentsEventArgs = {304/**305* The kind of change that occurred (add or remove).306*/307kind: EnvironmentChangeKind;308309/**310* The Python environment that was added or removed.311*/312environment: PythonEnvironment;313}[];314315/**316* Type representing the context for resolving a Python environment.317*/318export type ResolveEnvironmentContext = Uri;319320export interface QuickCreateConfig {321/**322* The description of the quick create step.323*/324readonly description: string;325326/**327* The detail of the quick create step.328*/329readonly detail?: string;330}331332/**333* Interface representing an environment manager.334*/335export interface EnvironmentManager {336/**337* The name of the environment manager. Allowed characters (a-z, A-Z, 0-9, -, _).338*/339readonly name: string;340341/**342* The display name of the environment manager.343*/344readonly displayName?: string;345346/**347* The preferred package manager ID for the environment manager. This is a combination348* of publisher id, extension id, and {@link EnvironmentManager.name package manager name}.349* `<publisher-id>.<extension-id>:<package-manager-name>`350*351* @example352* 'ms-python.python:pip'353*/354readonly preferredPackageManagerId: string;355356/**357* The description of the environment manager.358*/359readonly description?: string;360361/**362* The tooltip for the environment manager, which can be a string or a Markdown string.363*/364readonly tooltip?: string | MarkdownString | undefined;365366/**367* The icon path for the environment manager, which can be a string, Uri, or an object with light and dark theme paths.368*/369readonly iconPath?: IconPath;370371/**372* The log output channel for the environment manager.373*/374readonly log?: LogOutputChannel;375376/**377* The quick create details for the environment manager. Having this method also enables the quick create feature378* for the environment manager. Should Implement {@link EnvironmentManager.create} to support quick create.379*/380quickCreateConfig?(): QuickCreateConfig | undefined;381382/**383* Creates a new Python environment within the specified scope. Create should support adding a .gitignore file if it creates a folder within the workspace. If a manager does not support environment creation, do not implement this method; the UI disables "create" options when `this.manager.create === undefined`.384* @param scope - The scope within which to create the environment.385* @param options - Optional parameters for creating the Python environment.386* @returns A promise that resolves to the created Python environment, or undefined if creation failed.387*/388create?(scope: CreateEnvironmentScope, options?: CreateEnvironmentOptions): Promise<PythonEnvironment | undefined>;389390/**391* Removes the specified Python environment.392* @param environment - The Python environment to remove.393* @returns A promise that resolves when the environment is removed.394*/395remove?(environment: PythonEnvironment): Promise<void>;396397/**398* Refreshes the list of Python environments within the specified scope.399* @param scope - The scope within which to refresh environments.400* @returns A promise that resolves when the refresh is complete.401*/402refresh(scope: RefreshEnvironmentsScope): Promise<void>;403404/**405* Retrieves a list of Python environments within the specified scope.406* @param scope - The scope within which to retrieve environments.407* @returns A promise that resolves to an array of Python environments.408*/409getEnvironments(scope: GetEnvironmentsScope): Promise<PythonEnvironment[]>;410411/**412* Event that is fired when the list of Python environments changes.413*/414onDidChangeEnvironments?: Event<DidChangeEnvironmentsEventArgs>;415416/**417* Sets the current Python environment within the specified scope.418* @param scope - The scope within which to set the environment.419* @param environment - The Python environment to set. If undefined, the environment is unset.420* @returns A promise that resolves when the environment is set.421*/422set(scope: SetEnvironmentScope, environment?: PythonEnvironment): Promise<void>;423424/**425* Retrieves the current Python environment within the specified scope.426* @param scope - The scope within which to retrieve the environment.427* @returns A promise that resolves to the current Python environment, or undefined if none is set.428*/429get(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined>;430431/**432* Event that is fired when the current Python environment changes.433*/434onDidChangeEnvironment?: Event<DidChangeEnvironmentEventArgs>;435436/**437* Resolves the specified Python environment. The environment can be either a {@link PythonEnvironment} or a {@link Uri} context.438*439* This method is used to obtain a fully detailed {@link PythonEnvironment} object. The input can be:440* - A {@link PythonEnvironment} object, which might be missing key details such as {@link PythonEnvironment.execInfo}.441* - A {@link Uri} object, which typically represents either:442* - A folder that contains the Python environment.443* - The path to a Python executable.444*445* @param context - The context for resolving the environment, which can be a {@link PythonEnvironment} or a {@link Uri}.446* @returns A promise that resolves to the fully detailed {@link PythonEnvironment}, or `undefined` if the environment cannot be resolved.447*/448resolve(context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined>;449450/**451* Clears the environment manager's cache.452*453* @returns A promise that resolves when the cache is cleared.454*/455clearCache?(): Promise<void>;456}457458/**459* Interface representing a package ID.460*/461export interface PackageId {462/**463* The ID of the package.464*/465id: string;466467/**468* The ID of the package manager.469*/470managerId: string;471472/**473* The ID of the environment in which the package is installed.474*/475environmentId: string;476}477478/**479* Interface representing package information.480*/481export interface PackageInfo {482/**483* The name of the package.484*/485readonly name: string;486487/**488* The display name of the package.489*/490readonly displayName: string;491492/**493* The version of the package.494*/495readonly version?: string;496497/**498* The description of the package.499*/500readonly description?: string;501502/**503* The tooltip for the package, which can be a string or a Markdown string.504*/505readonly tooltip?: string | MarkdownString | undefined;506507/**508* The icon path for the package, which can be a string, Uri, or an object with light and dark theme paths.509*/510readonly iconPath?: IconPath;511512/**513* The URIs associated with the package.514*/515readonly uris?: readonly Uri[];516}517518/**519* Interface representing a package.520*/521export interface Package extends PackageInfo {522/**523* The ID of the package.524*/525readonly pkgId: PackageId;526}527528/**529* Enum representing the kinds of package changes.530*/531export enum PackageChangeKind {532/**533* Indicates that a package was added.534*/535add = 'add',536537/**538* Indicates that a package was removed.539*/540remove = 'remove',541}542543/**544* Event arguments for when packages change.545*/546export interface DidChangePackagesEventArgs {547/**548* The Python environment in which the packages changed.549*/550environment: PythonEnvironment;551552/**553* The package manager responsible for the changes.554*/555manager: PackageManager;556557/**558* The list of changes, each containing the kind of change and the package affected.559*/560changes: { kind: PackageChangeKind; pkg: Package }[];561}562563/**564* Interface representing a package manager.565*/566export interface PackageManager {567/**568* The name of the package manager. Allowed characters (a-z, A-Z, 0-9, -, _).569*/570name: string;571572/**573* The display name of the package manager.574*/575displayName?: string;576577/**578* The description of the package manager.579*/580description?: string;581582/**583* The tooltip for the package manager, which can be a string or a Markdown string.584*/585tooltip?: string | MarkdownString | undefined;586587/**588* The icon path for the package manager, which can be a string, Uri, or an object with light and dark theme paths.589*/590iconPath?: IconPath;591592/**593* The log output channel for the package manager.594*/595log?: LogOutputChannel;596597/**598* Installs/Uninstall packages in the specified Python environment.599* @param environment - The Python environment in which to install packages.600* @param options - Options for managing packages.601* @returns A promise that resolves when the installation is complete.602*/603manage(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void>;604605/**606* Refreshes the package list for the specified Python environment.607* @param environment - The Python environment for which to refresh the package list.608* @returns A promise that resolves when the refresh is complete.609*/610refresh(environment: PythonEnvironment): Promise<void>;611612/**613* Retrieves the list of packages for the specified Python environment.614* @param environment - The Python environment for which to retrieve packages.615* @returns An array of packages, or undefined if the packages could not be retrieved.616*/617getPackages(environment: PythonEnvironment): Promise<Package[] | undefined>;618619/**620* Event that is fired when packages change.621*/622onDidChangePackages?: Event<DidChangePackagesEventArgs>;623624/**625* Clears the package manager's cache.626* @returns A promise that resolves when the cache is cleared.627*/628clearCache?(): Promise<void>;629}630631/**632* Interface representing a Python project.633*/634export interface PythonProject {635/**636* The name of the Python project.637*/638readonly name: string;639640/**641* The URI of the Python project.642*/643readonly uri: Uri;644645/**646* The description of the Python project.647*/648readonly description?: string;649650/**651* The tooltip for the Python project, which can be a string or a Markdown string.652*/653readonly tooltip?: string | MarkdownString;654}655656/**657* Options for creating a Python project.658*/659export interface PythonProjectCreatorOptions {660/**661* The name of the Python project.662*/663name: string;664665/**666* Path provided as the root for the project.667*/668rootUri: Uri;669670/**671* Boolean indicating whether the project should be created without any user input.672*/673quickCreate?: boolean;674}675676/**677* Interface representing a creator for Python projects.678*/679export interface PythonProjectCreator {680/**681* The name of the Python project creator.682*/683readonly name: string;684685/**686* The display name of the Python project creator.687*/688readonly displayName?: string;689690/**691* The description of the Python project creator.692*/693readonly description?: string;694695/**696* The tooltip for the Python project creator, which can be a string or a Markdown string.697*/698readonly tooltip?: string | MarkdownString;699700/**701* Creates a new Python project(s) or, if files are not a project, returns Uri(s) to the created files.702* Anything that needs its own python environment constitutes a project.703* @param options Optional parameters for creating the Python project.704* @returns A promise that resolves to one of the following:705* - PythonProject or PythonProject[]: when a single or multiple projects are created.706* - Uri or Uri[]: when files are created that do not constitute a project.707* - undefined: if project creation fails.708*/709create(options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | Uri | Uri[] | undefined>;710711/**712* A flag indicating whether the project creator supports quick create where no user input is required.713*/714readonly supportsQuickCreate?: boolean;715}716717/**718* Event arguments for when Python projects change.719*/720export interface DidChangePythonProjectsEventArgs {721/**722* The list of Python projects that were added.723*/724added: PythonProject[];725726/**727* The list of Python projects that were removed.728*/729removed: PythonProject[];730}731732export type PackageManagementOptions =733| {734/**735* Upgrade the packages if they are already installed.736*/737upgrade?: boolean;738739/**740* Show option to skip package installation or uninstallation.741*/742showSkipOption?: boolean;743/**744* The list of packages to install.745*/746install: string[];747748/**749* The list of packages to uninstall.750*/751uninstall?: string[];752}753| {754/**755* Upgrade the packages if they are already installed.756*/757upgrade?: boolean;758759/**760* Show option to skip package installation or uninstallation.761*/762showSkipOption?: boolean;763/**764* The list of packages to install.765*/766install?: string[];767768/**769* The list of packages to uninstall.770*/771uninstall: string[];772};773774/**775* Options for creating a Python environment.776*/777export interface CreateEnvironmentOptions {778/**779* Provides some context about quick create based on user input.780* - if true, the environment should be created without any user input or prompts.781* - if false, the environment creation can show user input or prompts.782* This also means user explicitly skipped the quick create option.783* - if undefined, the environment creation can show user input or prompts.784* You can show quick create option to the user if you support it.785*/786quickCreate?: boolean;787/**788* Packages to install in addition to the automatically picked packages as a part of creating environment.789*/790additionalPackages?: string[];791}792793/**794* Object representing the process started using run in background API.795*/796export interface PythonProcess {797/**798* The process ID of the Python process.799*/800readonly pid?: number;801802/**803* The standard input of the Python process.804*/805readonly stdin: NodeJS.WritableStream;806807/**808* The standard output of the Python process.809*/810readonly stdout: NodeJS.ReadableStream;811812/**813* The standard error of the Python process.814*/815readonly stderr: NodeJS.ReadableStream;816817/**818* Kills the Python process.819*/820kill(): void;821822/**823* Event that is fired when the Python process exits.824*/825onExit(listener: (code: number | null, signal: NodeJS.Signals | null) => void): void;826}827828export interface PythonEnvironmentManagerRegistrationApi {829/**830* Register an environment manager implementation.831*832* @param manager Environment Manager implementation to register.833* @returns A disposable that can be used to unregister the environment manager.834* @see {@link EnvironmentManager}835*/836registerEnvironmentManager(manager: EnvironmentManager): Disposable;837}838839export interface PythonEnvironmentItemApi {840/**841* Create a Python environment item from the provided environment info. This item is used to interact842* with the environment.843*844* @param info Some details about the environment like name, version, etc. needed to interact with the environment.845* @param manager The environment manager to associate with the environment.846* @returns The Python environment.847*/848createPythonEnvironmentItem(info: PythonEnvironmentInfo, manager: EnvironmentManager): PythonEnvironment;849}850851export interface PythonEnvironmentManagementApi {852/**853* Create a Python environment using environment manager associated with the scope.854*855* @param scope Where the environment is to be created.856* @param options Optional parameters for creating the Python environment.857* @returns The Python environment created. `undefined` if not created.858*/859createEnvironment(860scope: CreateEnvironmentScope,861options?: CreateEnvironmentOptions,862): Promise<PythonEnvironment | undefined>;863864/**865* Remove a Python environment.866*867* @param environment The Python environment to remove.868* @returns A promise that resolves when the environment has been removed.869*/870removeEnvironment(environment: PythonEnvironment): Promise<void>;871}872873export interface PythonEnvironmentsApi {874/**875* Initiates a refresh of Python environments within the specified scope.876* @param scope - The scope within which to search for environments.877* @returns A promise that resolves when the search is complete.878*/879refreshEnvironments(scope: RefreshEnvironmentsScope): Promise<void>;880881/**882* Retrieves a list of Python environments within the specified scope.883* @param scope - The scope within which to retrieve environments.884* @returns A promise that resolves to an array of Python environments.885*/886getEnvironments(scope: GetEnvironmentsScope): Promise<PythonEnvironment[]>;887888/**889* Event that is fired when the list of Python environments changes.890* @see {@link DidChangeEnvironmentsEventArgs}891*/892onDidChangeEnvironments: Event<DidChangeEnvironmentsEventArgs>;893894/**895* This method is used to get the details missing from a PythonEnvironment. Like896* {@link PythonEnvironment.execInfo} and other details.897*898* @param context : The PythonEnvironment or Uri for which details are required.899*/900resolveEnvironment(context: ResolveEnvironmentContext): Promise<PythonEnvironment | undefined>;901}902903export interface PythonProjectEnvironmentApi {904/**905* Sets the current Python environment within the specified scope.906* @param scope - The scope within which to set the environment.907* @param environment - The Python environment to set. If undefined, the environment is unset.908*/909setEnvironment(scope: SetEnvironmentScope, environment?: PythonEnvironment): Promise<void>;910911/**912* Retrieves the current Python environment within the specified scope.913* @param scope - The scope within which to retrieve the environment.914* @returns A promise that resolves to the current Python environment, or undefined if none is set.915*/916getEnvironment(scope: GetEnvironmentScope): Promise<PythonEnvironment | undefined>;917918/**919* Event that is fired when the selected Python environment changes for Project, Folder or File.920* @see {@link DidChangeEnvironmentEventArgs}921*/922onDidChangeEnvironment: Event<DidChangeEnvironmentEventArgs>;923}924925export interface PythonEnvironmentManagerApi926extends PythonEnvironmentManagerRegistrationApi,927PythonEnvironmentItemApi,928PythonEnvironmentManagementApi,929PythonEnvironmentsApi,930PythonProjectEnvironmentApi { }931932export interface PythonPackageManagerRegistrationApi {933/**934* Register a package manager implementation.935*936* @param manager Package Manager implementation to register.937* @returns A disposable that can be used to unregister the package manager.938* @see {@link PackageManager}939*/940registerPackageManager(manager: PackageManager): Disposable;941}942943export interface PythonPackageGetterApi {944/**945* Refresh the list of packages in a Python Environment.946*947* @param environment The Python Environment for which the list of packages is to be refreshed.948* @returns A promise that resolves when the list of packages has been refreshed.949*/950refreshPackages(environment: PythonEnvironment): Promise<void>;951952/**953* Get the list of packages in a Python Environment.954*955* @param environment The Python Environment for which the list of packages is required.956* @returns The list of packages in the Python Environment.957*/958getPackages(environment: PythonEnvironment): Promise<Package[] | undefined>;959960/**961* Event raised when the list of packages in a Python Environment changes.962* @see {@link DidChangePackagesEventArgs}963*/964onDidChangePackages: Event<DidChangePackagesEventArgs>;965}966967export interface PythonPackageItemApi {968/**969* Create a package item from the provided package info.970*971* @param info The package info.972* @param environment The Python Environment in which the package is installed.973* @param manager The package manager that installed the package.974* @returns The package item.975*/976createPackageItem(info: PackageInfo, environment: PythonEnvironment, manager: PackageManager): Package;977}978979export interface PythonPackageManagementApi {980/**981* Install/Uninstall packages into a Python Environment.982*983* @param environment The Python Environment into which packages are to be installed.984* @param packages The packages to install.985* @param options Options for installing packages.986*/987managePackages(environment: PythonEnvironment, options: PackageManagementOptions): Promise<void>;988}989990export interface PythonPackageManagerApi991extends PythonPackageManagerRegistrationApi,992PythonPackageGetterApi,993PythonPackageManagementApi,994PythonPackageItemApi { }995996export interface PythonProjectCreationApi {997/**998* Register a Python project creator.999*1000* @param creator The project creator to register.1001* @returns A disposable that can be used to unregister the project creator.1002* @see {@link PythonProjectCreator}1003*/1004registerPythonProjectCreator(creator: PythonProjectCreator): Disposable;1005}1006export interface PythonProjectGetterApi {1007/**1008* Get all python projects.1009*/1010getPythonProjects(): readonly PythonProject[];10111012/**1013* Get the python project for a given URI.1014*1015* @param uri The URI of the project1016* @returns The project or `undefined` if not found.1017*/1018getPythonProject(uri: Uri): PythonProject | undefined;1019}10201021export interface PythonProjectModifyApi {1022/**1023* Add a python project or projects to the list of projects.1024*1025* @param projects The project or projects to add.1026*/1027addPythonProject(projects: PythonProject | PythonProject[]): void;10281029/**1030* Remove a python project from the list of projects.1031*1032* @param project The project to remove.1033*/1034removePythonProject(project: PythonProject): void;10351036/**1037* Event raised when python projects are added or removed.1038* @see {@link DidChangePythonProjectsEventArgs}1039*/1040onDidChangePythonProjects: Event<DidChangePythonProjectsEventArgs>;1041}10421043/**1044* The API for interacting with Python projects. A project in python is any folder or file that is a contained1045* in some manner. For example, a PEP-723 compliant file can be treated as a project. A folder with a `pyproject.toml`,1046* or just python files can be treated as a project. All this allows you to do is set a python environment for that project.1047*1048* By default all `vscode.workspace.workspaceFolders` are treated as projects.1049*/1050export interface PythonProjectApi extends PythonProjectCreationApi, PythonProjectGetterApi, PythonProjectModifyApi { }10511052export interface PythonTerminalCreateOptions extends TerminalOptions {1053/**1054* Whether to disable activation on create.1055*/1056disableActivation?: boolean;1057}10581059export interface PythonTerminalCreateApi {1060/**1061* Creates a terminal and activates any (activatable) environment for the terminal.1062*1063* @param environment The Python environment to activate.1064* @param options Options for creating the terminal.1065*1066* Note: Non-activatable environments have no effect on the terminal.1067*/1068createTerminal(environment: PythonEnvironment, options: PythonTerminalCreateOptions): Promise<Terminal>;1069}10701071/**1072* Options for running a Python script or module in a terminal.1073*1074* Example:1075* * Running Script: `python myscript.py --arg1`1076* ```typescript1077* {1078* args: ["myscript.py", "--arg1"]1079* }1080* ```1081* * Running a module: `python -m my_module --arg1`1082* ```typescript1083* {1084* args: ["-m", "my_module", "--arg1"]1085* }1086* ```1087*/1088export interface PythonTerminalExecutionOptions {1089/**1090* Current working directory for the terminal. This in only used to create the terminal.1091*/1092cwd: string | Uri;10931094/**1095* Arguments to pass to the python executable.1096*/1097args?: string[];10981099/**1100* Set `true` to show the terminal.1101*/1102show?: boolean;1103}11041105export interface PythonTerminalRunApi {1106/**1107* Runs a Python script or module in a terminal. This API will create a terminal if one is not available to use.1108* If a terminal is available, it will be used to run the script or module.1109*1110* Note:1111* - If you restart VS Code, this will create a new terminal, this is a limitation of VS Code.1112* - If you close the terminal, this will create a new terminal.1113* - In cases of multi-root/project scenario, it will create a separate terminal for each project.1114*/1115runInTerminal(environment: PythonEnvironment, options: PythonTerminalExecutionOptions): Promise<Terminal>;11161117/**1118* Runs a Python script or module in a dedicated terminal. This API will create a terminal if one is not available to use.1119* If a terminal is available, it will be used to run the script or module. This terminal will be dedicated to the script,1120* and selected based on the `terminalKey`.1121*1122* @param terminalKey A unique key to identify the terminal. For scripts you can use the Uri of the script file.1123*/1124runInDedicatedTerminal(1125terminalKey: Uri | string,1126environment: PythonEnvironment,1127options: PythonTerminalExecutionOptions,1128): Promise<Terminal>;1129}11301131/**1132* Options for running a Python task.1133*1134* Example:1135* * Running Script: `python myscript.py --arg1`1136* ```typescript1137* {1138* args: ["myscript.py", "--arg1"]1139* }1140* ```1141* * Running a module: `python -m my_module --arg1`1142* ```typescript1143* {1144* args: ["-m", "my_module", "--arg1"]1145* }1146* ```1147*/1148export interface PythonTaskExecutionOptions {1149/**1150* Name of the task to run.1151*/1152name: string;11531154/**1155* Arguments to pass to the python executable.1156*/1157args: string[];11581159/**1160* The Python project to use for the task.1161*/1162project?: PythonProject;11631164/**1165* Current working directory for the task. Default is the project directory for the script being run.1166*/1167cwd?: string;11681169/**1170* Environment variables to set for the task.1171*/1172env?: { [key: string]: string };1173}11741175export interface PythonTaskRunApi {1176/**1177* Run a Python script or module as a task.1178*1179*/1180runAsTask(environment: PythonEnvironment, options: PythonTaskExecutionOptions): Promise<TaskExecution>;1181}11821183/**1184* Options for running a Python script or module in the background.1185*/1186export interface PythonBackgroundRunOptions {1187/**1188* The Python environment to use for running the script or module.1189*/1190args: string[];11911192/**1193* Current working directory for the script or module. Default is the project directory for the script being run.1194*/1195cwd?: string;11961197/**1198* Environment variables to set for the script or module.1199*/1200env?: { [key: string]: string | undefined };1201}1202export interface PythonBackgroundRunApi {1203/**1204* Run a Python script or module in the background. This API will create a new process to run the script or module.1205*/1206runInBackground(environment: PythonEnvironment, options: PythonBackgroundRunOptions): Promise<PythonProcess>;1207}12081209export interface PythonExecutionApi1210extends PythonTerminalCreateApi,1211PythonTerminalRunApi,1212PythonTaskRunApi,1213PythonBackgroundRunApi { }12141215/**1216* Event arguments for when the monitored `.env` files or any other sources change.1217*/1218export interface DidChangeEnvironmentVariablesEventArgs {1219/**1220* The URI of the file that changed. No `Uri` means a non-file source of environment variables changed.1221*/1222uri?: Uri;12231224/**1225* The type of change that occurred.1226*/1227changeType: FileChangeType;1228}12291230export interface PythonEnvironmentVariablesApi {1231/**1232* Get environment variables for a workspace. This picks up `.env` file from the root of the1233* workspace.1234*1235* Order of overrides:1236* 1. `baseEnvVar` if given or `process.env`1237* 2. `.env` file from the "python.envFile" setting in the workspace.1238* 3. `.env` file at the root of the python project.1239* 4. `overrides` in the order provided.1240*1241* @param uri The URI of the project, workspace or a file in a for which environment variables are required.If not provided,1242* it fetches the environment variables for the global scope.1243* @param overrides Additional environment variables to override the defaults.1244* @param baseEnvVar The base environment variables that should be used as a starting point.1245*/1246getEnvironmentVariables(1247uri: Uri | undefined,1248overrides?: ({ [key: string]: string | undefined } | Uri)[],1249baseEnvVar?: { [key: string]: string | undefined },1250): Promise<{ [key: string]: string | undefined }>;12511252/**1253* Event raised when `.env` file changes or any other monitored source of env variable changes.1254*/1255onDidChangeEnvironmentVariables: Event<DidChangeEnvironmentVariablesEventArgs>;1256}12571258/**1259* The API for interacting with Python environments, package managers, and projects.1260*/1261export interface PythonEnvironmentApi1262extends PythonEnvironmentManagerApi,1263PythonPackageManagerApi,1264PythonProjectApi,1265PythonExecutionApi,1266PythonEnvironmentVariablesApi { }126712681269