@vscode/python-environments 1.0.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/out/cjs/main.cjs +101 -0
- package/out/{main.d.ts → cjs/main.d.ts} +177 -13
- package/out/esm/main.d.ts +1316 -0
- package/out/esm/main.mjs +96 -0
- package/package.json +22 -5
- package/out/main.js +0 -54
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `@vscode/python-environments` API package are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.3.0]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Added `PackageVersionLookupNotSupportedError`, thrown when a package manager cannot list a package's available versions (an unsupported capability, as distinct from an operational failure). The error exposes a stable `code` (`'PackageVersionLookupNotSupported'`) discriminator.
|
|
13
|
+
- Added the `isPackageVersionLookupNotSupportedError(error): error is PackageVersionLookupNotSupportedError` type guard. It recognizes the error via its stable `code`, so it works even when the error crosses an extension bundle boundary and `instanceof` would fail.
|
|
14
|
+
- Added an optional `errorMode` to `PythonPackageGetterApi.getPackageAvailableVersions`. The default `legacy` mode preserves the existing `undefined` result for unsupported lookups and operational failures. The opt-in `throw` mode rejects with `PackageVersionLookupNotSupportedError` for unsupported capabilities and propagates operational failures unchanged.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Documented that `PackageManager.getPackageAvailableVersions` implementations should throw `PackageVersionLookupNotSupportedError` when version lookup is unsupported and let operational failures propagate. Resolving to `undefined` continues to be treated by callers as an unsupported capability.
|
|
19
|
+
|
|
20
|
+
## [1.2.0]
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Added `PackageManagementInteractionOptions` with an optional `runHeadless?: boolean` property, mixed into `PackageManagementOptions`. When `true`, package management operations run without any user prompts or interaction — steps that would normally require input, such as selecting packages to install when none are specified, are skipped instead of prompting — for automated or headless scenarios such as integration tests.
|
|
25
|
+
- Added `RemoveEnvironmentOptions` with an optional `runHeadless?: boolean` property to remove environments without a confirmation prompt in automated or headless scenarios.
|
|
26
|
+
|
|
27
|
+
## [1.1.0]
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- Re-exported the `Pep440Version` type from `@renovatebot/pep440` for use with the new package version APIs.
|
|
32
|
+
- Added the optional `PackageInfo.isTransitive?: boolean` property to indicate whether a package is a transitive dependency.
|
|
33
|
+
- Added `GetPackagesOptions` with an optional `skipCache?: boolean` property. When `true`, package managers bypass cached data and query the underlying package management tool.
|
|
34
|
+
- Added optional `PackageManager.getPackageWatchTargets?(environment: PythonEnvironment): RelativePattern[]` to return manager-specific filesystem patterns to monitor for package installation and removal changes, in addition to the default site-packages metadata locations.
|
|
35
|
+
- Added optional `PackageManager.getDirectPackageNames?(environment: PythonEnvironment): Promise<Set<string> | undefined>` to return a best-effort set of direct, non-transitive package names when supported by the package manager.
|
|
36
|
+
- Added optional `PackageManager.getVersion?(environment: PythonEnvironment): Promise<Pep440Version | undefined>` to return the version of the underlying package management tool, such as pip, uv, or conda.
|
|
37
|
+
- Added optional `PackageManager.getPackageAvailableVersions?(environment: PythonEnvironment, packageName: string): Promise<Pep440Version[] | undefined>` to return the available versions of a package in newest-first order when supported.
|
|
38
|
+
- Added optional `PackageManager.formatInstallSpec?(packageName: string, version: string): string` to format a versioned install specification using manager-specific syntax, such as `name==version` for pip or `name=version` for conda.
|
|
39
|
+
- Added `PythonPackageGetterApi.getPackageAvailableVersions(environment: PythonEnvironment, packageName: string): Promise<Pep440Version[] | undefined>` so API consumers can query a package's available versions in newest-first order. Resolves to `undefined` when the environment's package manager does not support version listing.
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- Added the optional `options?: GetPackagesOptions` parameter to `PackageManager.getPackages(environment, options?)` and `PythonPackageGetterApi.getPackages(environment, options?)`. Consumers can set `options.skipCache` to request fresh package data.
|
package/out/cjs/main.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.PythonEnvironments = exports.EXTENSION_ID = exports.PackageVersionLookupNotSupportedError = exports.PackageChangeKind = exports.EnvironmentChangeKind = void 0;
|
|
6
|
+
exports.isPackageVersionLookupNotSupportedError = isPackageVersionLookupNotSupportedError;
|
|
7
|
+
const vscode_1 = require("vscode");
|
|
8
|
+
/**
|
|
9
|
+
* Enum representing the kinds of environment changes.
|
|
10
|
+
*/
|
|
11
|
+
var EnvironmentChangeKind;
|
|
12
|
+
(function (EnvironmentChangeKind) {
|
|
13
|
+
/**
|
|
14
|
+
* Indicates that an environment was added.
|
|
15
|
+
*/
|
|
16
|
+
EnvironmentChangeKind["add"] = "add";
|
|
17
|
+
/**
|
|
18
|
+
* Indicates that an environment was removed.
|
|
19
|
+
*/
|
|
20
|
+
EnvironmentChangeKind["remove"] = "remove";
|
|
21
|
+
})(EnvironmentChangeKind || (exports.EnvironmentChangeKind = EnvironmentChangeKind = {}));
|
|
22
|
+
/**
|
|
23
|
+
* Enum representing the kinds of package changes.
|
|
24
|
+
*/
|
|
25
|
+
var PackageChangeKind;
|
|
26
|
+
(function (PackageChangeKind) {
|
|
27
|
+
/**
|
|
28
|
+
* Indicates that a package was added.
|
|
29
|
+
*/
|
|
30
|
+
PackageChangeKind["add"] = "add";
|
|
31
|
+
/**
|
|
32
|
+
* Indicates that a package was removed.
|
|
33
|
+
*/
|
|
34
|
+
PackageChangeKind["remove"] = "remove";
|
|
35
|
+
})(PackageChangeKind || (exports.PackageChangeKind = PackageChangeKind = {}));
|
|
36
|
+
/**
|
|
37
|
+
* Error thrown when a package manager cannot list available package versions.
|
|
38
|
+
*
|
|
39
|
+
* This distinguishes an *unsupported capability* from an *operational failure* (such as a
|
|
40
|
+
* failed command, a network error, or malformed/unparseable output). Consumers of
|
|
41
|
+
* {@link PythonPackageGetterApi.getPackageAvailableVersions} should treat this specific error
|
|
42
|
+
* as a signal to fall back to manual version entry, while letting any other error propagate.
|
|
43
|
+
*
|
|
44
|
+
* The {@link code} property carries a stable, string-literal discriminator so the error can be
|
|
45
|
+
* recognized reliably across extension bundle boundaries, where `instanceof` may fail because
|
|
46
|
+
* each bundle can load its own copy of this class. Prefer {@link isPackageVersionLookupNotSupportedError}
|
|
47
|
+
* over a bare `instanceof` check for that reason.
|
|
48
|
+
*/
|
|
49
|
+
class PackageVersionLookupNotSupportedError extends Error {
|
|
50
|
+
constructor(message) {
|
|
51
|
+
super(message ?? 'The package manager does not support looking up available package versions.');
|
|
52
|
+
/**
|
|
53
|
+
* Stable discriminator identifying this error type across bundle boundaries.
|
|
54
|
+
*/
|
|
55
|
+
this.code = 'PackageVersionLookupNotSupported';
|
|
56
|
+
this.name = 'PackageVersionLookupNotSupportedError';
|
|
57
|
+
// Preserve the prototype chain when this class is transpiled to older targets so that
|
|
58
|
+
// `instanceof` continues to work within a single bundle.
|
|
59
|
+
Object.setPrototypeOf(this, PackageVersionLookupNotSupportedError.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.PackageVersionLookupNotSupportedError = PackageVersionLookupNotSupportedError;
|
|
63
|
+
/**
|
|
64
|
+
* Type guard reporting whether an error represents unsupported package version lookup.
|
|
65
|
+
*
|
|
66
|
+
* Uses the stable {@link PackageVersionLookupNotSupportedError.code} discriminator, so it returns
|
|
67
|
+
* `true` even when the error crossed an extension bundle boundary and `instanceof` would fail.
|
|
68
|
+
*
|
|
69
|
+
* @param error The value to test.
|
|
70
|
+
* @returns `true` if `error` is a {@link PackageVersionLookupNotSupportedError} (or a structurally
|
|
71
|
+
* equivalent error carrying the same `code`).
|
|
72
|
+
*/
|
|
73
|
+
function isPackageVersionLookupNotSupportedError(error) {
|
|
74
|
+
return (error instanceof PackageVersionLookupNotSupportedError ||
|
|
75
|
+
(typeof error === 'object' &&
|
|
76
|
+
error !== null &&
|
|
77
|
+
'code' in error &&
|
|
78
|
+
error.code === 'PackageVersionLookupNotSupported'));
|
|
79
|
+
}
|
|
80
|
+
exports.EXTENSION_ID = 'ms-python.vscode-python-envs';
|
|
81
|
+
var PythonEnvironments;
|
|
82
|
+
(function (PythonEnvironments) {
|
|
83
|
+
/**
|
|
84
|
+
* Returns the API exposed by the Python Environments extension in VS Code.
|
|
85
|
+
*/
|
|
86
|
+
async function api() {
|
|
87
|
+
const extension = vscode_1.extensions.getExtension(exports.EXTENSION_ID);
|
|
88
|
+
if (extension === undefined) {
|
|
89
|
+
throw new Error(`Python Environments extension (${exports.EXTENSION_ID}) is not installed or is disabled`);
|
|
90
|
+
}
|
|
91
|
+
if (!extension.isActive) {
|
|
92
|
+
await extension.activate();
|
|
93
|
+
}
|
|
94
|
+
const api = extension.exports;
|
|
95
|
+
if (!api) {
|
|
96
|
+
throw new Error(`Python Environments extension (${exports.EXTENSION_ID}) did not expose its API. Ensure "python.useEnvironmentsExtension" is enabled and reload the window.`);
|
|
97
|
+
}
|
|
98
|
+
return api;
|
|
99
|
+
}
|
|
100
|
+
PythonEnvironments.api = api;
|
|
101
|
+
})(PythonEnvironments || (exports.PythonEnvironments = PythonEnvironments = {}));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Pep440Version } from '@renovatebot/pep440';
|
|
2
|
+
import type { Disposable, Event, FileChangeType, LogOutputChannel, MarkdownString, RelativePattern, TaskExecution, Terminal, TerminalOptions, ThemeIcon, Uri } from 'vscode';
|
|
3
|
+
export type { Pep440Version } from '@renovatebot/pep440';
|
|
2
4
|
/**
|
|
3
5
|
* The path to an icon, or a theme-specific configuration of icons.
|
|
4
6
|
*/
|
|
@@ -274,6 +276,16 @@ export interface QuickCreateConfig {
|
|
|
274
276
|
*/
|
|
275
277
|
readonly detail?: string;
|
|
276
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Options controlling environment removal.
|
|
281
|
+
*/
|
|
282
|
+
export interface RemoveEnvironmentOptions {
|
|
283
|
+
/**
|
|
284
|
+
* When `true`, removes the environment without prompting for confirmation.
|
|
285
|
+
* Intended for automated or headless scenarios. Defaults to `false`.
|
|
286
|
+
*/
|
|
287
|
+
runHeadless?: boolean;
|
|
288
|
+
}
|
|
277
289
|
/**
|
|
278
290
|
* Interface representing an environment manager.
|
|
279
291
|
*
|
|
@@ -345,7 +357,7 @@ export interface EnvironmentManager {
|
|
|
345
357
|
* Invoked to delete the given environment. Typical triggers include an explicit user
|
|
346
358
|
* action (such as a "Delete Environment" command) and programmatic removal via the API.
|
|
347
359
|
*/
|
|
348
|
-
remove?(environment: PythonEnvironment): Promise<void>;
|
|
360
|
+
remove?(environment: PythonEnvironment, options?: RemoveEnvironmentOptions): Promise<void>;
|
|
349
361
|
/**
|
|
350
362
|
* Refreshes the list of Python environments within the specified scope.
|
|
351
363
|
* @param scope - The scope within which to refresh environments.
|
|
@@ -484,6 +496,10 @@ export interface PackageInfo {
|
|
|
484
496
|
* The URIs associated with the package.
|
|
485
497
|
*/
|
|
486
498
|
readonly uris?: readonly Uri[];
|
|
499
|
+
/**
|
|
500
|
+
* Whether the package is a transitive dependency.
|
|
501
|
+
*/
|
|
502
|
+
readonly isTransitive?: boolean;
|
|
487
503
|
}
|
|
488
504
|
/**
|
|
489
505
|
* Interface representing a package.
|
|
@@ -571,18 +587,79 @@ export interface PackageManager {
|
|
|
571
587
|
/**
|
|
572
588
|
* Retrieves the list of packages for the specified Python environment.
|
|
573
589
|
* @param environment - The Python environment for which to retrieve packages.
|
|
590
|
+
* @param options - Optional settings for package retrieval.
|
|
574
591
|
* @returns An array of packages, or undefined if the packages could not be retrieved.
|
|
575
592
|
*/
|
|
576
|
-
getPackages(environment: PythonEnvironment): Promise<Package[] | undefined>;
|
|
593
|
+
getPackages(environment: PythonEnvironment, options?: GetPackagesOptions): Promise<Package[] | undefined>;
|
|
594
|
+
/**
|
|
595
|
+
* Returns additional filesystem patterns to watch for package install/uninstall changes.
|
|
596
|
+
*
|
|
597
|
+
* These patterns are appended to the default site-packages metadata locations.
|
|
598
|
+
* Implement this for manager-specific locations (for example, conda-meta).
|
|
599
|
+
*
|
|
600
|
+
* @param environment - The Python environment whose package paths should be watched.
|
|
601
|
+
* @returns Relative patterns to watch for package changes.
|
|
602
|
+
*/
|
|
603
|
+
getPackageWatchTargets?(environment: PythonEnvironment): RelativePattern[];
|
|
577
604
|
/**
|
|
578
605
|
* Event that is fired when packages change.
|
|
579
606
|
*/
|
|
580
607
|
onDidChangePackages?: Event<DidChangePackagesEventArgs>;
|
|
608
|
+
/**
|
|
609
|
+
* Fetches the names of direct (non-transitive) packages for the specified Python environment.
|
|
610
|
+
*
|
|
611
|
+
* **Caveat:** Most package managers cannot track user install intent. For pip, this uses
|
|
612
|
+
* `pip list --not-required` which returns packages with no installed dependents (leaf packages),
|
|
613
|
+
* not necessarily packages the user explicitly installed. For example, if a user runs
|
|
614
|
+
* `pip install flask werkzeug`, werkzeug will still be reported as transitive because flask
|
|
615
|
+
* depends on it. This is a best-effort approximation.
|
|
616
|
+
*
|
|
617
|
+
* @param environment - The Python environment for which to fetch direct package names.
|
|
618
|
+
* @returns A promise that resolves to a set of package name strings, or undefined if not supported.
|
|
619
|
+
*/
|
|
620
|
+
getDirectPackageNames?(environment: PythonEnvironment): Promise<Set<string> | undefined>;
|
|
581
621
|
/**
|
|
582
622
|
* Clears the package manager's cache.
|
|
583
623
|
* @returns A promise that resolves when the cache is cleared.
|
|
584
624
|
*/
|
|
585
625
|
clearCache?(): Promise<void>;
|
|
626
|
+
/**
|
|
627
|
+
* Returns the version of the underlying package management tool (e.g., pip, uv, conda).
|
|
628
|
+
* @param environment - The Python environment context.
|
|
629
|
+
* @returns A promise that resolves to a {@link Pep440Version} object, or `undefined` if not available.
|
|
630
|
+
*/
|
|
631
|
+
getVersion?(environment: PythonEnvironment): Promise<Pep440Version | undefined>;
|
|
632
|
+
/**
|
|
633
|
+
* Retrieves the list of available versions for a given package, newest first.
|
|
634
|
+
*
|
|
635
|
+
* Implementations should:
|
|
636
|
+
* - resolve to an array of {@link Pep440Version} objects on success;
|
|
637
|
+
* - throw a {@link PackageVersionLookupNotSupportedError} when this manager cannot look up
|
|
638
|
+
* versions at all (an unsupported capability);
|
|
639
|
+
* - let operational failures (command, network, or malformed/unparseable output) propagate
|
|
640
|
+
* instead of swallowing them into `undefined`.
|
|
641
|
+
*
|
|
642
|
+
* Resolving to `undefined` is treated by callers as an unsupported capability, equivalent to
|
|
643
|
+
* throwing {@link PackageVersionLookupNotSupportedError}.
|
|
644
|
+
*
|
|
645
|
+
* @param environment - The Python environment context for the lookup.
|
|
646
|
+
* @param packageName - The name of the package to look up.
|
|
647
|
+
* @returns A promise that resolves to an array of {@link Pep440Version} objects (newest first).
|
|
648
|
+
* @throws {@link PackageVersionLookupNotSupportedError} when version lookup is unsupported.
|
|
649
|
+
*/
|
|
650
|
+
getPackageAvailableVersions?(environment: PythonEnvironment, packageName: string): Promise<Pep440Version[] | undefined>;
|
|
651
|
+
/**
|
|
652
|
+
* Formats a versioned install specification for this package manager.
|
|
653
|
+
*
|
|
654
|
+
* Different package managers use different syntax (e.g. pip uses `name==version`,
|
|
655
|
+
* conda uses `name=version`). Implement this method to return the correct format.
|
|
656
|
+
* When absent, callers should default to `name==version`.
|
|
657
|
+
*
|
|
658
|
+
* @param packageName - The name of the package.
|
|
659
|
+
* @param version - The version string.
|
|
660
|
+
* @returns The install specification string (e.g. `"requests==2.31.0"` or `"requests=2.31.0"`).
|
|
661
|
+
*/
|
|
662
|
+
formatInstallSpec?(packageName: string, version: string): string;
|
|
586
663
|
}
|
|
587
664
|
/**
|
|
588
665
|
* Interface representing a Python project.
|
|
@@ -670,7 +747,30 @@ export interface DidChangePythonProjectsEventArgs {
|
|
|
670
747
|
*/
|
|
671
748
|
removed: PythonProject[];
|
|
672
749
|
}
|
|
673
|
-
|
|
750
|
+
/**
|
|
751
|
+
* Options for retrieving packages from a package manager.
|
|
752
|
+
*/
|
|
753
|
+
export interface GetPackagesOptions {
|
|
754
|
+
/**
|
|
755
|
+
* When `true`, bypasses the cache and fetches the latest packages from the underlying tool.
|
|
756
|
+
* Defaults to `false`.
|
|
757
|
+
*/
|
|
758
|
+
skipCache?: boolean;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Options controlling user interaction during package management operations.
|
|
762
|
+
*/
|
|
763
|
+
export interface PackageManagementInteractionOptions {
|
|
764
|
+
/**
|
|
765
|
+
* When `true`, the package management operation runs without any user prompts or
|
|
766
|
+
* interaction and relies solely on the packages provided in the options. Any step
|
|
767
|
+
* that would normally require user input — such as selecting packages to install
|
|
768
|
+
* when none are specified — is skipped instead of prompting the user. Intended for
|
|
769
|
+
* automated or headless scenarios such as integration tests. Defaults to `false`.
|
|
770
|
+
*/
|
|
771
|
+
runHeadless?: boolean;
|
|
772
|
+
}
|
|
773
|
+
export type PackageManagementOptions = PackageManagementInteractionOptions & ({
|
|
674
774
|
/**
|
|
675
775
|
* Upgrade the packages if they are already installed.
|
|
676
776
|
*/
|
|
@@ -704,7 +804,7 @@ export type PackageManagementOptions = {
|
|
|
704
804
|
* The list of packages to uninstall.
|
|
705
805
|
*/
|
|
706
806
|
uninstall: string[];
|
|
707
|
-
};
|
|
807
|
+
});
|
|
708
808
|
/**
|
|
709
809
|
* Options for creating a Python environment.
|
|
710
810
|
*/
|
|
@@ -758,9 +858,8 @@ export interface PythonEnvironmentManagerRegistrationApi {
|
|
|
758
858
|
*
|
|
759
859
|
* @param manager Environment Manager implementation to register.
|
|
760
860
|
* @param options Optional registration options.
|
|
761
|
-
* @param options.extensionId The extension ID of the calling extension.
|
|
762
|
-
*
|
|
763
|
-
* does not contain its marketplace ID. If automatic detection succeeds, this value is ignored.
|
|
861
|
+
* @param options.extensionId The extension ID of the calling extension. When this is not specified,
|
|
862
|
+
* or when the specified extension cannot be found, the extension ID will be automatically detected.
|
|
764
863
|
* @returns A disposable that can be used to unregister the environment manager.
|
|
765
864
|
* @see {@link EnvironmentManager}
|
|
766
865
|
*/
|
|
@@ -792,9 +891,10 @@ export interface PythonEnvironmentManagementApi {
|
|
|
792
891
|
* Remove a Python environment.
|
|
793
892
|
*
|
|
794
893
|
* @param environment The Python environment to remove.
|
|
894
|
+
* @param options Optional parameters controlling environment removal.
|
|
795
895
|
* @returns A promise that resolves when the environment has been removed.
|
|
796
896
|
*/
|
|
797
|
-
removeEnvironment(environment: PythonEnvironment): Promise<void>;
|
|
897
|
+
removeEnvironment(environment: PythonEnvironment, options?: RemoveEnvironmentOptions): Promise<void>;
|
|
798
898
|
}
|
|
799
899
|
export interface PythonEnvironmentsApi {
|
|
800
900
|
/**
|
|
@@ -849,9 +949,8 @@ export interface PythonPackageManagerRegistrationApi {
|
|
|
849
949
|
*
|
|
850
950
|
* @param manager Package Manager implementation to register.
|
|
851
951
|
* @param options Optional registration options.
|
|
852
|
-
* @param options.extensionId The extension ID of the calling extension.
|
|
853
|
-
*
|
|
854
|
-
* does not contain its marketplace ID. If automatic detection succeeds, this value is ignored.
|
|
952
|
+
* @param options.extensionId The extension ID of the calling extension. When this is not specified,
|
|
953
|
+
* or when the specified extension cannot be found, the extension ID will be automatically detected.
|
|
855
954
|
* @returns A disposable that can be used to unregister the package manager.
|
|
856
955
|
* @see {@link PackageManager}
|
|
857
956
|
*/
|
|
@@ -859,6 +958,52 @@ export interface PythonPackageManagerRegistrationApi {
|
|
|
859
958
|
extensionId?: string;
|
|
860
959
|
}): Disposable;
|
|
861
960
|
}
|
|
961
|
+
/**
|
|
962
|
+
* Error thrown when a package manager cannot list available package versions.
|
|
963
|
+
*
|
|
964
|
+
* This distinguishes an *unsupported capability* from an *operational failure* (such as a
|
|
965
|
+
* failed command, a network error, or malformed/unparseable output). Consumers of
|
|
966
|
+
* {@link PythonPackageGetterApi.getPackageAvailableVersions} should treat this specific error
|
|
967
|
+
* as a signal to fall back to manual version entry, while letting any other error propagate.
|
|
968
|
+
*
|
|
969
|
+
* The {@link code} property carries a stable, string-literal discriminator so the error can be
|
|
970
|
+
* recognized reliably across extension bundle boundaries, where `instanceof` may fail because
|
|
971
|
+
* each bundle can load its own copy of this class. Prefer {@link isPackageVersionLookupNotSupportedError}
|
|
972
|
+
* over a bare `instanceof` check for that reason.
|
|
973
|
+
*/
|
|
974
|
+
export declare class PackageVersionLookupNotSupportedError extends Error {
|
|
975
|
+
/**
|
|
976
|
+
* Stable discriminator identifying this error type across bundle boundaries.
|
|
977
|
+
*/
|
|
978
|
+
readonly code = "PackageVersionLookupNotSupported";
|
|
979
|
+
constructor(message?: string);
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Type guard reporting whether an error represents unsupported package version lookup.
|
|
983
|
+
*
|
|
984
|
+
* Uses the stable {@link PackageVersionLookupNotSupportedError.code} discriminator, so it returns
|
|
985
|
+
* `true` even when the error crossed an extension bundle boundary and `instanceof` would fail.
|
|
986
|
+
*
|
|
987
|
+
* @param error The value to test.
|
|
988
|
+
* @returns `true` if `error` is a {@link PackageVersionLookupNotSupportedError} (or a structurally
|
|
989
|
+
* equivalent error carrying the same `code`).
|
|
990
|
+
*/
|
|
991
|
+
export declare function isPackageVersionLookupNotSupportedError(error: unknown): error is PackageVersionLookupNotSupportedError;
|
|
992
|
+
/**
|
|
993
|
+
* Controls how package version lookup failures are reported.
|
|
994
|
+
*/
|
|
995
|
+
export interface GetPackageAvailableVersionsOptions {
|
|
996
|
+
/**
|
|
997
|
+
* Determines whether lookup failures preserve the legacy `undefined` result or reject.
|
|
998
|
+
*
|
|
999
|
+
* - `legacy` resolves to `undefined` for unsupported lookups and operational failures.
|
|
1000
|
+
* This remains the default for backward compatibility, but may be removed in a future
|
|
1001
|
+
* major API version.
|
|
1002
|
+
* - `throw` rejects with {@link PackageVersionLookupNotSupportedError} for unsupported
|
|
1003
|
+
* lookups and propagates operational failures unchanged.
|
|
1004
|
+
*/
|
|
1005
|
+
errorMode?: 'legacy' | 'throw';
|
|
1006
|
+
}
|
|
862
1007
|
export interface PythonPackageGetterApi {
|
|
863
1008
|
/**
|
|
864
1009
|
* Refresh the list of packages in a Python Environment.
|
|
@@ -871,9 +1016,28 @@ export interface PythonPackageGetterApi {
|
|
|
871
1016
|
* Get the list of packages in a Python Environment.
|
|
872
1017
|
*
|
|
873
1018
|
* @param environment The Python Environment for which the list of packages is required.
|
|
1019
|
+
* @param options Optional settings for package retrieval.
|
|
874
1020
|
* @returns The list of packages in the Python Environment.
|
|
875
1021
|
*/
|
|
876
|
-
getPackages(environment: PythonEnvironment): Promise<Package[] | undefined>;
|
|
1022
|
+
getPackages(environment: PythonEnvironment, options?: GetPackagesOptions): Promise<Package[] | undefined>;
|
|
1023
|
+
/**
|
|
1024
|
+
* Get the list of available versions for a package, newest first.
|
|
1025
|
+
*
|
|
1026
|
+
* By default, this preserves the legacy behavior of resolving to `undefined` for unsupported
|
|
1027
|
+
* lookups and operational failures. Pass `{ errorMode: 'throw' }` to distinguish unsupported
|
|
1028
|
+
* capabilities from operational failures: unsupported lookups reject with
|
|
1029
|
+
* {@link PackageVersionLookupNotSupportedError}, while other failures propagate unchanged.
|
|
1030
|
+
*
|
|
1031
|
+
* @param environment The Python Environment context for the lookup.
|
|
1032
|
+
* @param packageName The name of the package to look up.
|
|
1033
|
+
* @param options Controls how lookup failures are reported.
|
|
1034
|
+
* @returns A promise that resolves to an array of {@link Pep440Version} objects (newest first),
|
|
1035
|
+
* or `undefined` in legacy mode when lookup is unsupported or fails.
|
|
1036
|
+
*/
|
|
1037
|
+
getPackageAvailableVersions(environment: PythonEnvironment, packageName: string, options: GetPackageAvailableVersionsOptions & {
|
|
1038
|
+
errorMode: 'throw';
|
|
1039
|
+
}): Promise<Pep440Version[]>;
|
|
1040
|
+
getPackageAvailableVersions(environment: PythonEnvironment, packageName: string, options?: GetPackageAvailableVersionsOptions): Promise<Pep440Version[] | undefined>;
|
|
877
1041
|
/**
|
|
878
1042
|
* Event raised when the list of packages in a Python Environment changes.
|
|
879
1043
|
* @see {@link DidChangePackagesEventArgs}
|