Skip to content

Commit 3105593

Browse files
Copiloteleanorjboyd
andcommitted
Update documentation to reflect simplified packageFolder approach
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent f14f8bd commit 3105593

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

docs/automatic-package-refresh.md

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
# Automatic Package List Refresh
22

3-
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.
3+
This feature automatically refreshes the package list when packages are installed or uninstalled in Python environments. It works by monitoring each environment's package directory for changes and triggering the package manager's refresh functionality when changes are detected.
44

55
## How It Works
66

7-
1. **Environment Monitoring**: The `SitePackagesWatcherService` listens for environment changes (add/remove)
8-
2. **Site-packages Resolution**: For each environment, the service resolves the site-packages path using the environment's `sysPrefix`
9-
3. **File System Watching**: Creates VS Code file system watchers to monitor the site-packages directories
7+
1. **Environment Setup**: Each environment specifies its package directory via the `packageFolder` property
8+
2. **Environment Monitoring**: The `SitePackagesWatcherService` listens for environment changes (add/remove)
9+
3. **File System Watching**: Creates VS Code file system watchers to monitor the package directories
1010
4. **Automatic Refresh**: When changes are detected, triggers the appropriate package manager's `refresh()` method
1111

1212
## Supported Environment Types
1313

14-
The feature works with all environment types that provide a valid `sysPrefix`:
14+
The feature works with all environment types that set the `packageFolder` property:
1515

1616
- **venv** environments
1717
- **conda** environments
1818
- **system** Python installations
1919
- **poetry** environments
2020
- **pyenv** environments
2121

22-
## Site-packages Path Resolution
22+
## Package Directory Resolution
2323

24-
The service automatically detects site-packages directories on different platforms:
24+
Each environment manager is responsible for setting the `packageFolder` property when creating environments. The resolution follows platform-specific patterns:
2525

2626
### Windows
2727
- `{sysPrefix}/Lib/site-packages`
2828

2929
### Unix/Linux/macOS
30-
- `{sysPrefix}/lib/python3.*/site-packages`
31-
- `{sysPrefix}/lib/python3/site-packages` (fallback)
30+
- `{sysPrefix}/lib/python3/site-packages` (standard environments)
31+
- `{sysPrefix}/site-packages` (conda-style environments)
3232

33-
### Conda Environments
34-
- `{sysPrefix}/site-packages` (for minimal environments)
33+
### Environment Manager Implementation
34+
35+
Environment managers use the `resolvePackageFolderFromSysPrefix()` utility function to determine the appropriate package directory based on the environment's `sysPrefix`.
3536

3637
## Implementation Details
3738

3839
### Key Components
3940

4041
1. **`SitePackagesWatcherService`**: Main service that manages file system watchers
41-
2. **`sitePackagesUtils.ts`**: Utility functions for resolving site-packages paths
42-
3. **Integration**: Automatically initialized in `extension.ts` when the extension activates
42+
2. **`sitePackagesUtils.ts`**: Utility function for resolving package folder paths from sysPrefix
43+
3. **Environment Managers**: Each manager sets the `packageFolder` property when creating environments
44+
4. **Integration**: Automatically initialized in `extension.ts` when the extension activates
4345

4446
### Lifecycle Management
4547

@@ -49,9 +51,9 @@ The service automatically detects site-packages directories on different platfor
4951

5052
### Error Handling
5153

52-
- Graceful handling of environments without valid `sysPrefix`
54+
- Graceful handling of environments without a `packageFolder` property
5355
- Robust error handling for file system operations
54-
- Fallback behavior when site-packages directories cannot be found
56+
- Fallback behavior when package directories cannot be accessed
5557

5658
## Benefits
5759

@@ -60,10 +62,29 @@ The service automatically detects site-packages directories on different platfor
6062
3. **Environment Agnostic**: Supports all Python environment types
6163
4. **Performance**: Uses VS Code's efficient file system watchers
6264
5. **User Experience**: No manual refresh needed after installing/uninstalling packages
65+
6. **Simplified Architecture**: Environment managers explicitly specify their package directories
6366

6467
## Technical Notes
6568

6669
- File system events are debounced to avoid excessive refresh calls
6770
- Package refreshes happen asynchronously to avoid blocking the UI
6871
- The service integrates seamlessly with existing package manager architecture
69-
- Comprehensive test coverage ensures reliability across different scenarios
72+
- Environment managers use the `resolvePackageFolderFromSysPrefix()` utility for consistent package directory resolution
73+
- Comprehensive test coverage ensures reliability across different scenarios
74+
75+
## For Environment Manager Developers
76+
77+
When implementing a new environment manager, ensure you set the `packageFolder` property in your `PythonEnvironmentInfo`:
78+
79+
```typescript
80+
import { resolvePackageFolderFromSysPrefix } from '../../features/packageWatcher';
81+
82+
const environmentInfo: PythonEnvironmentInfo = {
83+
// ... other properties
84+
sysPrefix: '/path/to/environment',
85+
packageFolder: resolvePackageFolderFromSysPrefix('/path/to/environment'),
86+
// ... other properties
87+
};
88+
```
89+
90+
This ensures automatic package refresh functionality works with your environment type.

0 commit comments

Comments
 (0)