Skip to content

Commit

Permalink
Indicate the PyPi package doesn't have a plugin (#358)
Browse files Browse the repository at this point in the history
Pulumi automatically determines required plugins for a program. For Python programs, it essentially does this by running `python -m pip list --format json`, and any packages prefixed with `pulumi-` or `pulumi_` are assumed to have associated plugins, unless the package includes a `pulumi-plugin.json` file that has indicated there is no plugin via `{ "resource": false }`.

When the `GetRequiredPlugins` support was originally added to the Python language host, it [hardcoded](https://github.com/pulumi/pulumi/blob/e6d20d26f7f64a624238f86204d862642ff27e16/sdk/python/cmd/pulumi-language-python/main.go#L428-L430) that `pulumi-policy` did not have an associated plugin. The hardcode mainly for older versions of `pulumi-policy` that did not contain a `pulumi-plugin.json` file.

`pulumi-plugin.json` was actually originally named `pulumiplugin.json` (no dash). This file wasn't  used anywhere, aside from in `pulumi-policy`, but the hardcod prevented it from ever being loaded in that case. It turned out that there was a bug parsing `pulumiplugin.json` that caused the CLI to error when that file existed in other packages. Since we were planning to expand the use of the file to other languages, and make it generated by default by SDKgen, we changed the name from `pulumiplugin.json` to `pulumi-plugin.json` to avoid breaking older CLIs with the bug (see pulumi/pulumi#8593).

After making that change, we never followed up to rename the `pulumiplugin.json` file in `pulumi-policy` to `pulumi-plugin.json`, largely because it didn't matter since we had the hardcode.

However, this hardcode no longer works with the latest version of `pulumi-policy` (v1.11.0). This version was built with a newer version of `setuptools` which has a behavior change where the package name in the metadata will now allow underscores, instead of having underscores replaced with dashes (pypa/setuptools#4159). This means that the package name reported from `pip list` is now `pulumi_policy` instead of `pulumi-policy`, which doesn't match the hardcoded list. And since there is no `pulumi-plugin.json` file in the package (it's still the old `pulumiplugin.json` name), the Pulumi Python language host thinks this package needs a plugin and tries to retrieve one that doesn't exist.

This change addresses the issue by renaming `pulumiplugin.json` to `pulumi-plugin.json` in the package.
  • Loading branch information
justinvp committed Jul 23, 2024
1 parent 31e46ca commit dd9a977
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

---

## Unreleased

- Python: Indicate that the PyPi package doesn't have an associated Pulumi plugin
(https://github.com/pulumi/pulumi-policy/pull/358).

## 1.11.0 (2024-04-17)

- Fix panic when a stack policy with a "remediate" level reports a violation
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/lib/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def readme():
package_data={
'pulumi_policy': [
'py.typed',
'pulumiplugin.json'
'pulumi-plugin.json'
]
},
install_requires=[
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

ptesting "github.com/pulumi/pulumi/sdk/v3/go/common/testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type Runtime int
Expand Down Expand Up @@ -869,3 +870,30 @@ func TestRemoteComponent(t *testing.T) {
},
})
}

func TestPythonDoesNotTryToInstallPlugin(t *testing.T) {
e := ptesting.NewEnvironment(t)
t.Log(e.RootPath)
defer e.DeleteIfNotFailed()

pulumiHome := t.TempDir()
t.Setenv("PULUMI_HOME", pulumiHome)

e.RunCommand("pulumi", "login", "--local")
e.RunCommand("pulumi", "new", "python", "--generate-only", "--yes", "--force")

requirementsTxtPath := filepath.Join(e.RootPath, "requirements.txt")

dep, err := filepath.Abs(filepath.Join("..", "..", "sdk", "python", "lib"))
require.NoError(t, err)

file, err := os.OpenFile(requirementsTxtPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
require.NoError(t, err)
defer file.Close()
_, err = file.WriteString(dep)
require.NoError(t, err)

// Pulumi should not try to install a plugin for pulumi_policy.
// This command will fail if it tries to install the non-existent pulumi_policy plugin.
e.RunCommand("pulumi", "install")
}

0 comments on commit dd9a977

Please sign in to comment.