This feature automatically refreshes the package list when packages are installed or uninstalled in Python environments. It works by monitoring the site-packages directory for changes and triggering the package manager's refresh functionality when changes are detected.
- Environment Monitoring: The
SitePackagesWatcherServicelistens for environment changes (add/remove) - Site-packages Resolution: For each environment, the service resolves the site-packages path using the environment's
sysPrefix - File System Watching: Creates VS Code file system watchers to monitor the site-packages directories
- Automatic Refresh: When changes are detected, triggers the appropriate package manager's
refresh()method
The feature works with all environment types that provide a valid sysPrefix:
- venv environments
- conda environments
- system Python installations
- poetry environments
- pyenv environments
The service automatically detects site-packages directories on different platforms:
{sysPrefix}/Lib/site-packages
{sysPrefix}/lib/python3.*/site-packages{sysPrefix}/lib/python3/site-packages(fallback)
{sysPrefix}/site-packages(for minimal environments)
SitePackagesWatcherService: Main service that manages file system watcherssitePackagesUtils.ts: Utility functions for resolving site-packages paths- Integration: Automatically initialized in
extension.tswhen the extension activates
- Initialization: Watchers are created for existing environments when the service starts
- Environment Changes: New watchers are added when environments are created, removed when environments are deleted
- Cleanup: All watchers are properly disposed when the extension deactivates
- Graceful handling of environments without valid
sysPrefix - Robust error handling for file system operations
- Fallback behavior when site-packages directories cannot be found
- Real-time Updates: Package lists are automatically updated when packages change
- Cross-platform Support: Works on Windows, macOS, and Linux
- Environment Agnostic: Supports all Python environment types
- Performance: Uses VS Code's efficient file system watchers
- User Experience: No manual refresh needed after installing/uninstalling packages
- File system events are debounced to avoid excessive refresh calls
- Package refreshes happen asynchronously to avoid blocking the UI
- The service integrates seamlessly with existing package manager architecture
- Comprehensive test coverage ensures reliability across different scenarios