Skip to content

Add site-packages watchers#1597

Open
edvilme wants to merge 11 commits into
mainfrom
packages-sync
Open

Add site-packages watchers#1597
edvilme wants to merge 11 commits into
mainfrom
packages-sync

Conversation

@edvilme

@edvilme edvilme commented Jun 18, 2026

Copy link
Copy Markdown
Contributor
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:

  • Added a new module, packageWatcher.ts, which provides watchPackageChangesForEnvironment and registerPackageWatcherForManager to handle file watching and package refresh for any environment manager. This replaces duplicated logic in each manager.

Refactoring of Environment Managers:

  • Updated main.ts files for system, conda, and poetry managers to use the new registerPackageWatcherForManager function, 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:

  • The new watcher logic automatically tracks the active environment, ensuring watchers are always up-to-date and resources are cleaned up appropriately.

Platform and Environment Awareness:

  • The watcher targets are now tailored to different platforms (Windows, Unix) and environment types (including conda), ensuring accurate detection of package changes.

@edvilme edvilme added the feature-request Request for new features or functionality label Jun 18, 2026
@edvilme edvilme linked an issue Jun 18, 2026 that may be closed by this pull request
@eleanorjboyd

Copy link
Copy Markdown
Member

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!

@edvilme

edvilme commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Sure thing, will do more testing for performance. Thanks for taking a look! :)

@edvilme

edvilme commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

The new approach should actually be more efficient -- the old code used a single global **/site-packages/*.dist-info/METADATA watcher across the entire workspace and refreshed all projects on any change. Now we use RelativePattern scoped to each active environment's sysPrefix, so VS Code watches a narrow directory and only refreshes the affected environment. Watchers are disposed on environment switch (no accumulation), and the 500ms debounce coalesces rapid events like pip install into a single refresh.

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>
@edvilme edvilme requested review from StellaHuang95 and eleanorjboyd and removed request for eleanorjboyd June 22, 2026 21:31
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts to create per-environment filesystem watchers with debounced package refresh.
  • Updated builtin and poetry managers to register the shared watcher instead of bespoke logic.
  • Extended PackageManager with getPackageWatchTargets?() and added a python-envs.packageWatchers setting (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.

Comment thread src/managers/common/packageWatcher.ts
Comment thread src/managers/common/packageWatcher.ts
Comment thread src/managers/common/packageWatcher.ts
Comment thread src/managers/common/packageWatcher.ts
Comment thread src/test/managers/common/packageWatcher.unit.test.ts Outdated
Comment thread src/test/managers/common/packageWatcher.unit.test.ts Outdated
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-request Request for new features or functionality skip package*.json

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically refresh package list on package changes

3 participants