-
Notifications
You must be signed in to change notification settings - Fork 14
Implement automatic package list refresh when site-packages change #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: eleanorjboyd <[email protected]>
…mentation Co-authored-by: eleanorjboyd <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this solution seems a bit complex with getting possible paths to check. Instead can you make it so every environment has a path called "packageFolder" that needs to be set when the environment is created
…environments Co-authored-by: eleanorjboyd <[email protected]>
Co-authored-by: eleanorjboyd <[email protected]>
I've simplified the implementation as requested. The solution now uses a Key changes made:
This approach is much cleaner as it moves the responsibility of knowing the package directory to the environment managers who create the environments, eliminating runtime path guessing. Implemented in commit 3105593. |
Overview
This PR implements automatic package list refresh when packages are installed or uninstalled (including from the command line) by monitoring the site-packages directory for changes. This enhancement provides a seamless user experience by eliminating the need for manual package list refreshes.
Problem Statement
Previously, users had to manually refresh package lists in the VS Code Python Environments extension after installing or uninstalling packages via command line tools like
pip install
orconda install
. This created a disconnect between the actual package state and what was displayed in the extension.Solution
The implementation introduces a file system watcher service that:
Key Features
🔍 Smart Path Resolution
sysPrefix
{sysPrefix}/Lib/site-packages
{sysPrefix}/lib/python*/site-packages
{sysPrefix}/site-packages
🔄 Lifecycle Management
⚡ Performance Optimized
🛡️ Robust Error Handling
sysPrefix
Implementation Details
New Components
SitePackagesWatcherService
- Main service managing file system watcherssitePackagesUtils.ts
- Utility functions for path resolution and validationextension.ts
- Service initialization during extension activationCode Structure
Testing
Example Usage
After this change, the following workflow now works seamlessly:
pip install requests
in terminalBackwards Compatibility
This change is fully backwards compatible:
Files Changed
src/features/packageWatcher/sitePackagesWatcherService.ts
src/features/packageWatcher/sitePackagesUtils.ts
src/features/packageWatcher/index.ts
src/extension.ts
(added service initialization)src/test/features/packageWatcher/sitePackagesUtils.unit.test.ts
src/test/features/packageWatcher/sitePackagesWatcherService.unit.test.ts
docs/automatic-package-refresh.md
Validation
The implementation has been tested to ensure:
This enhancement significantly improves the developer experience by providing real-time package list updates that stay in sync with the actual environment state.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.