Add site-packages watchers#1597
Conversation
|
Thanks for looking into this! Can you confirm there is no slow down or lag with these extra watchers? I also saw you used a debounce but testing it with a ton of changes at once maybe and making sure it works effectively that would be great. Thanks! |
|
Sure thing, will do more testing for performance. Thanks for taking a look! :) |
|
The new approach should actually be more efficient -- the old code used a single global |
Adds python-envs.packageWatchers (default: true) that allows users to disable site-packages file system watchers if they experience performance issues. The check is centralized in registerPackageWatcherForManager so all managers (builtin, conda, poetry) respect it automatically. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR centralizes Python package change detection by introducing a shared site-packages watcher utility and wiring it into multiple environment managers (system, venv, conda, poetry). It also extends the PackageManager API to optionally provide manager-specific watch targets (e.g., conda’s conda-meta) and adds a user setting to enable/disable the watchers.
Changes:
- Added
src/managers/common/packageWatcher.tsto create per-environment filesystem watchers with debounced package refresh. - Updated builtin and poetry managers to register the shared watcher instead of bespoke logic.
- Extended
PackageManagerwithgetPackageWatchTargets?()and added apython-envs.packageWatcherssetting (localized).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/managers/common/packageWatcher.ts | New shared watcher implementation for site-packages + manager-specific targets. |
| src/managers/builtin/main.ts | Removes duplicated watcher logic; registers shared watcher for sys + venv managers. |
| src/managers/poetry/main.ts | Registers shared package watcher for Poetry environments. |
| src/managers/conda/condaPackageManager.ts | Adds conda-specific watch target provider (conda-meta/**/*.json). |
| src/api.ts | Extends PackageManager interface with getPackageWatchTargets?(). |
| api/src/main.ts | Mirrors API surface change for published API package. |
| examples/sample1/src/api.ts | Mirrors API surface change for sample API typings. |
| package.json | Adds new python-envs.packageWatchers configuration setting. |
| package.nls.json | Adds localized description for the new setting. |
| src/test/managers/common/packageWatcher.unit.test.ts | Adds unit tests for watcher target creation/registration behavior. |
- Fix traceVerbose misuse: use log.debug() with env.envId.id - Set ignoreChangeEvents to true (matching prior behavior) - Dispose debouncedRefresh and bind trigger to preserve context - Guard against old.envId.id === new.envId.id disposing active watcher - Rewrite create/delete tests to actually fire events and assert refresh - Assert existing watcher is not disposed on same-env re-emit Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
package.sync.mp4
This pull request refactors and centralizes the logic for watching Python package changes across different environment managers (system, conda, poetry). The new approach introduces a shared utility to handle file system watching for package metadata, ensuring more robust and consistent package refresh behavior when environments change.
Key improvements and changes:
Centralized Package Watcher Logic:
packageWatcher.ts, which provideswatchPackageChangesForEnvironmentandregisterPackageWatcherForManagerto handle file watching and package refresh for any environment manager. This replaces duplicated logic in each manager.Refactoring of Environment Managers:
main.tsfiles for system, conda, and poetry managers to use the newregisterPackageWatcherForManagerfunction, removing their own package watcher and debounce logic. This simplifies each manager and ensures consistency. [1] [2] [3] [4] [5] [6]Improved Robustness and Maintainability:
Platform and Environment Awareness: