You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7ea97a3
Browse filesBrowse the repository at this point in the historyBrowse files
Fixes#1779
## Summary
Adds project-scoped package manager instances for package managers whose
behavior depends on the active Python project. Instead of threading
project context through every package operation, a provider can
implement `PackageManager.createForProject(project)` and return a
manager bound to that project.
## Changes
- Add the optional `PackageManager.createForProject(project)` API.
- Cache project-bound manager instances by provider and normalized
project path while keeping project-independent managers shared.
- Preserve the registered provider ID for scoped managers and allow
scoped managers to create package items.
- Forward package-change events from root and scoped managers through
the internal and public APIs.
- Keep package watchers distinct by provider, environment, and project.
- Retain the scoped manager for package actions initiated from the
project view.
- Bind Poetry package operations to an immutable `PythonProject`:
- `add`, `remove`, `show`, and `show --top-level` run from the project
directory.
- `manage` and `refresh` reject when Poetry is not project-bound.
- `getPackages` and `getDirectPackageNames` return `undefined` when
Poetry is not project-bound.
- Project-independent operations such as `getVersion` and
`formatInstallSpec` remain available.
- Update the API package metadata, changelog, and documentation.
## Validation
- `npm run lint`
- `npm run compile-tests`
- `npm run unittest` — 2,425 passing, 6 pending
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: .github/instructions/testing-workflow.instructions.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ This guide covers the full testing lifecycle:
19
19
## Learnings
20
20
21
21
- Pip commands that return JSON must pass `--disable-pip-version-check`; the process helper combines stderr with stdout, so update notices can otherwise make valid JSON unparseable (1).
22
+
- When a view subscribes to a newly added provider event, TypeMoq-based view tests must return a real `EventEmitter.event`; an unstubbed event yields an undefined disposable and fails during teardown (1).
Copy file name to clipboardExpand all lines: api/CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,17 @@ All notable changes to the `@vscode/python-environments` API package are documen
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
8
+
## [1.5.0]
9
+
10
+
### Added
11
+
12
+
- Added the optional `PackageManager.createForProject` factory for package managers whose operations depend on the calling Python project. Explicit project contexts are used directly; environment-only operations use a scoped manager only when exactly one tracked project matches.
13
+
- Added optional `PackageManager.dispose` support for releasing resources owned by project-scoped package managers.
14
+
15
+
### Changed
16
+
17
+
- Environment-only package operations no longer fall back to an unbound project-aware package manager. When no unique project can be inferred, package reads return `undefined` and mutations and refreshes reject with `No package manager found`.
|`environment`|[`PythonEnvironment`](#pythonenvironment)| Yes | The environment whose package list should be refreshed. |
819
820
820
821
**Returns**`Promise<void>`. Changes surface through
821
-
[`onDidChangePackages`](#ondidchangepackages).
822
+
[`onDidChangePackages`](#ondidchangepackages). Rejects with
823
+
`No package manager found` when no package manager can be resolved for the
824
+
environment - including when a project-aware manager cannot identify one unique
825
+
project.
822
826
823
827
```typescript
824
828
// Packages were installed outside the extension - re-read the list.
@@ -842,8 +846,10 @@ managePackages(
842
846
|`environment`|[`PythonEnvironment`](#pythonenvironment)| Yes | The environment to modify. |
843
847
|`options`|[`PackageManagementOptions`](#packagemanagementoptions)| Yes | Must specify `install`, `uninstall`, or both. Also carries `upgrade`, `showSkipOption`, and `runHeadless`. |
844
848
845
-
**Returns**`Promise<void>`, resolving when the operation finishes. Rejects if
846
-
the underlying tool fails.
849
+
**Returns**`Promise<void>`, resolving when the operation finishes. Rejects with
850
+
`No package manager found` when no package manager can be resolved for the
851
+
environment - including when a project-aware manager cannot identify one unique
852
+
project - or if the underlying tool fails.
847
853
848
854
```typescript
849
855
awaitapi.managePackages(env, {
@@ -1613,13 +1619,61 @@ Reports and changes the packages of an environment.
|`getPackages(environment, options?)`|`(environment: PythonEnvironment, options?: GetPackagesOptions) => Promise<Package[] \| undefined>`| Yes | Returns installed packages, or `undefined` if they cannot be retrieved. |
1615
1621
|`getPackageWatchTargets(environment)`|`(environment: PythonEnvironment) => RelativePattern[]`| No | Extra filesystem patterns to watch for install and uninstall changes, appended to the default site-packages locations. Implement for manager-specific locations such as `conda-meta`. |
1622
+
|`createForProject(project)`|`(project: PythonProject) => PackageManager`| No | Creates a manager bound to a project for project-sensitive operations. |
1623
+
|`dispose()`|`() => void`| No | Releases resources owned by the manager. The extension disposes project-scoped managers when their project is removed or replaced, their provider is unregistered, or the extension shuts down. |
1616
1624
|`getDirectPackageNames(environment)`|`(environment: PythonEnvironment) => Promise<Set<string> \| undefined>`| No | Best-effort set of non-transitive package names. Most tools cannot record user intent - pip uses `pip list --not-required`, which reports leaf packages rather than explicitly installed ones. |
1617
1625
|`clearCache()`|`() => Promise<void>`| No | Drops cached package data. |
1618
1626
|`getVersion(environment)`|`(environment: PythonEnvironment) => Promise<Pep440Version \| undefined>`| No | Version of the underlying tool, such as pip, uv, or conda. |
1619
1627
|`getPackageAvailableVersions(environment, packageName)`|`(environment: PythonEnvironment, packageName: string) => Promise<Pep440Version[] \| undefined>`| No | Available versions, newest first. Throw `PackageVersionLookupNotSupportedError` when unsupported and let operational failures propagate. Resolving to `undefined` is treated as unsupported. |
1620
1628
|`formatInstallSpec(packageName, version)`|`(packageName: string, version: string) => string`| No | Formats a pinned specifier for this tool, for example `requests==2.31.0` for pip or `requests=2.31.0` for conda. Callers default to `name==version` when absent. |
1621
1629
|`onDidChangePackages`|`Event<DidChangePackagesEventArgs>`| No | Fire when packages change. |
1622
1630
1631
+
##### Project-scoped package managers
1632
+
1633
+
Implement `createForProject` when package operations depend on project files or
1634
+
the process working directory, as they do for tools such as Poetry. Callers that
1635
+
already have a `PythonProject` use that project directly. For environment-only
1636
+
operations, the extension selects a project-scoped manager only when exactly one
1637
+
tracked project uses the environment; it does not choose arbitrarily when no
1638
+
project or multiple projects match.
1639
+
1640
+
Environment-only paths never use a project-aware provider as an unbound
1641
+
fallback. When no unique project can be inferred, `getPackageManager` returns no
1642
+
manager, so package reads return `undefined`, package views suppress those
1643
+
operations, and package mutations or refreshes reject with `No package manager
1644
+
found`. Keep project-specific caches and mutable state on the manager returned by
1645
+
`createForProject`, and implement `dispose` when that manager owns resources.
1646
+
1647
+
When a scoped manager fires `onDidChangePackages`, the event's `manager` must be
1648
+
the exact scoped instance returned by `createForProject`. This requirement also
1649
+
applies when root and scoped managers share an event emitter.
0 commit comments