-
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
Open
rshade
wants to merge
3
commits into
main
Choose a base branch
from
python-replacement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package opttest_test | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/pulumi/providertest/pulumitest/opttest" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPythonLinkOption(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| opts := opttest.DefaultOptions() | ||
| assert.Empty(t, opts.PythonLinks, "expected PythonLinks to be empty by default") | ||
|
|
||
| pythonLink := opttest.PythonLink("path/to/sdk") | ||
| pythonLink.Apply(opts) | ||
|
|
||
| assert.Equal(t, []string{"path/to/sdk"}, opts.PythonLinks, "expected PythonLink to append path") | ||
| } | ||
|
|
||
| func TestPythonLinkMultiplePackages(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| opts := opttest.DefaultOptions() | ||
|
|
||
| pythonLink := opttest.PythonLink("path/to/sdk1", "path/to/sdk2") | ||
| pythonLink.Apply(opts) | ||
|
|
||
| assert.Equal(t, []string{"path/to/sdk1", "path/to/sdk2"}, opts.PythonLinks, | ||
| "expected PythonLink to append multiple paths") | ||
| } | ||
|
|
||
| func TestPythonLinkAccumulates(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| opts := opttest.DefaultOptions() | ||
|
|
||
| pythonLink1 := opttest.PythonLink("path/to/sdk1") | ||
| pythonLink1.Apply(opts) | ||
|
|
||
| pythonLink2 := opttest.PythonLink("path/to/sdk2") | ||
| pythonLink2.Apply(opts) | ||
|
|
||
| assert.Equal(t, []string{"path/to/sdk1", "path/to/sdk2"}, opts.PythonLinks, | ||
| "expected PythonLinks to accumulate across multiple calls") | ||
| } | ||
|
|
||
| func TestDefaultsResetsPythonLinks(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| opts := opttest.DefaultOptions() | ||
|
|
||
| pythonLink := opttest.PythonLink("path/to/sdk") | ||
| pythonLink.Apply(opts) | ||
|
|
||
| assert.NotEmpty(t, opts.PythonLinks, "expected PythonLinks to be populated") | ||
|
|
||
| defaults := opttest.Defaults() | ||
| defaults.Apply(opts) | ||
|
|
||
| assert.Empty(t, opts.PythonLinks, "expected Defaults to reset PythonLinks") | ||
| } | ||
|
|
||
| func TestPythonLinkIntegrationV1(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Integration test: verify PythonLink can be used with a real test package (v1) | ||
| // This test checks that the option correctly processes package paths | ||
| pkgV1Path := filepath.Join("..", "testdata", "python_pkg_v1") | ||
|
|
||
| // Verify the test package directory exists | ||
| _, err := filepath.Abs(pkgV1Path) | ||
| assert.NoError(t, err, "expected to resolve package path v1") | ||
|
|
||
| // Create test with PythonLink pointing to v1 package | ||
| opts := opttest.DefaultOptions() | ||
| pythonLink := opttest.PythonLink(pkgV1Path) | ||
| pythonLink.Apply(opts) | ||
|
|
||
| // Verify the path was correctly added to options | ||
| assert.Equal(t, 1, len(opts.PythonLinks), "expected one Python package path") | ||
| assert.True(t, len(opts.PythonLinks[0]) > 0, "expected non-empty package path") | ||
| } | ||
|
|
||
| func TestPythonLinkIntegrationV2(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Integration test: verify PythonLink can be used with a real test package (v2) | ||
| pkgV2Path := filepath.Join("..", "testdata", "python_pkg_v2") | ||
|
|
||
| // Verify the test package directory exists | ||
| _, err := filepath.Abs(pkgV2Path) | ||
| assert.NoError(t, err, "expected to resolve package path v2") | ||
|
|
||
| // Create test with PythonLink pointing to v2 package | ||
| opts := opttest.DefaultOptions() | ||
| pythonLink := opttest.PythonLink(pkgV2Path) | ||
| pythonLink.Apply(opts) | ||
|
|
||
| // Verify the path was correctly added to options | ||
| assert.Equal(t, 1, len(opts.PythonLinks), "expected one Python package path") | ||
| assert.True(t, len(opts.PythonLinks[0]) > 0, "expected non-empty package path") | ||
| } | ||
|
|
||
| func TestPythonLinkUpgradePathGeneration(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Integration test: verify PythonLink generates correct paths for version upgrades | ||
| pkgV1Path := filepath.Join("..", "testdata", "python_pkg_v1") | ||
| pkgV2Path := filepath.Join("..", "testdata", "python_pkg_v2") | ||
|
|
||
| opts := opttest.DefaultOptions() | ||
|
|
||
| // Add v1 package | ||
| pythonLinkV1 := opttest.PythonLink(pkgV1Path) | ||
| pythonLinkV1.Apply(opts) | ||
| assert.Equal(t, 1, len(opts.PythonLinks), "expected one path after v1") | ||
|
|
||
| // Add v2 package (simulating version upgrade) | ||
| pythonLinkV2 := opttest.PythonLink(pkgV2Path) | ||
| pythonLinkV2.Apply(opts) | ||
| assert.Equal(t, 2, len(opts.PythonLinks), "expected two paths after adding v2") | ||
|
|
||
| // Verify both paths are present | ||
| assert.Contains(t, opts.PythonLinks, pkgV1Path, "expected v1 path to be present") | ||
| assert.Contains(t, opts.PythonLinks, pkgV2Path, "expected v2 path to be present") | ||
| } |
13 changes: 13 additions & 0 deletions
13
pulumitest/testdata/python_pkg_v1/pulumi_test_pkg/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| """Test package for PythonLink integration tests.""" | ||
|
|
||
| __version__ = "0.0.1" | ||
|
|
||
|
|
||
| def get_version(): | ||
| """Return the package version.""" | ||
| return __version__ | ||
|
|
||
|
|
||
| def get_message(): | ||
| """Return a version-specific message.""" | ||
| return f"pulumi-test-pkg version {__version__}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from setuptools import setup, find_packages | ||
|
|
||
| setup( | ||
| name="pulumi-test-pkg", | ||
| version="0.0.1", | ||
| packages=find_packages(), | ||
| description="Test package for PythonLink integration tests", | ||
| ) |
13 changes: 13 additions & 0 deletions
13
pulumitest/testdata/python_pkg_v2/pulumi_test_pkg/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| """Test package for PythonLink integration tests.""" | ||
|
|
||
| __version__ = "0.0.2" | ||
|
|
||
|
|
||
| def get_version(): | ||
| """Return the package version.""" | ||
| return __version__ | ||
|
|
||
|
|
||
| def get_message(): | ||
| """Return a version-specific message.""" | ||
| return f"pulumi-test-pkg version {__version__}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from setuptools import setup, find_packages | ||
|
|
||
| setup( | ||
| name="pulumi-test-pkg", | ||
| version="0.0.2", | ||
| packages=find_packages(), | ||
| description="Test package for PythonLink integration tests", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| name: python-with-local-pkg | ||
| runtime: python | ||
| description: Test program for PythonLink integration tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| """Pulumi program that uses the local test package.""" | ||
|
|
||
rshade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import pulumi | ||
| import pulumi_test_pkg | ||
|
|
||
| # Import the test package and verify version | ||
| version = pulumi_test_pkg.get_version() | ||
| message = pulumi_test_pkg.get_message() | ||
|
|
||
| # Export the version as a stack output | ||
| pulumi.export("package_version", version) | ||
| pulumi.export("package_message", message) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # This is intentionally empty - we'll use PythonLink to install the local package |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.