-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add local python SDK replacement option via pip #150
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
83e26e4 to
46198c3
Compare
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.
Pull Request Overview
This PR implements local Python SDK replacement functionality to enable testing Pulumi providers with unpublished Python SDK builds using pip install -e (editable mode). It follows the same architectural pattern as existing YarnLink and GoModReplacement features.
- Added
PythonLinks []stringfield to Options struct andPythonLink()function for specifying local Python package paths - Implemented pip install logic in
NewStack()to executepython -m pip install -e <path>for each specified package - Added comprehensive test coverage with 6 unit tests and updated documentation with usage examples
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pulumitest/opttest/opttest.go | Added PythonLinks field to Options struct and PythonLink() function |
| pulumitest/newStack.go | Implemented pip install execution logic with error handling |
| pulumitest/opttest/opttest_test.go | Added comprehensive unit tests for PythonLink functionality |
| pulumitest/README.md | Added documentation section for Python local package installation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
46198c3 to
2cc0f20
Compare
2cc0f20 to
65d70bc
Compare
65d70bc to
0b334a5
Compare
…umi 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.
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
- **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
- ✅ 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
```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)
}
```
0b334a5 to
e8b12a1
Compare
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.
Pull Request Overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
blampe
left a comment
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.
So for what it's worth I'm testing this out and it only seems to work if I also include opttest.SkipInstall(). @rshade has that been your experience as well?
With just opttest.PythonLink("../sdk/python"):
python_test.go:14: installing packages and plugins
python_test.go:14: failed to install packages and plugins: exit status 255
Installing dependencies...
Updating pip, setuptools, and wheel in virtual environment...
Requirement already satisfied: pip in /Users/bryce/.local/share/mise/installs/python/3.11.8/lib/python3.11/site-packages (25.3)
Requirement already satisfied: setuptools in /Users/bryce/.local/share/mise/installs/python/3.11.8/lib/python3.11/site-packages (80.9.0)
Requirement already satisfied: wheel in /Users/bryce/.local/share/mise/installs/python/3.11.8/lib/python3.11/site-packages (0.45.1)
Finished updating
Installing dependencies in virtual environment...
ERROR: Could not find a version that satisfies the requirement pulumi_provide_boilerplate>=1.0.0 (from versions: none)
ERROR: No matching distribution found for pulumi_provide_boilerplate>=1.0.0
error: installing dependencies: installing dependencies via '/Users/bryce/.local/share/mise/installs/python/3.11.8/bin/python3 -m pip install -r requirements.txt': exit status 1
installing dependencies via '/Users/bryce/.local/share/mise/installs/python/3.11.8/bin/python3 -m pip install -r requirements.txt': exit status 1
installing dependencies via '/Users/bryce/.local/share/mise/installs/python/3.11.8/bin/python3 -m pip install -r requirements.txt': exit status 1
python_test.go:14: Skipping removal of programDir temp directories on failures: "/var/folders/kq/zdlx0fn57yl66gxktcyzylv40000gn/T/TestPython1125338078"
python_test.go:14: To remove these directories on failures, set PULUMITEST_RETAIN_FILES_ON_FAILURE=false
Everything works as expected when I add opttest.SkipInstall().
We weren't validating that example tests still run for Node/Dotnet/Python/Java. Python needs pulumi/providertest#150. Java still needs an example program but is less of a priority.
Co-authored-by: Bryce Lampe <[email protected]>
Let me look into that. I thought I had it working. I may have broken it after. |
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.Key Features
pip install -efor symlinked/editable installation (same behavior as yarn link)python -m pipfor better virtual environment compatibilityUsage Example
Fixes #39