Skip to content
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

[sdkgen/python] Fix referencing local types with a different package name #12669

Merged
merged 1 commit into from Apr 18, 2023

Conversation

justinvp
Copy link
Member

@justinvp justinvp commented Apr 13, 2023

The Python SDK generator wasn't correctly referencing types that have a different package name in their type token than the name of the schema's package (which is the case when embedding k8s CRD resources/types in a package). This change fixes the generator to emit these local references correctly.

Fixes #12624

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Apr 13, 2023

Changelog

[uncommitted] (2023-04-17)

Bug Fixes

  • [sdkgen/python] Fix referencing local types with a different package name
    #12669

@justinvp justinvp changed the title [sdkgen/python] Allow types with different package name [sdkgen/python] Fix referencing local types with a different package name Apr 17, 2023
The Python SDK generator wasn't correctly referencing types that have a
different package name in their type token than the name of the schema's
package (which is the case when embedding k8s CRD resources/types in a
package). This change fixes the generator to emit these local references
correctly.
@justinvp justinvp marked this pull request as ready for review April 17, 2023 21:27
@justinvp justinvp requested review from Frassle and a team April 17, 2023 21:27
@@ -791,9 +790,6 @@ func (mod *modContext) importObjectType(t *schema.ObjectType, input bool) string
}

importPath := mod.getRelImportFromRoot()
if mod.pkg.Name() != parts[0] {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we handle external imports at the start of the method:

if !codegen.PkgEquals(t.PackageReference, mod.pkg) {
return fmt.Sprintf("import %s", pyPack(t.PackageReference.Name()))
}

What I'm removing seems to be leftover from a previous attempt to support this, which is causing the problems.

import pulumi.runtime
from typing import Any, Mapping, Optional, Sequence, Union, overload
from . import _utilities
from . import crd_k8s_amazonaws_com as _crd_k8s_amazonaws_com
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now import here correctly.

Copy link
Contributor

@abhinav abhinav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated Python code looks valid, and existing Python code hasn't changed.

@justinvp
Copy link
Member Author

bors merge

@bors
Copy link
Contributor

bors bot commented Apr 18, 2023

Build succeeded:

  • bors-ok

@bors bors bot merged commit c6b1102 into master Apr 18, 2023
47 of 52 checks passed
@bors bors bot deleted the justin/embeddedcrds branch April 18, 2023 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[codegen] pulumi imports are incorrectly using pulumi-kubernetes
4 participants