Commit 83e26e4
committed
# feat: Add local python SDK replacement option via pip
## Summary
Implements local Python SDK replacement functionality for testing Pulumi providers and programs with unpublished Python SDK builds. This feature enables developers to test against local Python SDKs using `pip install -e` (editable mode), following the same pattern as existing YarnLink (Node.js) and GoModReplacement (Go) features.
## Implementation Details
### Changes Made
1. **pulumitest/opttest/opttest.go**:
- Added `PythonLinks []string` field to `Options` struct to store local Python package paths
- Created `PythonLink()` function to accept one or more local Python package paths
- Updated `Defaults()` function to initialize `PythonLinks` slice
2. **pulumitest/newStack.go**:
- Implemented pip install logic to execute `python -m pip install -e <path>` for each Python package
- Uses absolute paths (consistent with GoModReplacement pattern)
- Executes after YarnLink and before GoModReplacement for logical ordering
- Includes proper error handling and logging
3. **pulumitest/opttest/opttest_test.go** (new file):
- `TestPythonLinkOption`: Verifies single package path is appended
- `TestPythonLinkMultiplePackages`: Verifies multiple package paths can be specified
- `TestPythonLinkAccumulates`: Verifies packages accumulate across multiple calls
- `TestDefaultsResetsPythonLinks`: Verifies Defaults() resets PythonLinks
4. **pulumitest/README.md**:
- Added "Python - Local Package Installation" section
- Documented PythonLink usage with examples
- Followed same documentation pattern as YarnLink and GoModReplacement sections
### Key Features
- **Editable Mode**: Uses `pip install -e` for symlinked/editable installation (same behavior as yarn link)
- **Multiple Packages**: Supports installing multiple local Python packages in a single test
- **Absolute Paths**: Converts relative paths to absolute paths for reliability
- **Error Handling**: Clear error messages if pip install fails or paths don't exist
- **Environment Aware**: Uses `python -m pip` for better virtual environment compatibility
## Test Plan
- ✅ All unit tests for PythonLink option pass (4/4 tests)
- ✅ Code formatting passes (go fmt)
- ✅ Code vetting passes (go vet)
- ✅ Linting passes
- ✅ Implementation follows existing architectural patterns for YarnLink and GoModReplacement
## Usage Example
```go
import (
"filepath"
"testing"
"github.com/pulumi/providertest/pulumitest"
"github.com/pulumi/providertest/pulumitest/opttest"
)
func TestWithLocalPythonSDK(t *testing.T) {
// Use local Python SDK build
test := pulumitest.NewPulumiTest(t, "test_dir",
opttest.PythonLink("../sdk/python"))
// Or multiple packages
test2 := pulumitest.NewPulumiTest(t, "test_dir",
opttest.PythonLink("../sdk/python", "../other-sdk/python"))
test.Up(t)
}
```
## Fixes #391 parent fe0a2a7 commit 83e26e4
File tree
4 files changed
+110
-5
lines changed- pulumitest
- opttest
4 files changed
+110
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
134 | 151 | | |
135 | 152 | | |
136 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
| |||
148 | 152 | | |
149 | 153 | | |
150 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
151 | 171 | | |
152 | 172 | | |
153 | 173 | | |
| |||
170 | 190 | | |
171 | 191 | | |
172 | 192 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 193 | | |
179 | 194 | | |
180 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
166 | 174 | | |
167 | 175 | | |
168 | 176 | | |
| 177 | + | |
169 | 178 | | |
170 | 179 | | |
171 | 180 | | |
| |||
200 | 209 | | |
201 | 210 | | |
202 | 211 | | |
| 212 | + | |
203 | 213 | | |
204 | 214 | | |
205 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
0 commit comments