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

Go and Python codegen support symbols with hyphens in their names #10738

Merged
merged 12 commits into from
Oct 11, 2022

Conversation

mattolenik
Copy link

@mattolenik mattolenik commented Sep 15, 2022

Description

This change enables the fix for pulumi/crd2pulumi#43, wherein hyphens - were mishandled and led to generation of invalid Go and Python. For example, code such as func My-Thing() {} or class My-Thing.

This change improves the existing casing functions and extracts them to a new subpackage, cgstrings.

Resolves pulumi/crd2pulumi#43. When this change is merged go get -u will fix the crd2pulumi issue.

Checklist

  • I have added tests that prove my fix is effective or that my feature works

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Sep 15, 2022

Changelog

[uncommitted] (2022-10-10)

@mattolenik mattolenik added the impact/no-changelog-required This issue doesn't require a CHANGELOG update label Sep 15, 2022
@mattolenik mattolenik marked this pull request as ready for review September 15, 2022 19:01
@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@mattolenik mattolenik force-pushed the crd2pulumi43 branch 4 times, most recently from 22fbc1b to 0a05b53 Compare September 19, 2022 18:20
@mattolenik mattolenik requested a review from a team September 19, 2022 18:39
@iwahbe iwahbe added the kind/engineering Work that is not visible to an external user label Sep 20, 2022
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

This looks good to me.

@mikhailshilkov
Copy link
Member

@mattolenik @iwahbe Should we modify some programgen test cases to cover changes from this PR?

pkg/codegen/cgstrings/cgstrings.go Outdated Show resolved Hide resolved
return string(res)
}

// UppercaseFirst uppercases the first letter of s.
Copy link
Member

Choose a reason for hiding this comment

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

This is called Title elsewhere

Copy link
Author

Choose a reason for hiding this comment

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

True, though there are package-specific implementations of Title that can (possibly) contain different logic. They get used like this:

// From pkg/codegen/docs/utils.go
func title(s, lang string) string {
	switch lang {
	case "go":
		return go_gen.Title(s)
	case "csharp":
		return dotnet.Title(s)
	default:
		return strings.Title(s)
	}
}

And since Title has the association (at least to me) of being like strings.Title which will uppercase multiple letters and not just the first one. Like foo bar becomes Foo Bar not Foo bar which is what we want here. So I figured a new name was clearer, but happy to take suggestions anyway of course

Copy link
Member

Choose a reason for hiding this comment

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

That's fair enough reasoning to leave it as is

pkg/codegen/go/utilities.go Outdated Show resolved Hide resolved
pkg/codegen/python/utilities.go Outdated Show resolved Hide resolved
@Frassle
Copy link
Member

Frassle commented Sep 20, 2022

Should we modify some programgen test cases to cover changes from this PR?

Or add new ones

@mattolenik mattolenik force-pushed the crd2pulumi43 branch 3 times, most recently from 42fa179 to ada2764 Compare September 23, 2022 16:54
@mikhailshilkov
Copy link
Member

@iwahbe @AaronFriel should we take this PR over and bring it to the finish line?

Matthew Olenik added 9 commits October 10, 2022 12:25
Previously codegen would output hyphens into the names of symbols such
as functions, variable names, etc. This fix converts hyphens to
underscores, making them valid code in Go and Python.
@iwahbe iwahbe self-assigned this Oct 10, 2022
@iwahbe
Copy link
Member

iwahbe commented Oct 10, 2022

@iwahbe @AaronFriel should we take this PR over and bring it to the finish line?

Yes we should. I'm on it.

@AaronFriel
Copy link
Member

Convert to draft & remove reviewers until ready for review?

@iwahbe
Copy link
Member

iwahbe commented Oct 10, 2022

Convert to draft & remove reviewers until ready for review?

It should be ready for review now. @mattolenik addressed most of the feedback he got. I cleaned up the rest and regenerated the test case. It can be reviewed now.

@iwahbe iwahbe requested a review from Frassle October 11, 2022 16:37
@iwahbe
Copy link
Member

iwahbe commented Oct 11, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 11, 2022

Build succeeded:

@bors bors bot merged commit 9f1115c into master Oct 11, 2022
@pulumi-bot pulumi-bot deleted the crd2pulumi43 branch October 11, 2022 17:40
@iwahbe iwahbe restored the crd2pulumi43 branch October 14, 2022 23:11
bors bot added a commit that referenced this pull request Oct 14, 2022
11033: Revert "Go and Python codegen support symbols with hyphens in their names" r=iwahbe a=iwahbe

Reverts #10738

This caused changes in python class names.

Co-authored-by: Ian Wahbe <ian@wahbe.com>
@iwahbe iwahbe mentioned this pull request Oct 15, 2022
3 tasks
bors bot added a commit that referenced this pull request Oct 15, 2022
11033: Revert "Go and Python codegen support symbols with hyphens in their names" r=iwahbe a=iwahbe

Reverts #10738

This caused changes in python class names.

Co-authored-by: Ian Wahbe <ian@wahbe.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact/no-changelog-required This issue doesn't require a CHANGELOG update kind/engineering Work that is not visible to an external user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crd properties with - in name
6 participants