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 fs #219

Merged
merged 5 commits into from
Feb 15, 2023
Merged

Go fs #219

merged 5 commits into from
Feb 15, 2023

Conversation

jhsinger-klotho
Copy link
Contributor

• Does any part of it require special attention?
• Does it relate to or fix any issue?

This is the parsing and transformation side of https://github.com/klothoplatform/klotho-history/issues/466.

We look for the fileblob and transform that to the s3 defintition found in https://gocloud.dev/howto/blob/.

Going to do the IAC side after this so it doesnt grow too large

Standard checks

  • Unit tests: Any special considerations? Added for query and transform as well as some of the helper functions
  • Docs: Do we need to update any docs, internal or public? Not yet
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working? yes, new feature

@jhsinger-klotho
Copy link
Contributor Author

Need to update this to be in sync with updates in the imports pr

}

func (a *Argument) IsString() bool {
return a.Type == "interpreted_string_literal"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the intent here not to match raw_string_literal (using backticks - ``)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah is that a valid go node type with the only difference being `` instead of ""? If so, i definitely need to add that

Comment on lines 31 to 35
for _, f := range unit.Files() {
goSource, ok := Language.ID.CastFile(f)
if !ok {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could be simplified with

for _, goSource := range unit.FilesOfLang(goLang) {
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will update

}

args[0].Content = "nil"
args[1].Content = fmt.Sprintf(`os.Getenv("%s")`, fsEnvVar.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we check to make sure os is imported anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • good callout, i need to make a bunch of updates but i definitely missed this originally

args[0].Content = "nil"
args[1].Content = fmt.Sprintf(`os.Getenv("%s")`, fsEnvVar.Name)

newNodeContent := strings.Replace(result.args.Content(), result.args.Content(), ArgumentListToString(args), 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused here. Won't the outcome of strings.Replace() always be to replace the entirety of the original string with the value of ArgumentListToString(args)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah so were replacing all of the args node which is (var1, var2) with our new args (newVar1, newVar2)

Copy link
Contributor

Choose a reason for hiding this comment

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

What David's saying is that this is the same as

newNodeContent := ArgumentListToString(args)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah i see, good point let me update

@@ -0,0 +1,18 @@
(short_var_declaration
Copy link
Contributor

Choose a reason for hiding this comment

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

no long var declarations? 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i guess not, go is a simpleton

Copy link
Contributor

Choose a reason for hiding this comment

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

This probably won't handle:

var bucket, err = fileblob.OpenBucket(myDir, myConnector)

(presumably the (long) var_declaration)

or

var bucket, err
bucket, err = fileblob.OpenBucket(myDir, myConnector)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me update the query, should be able to make it work without having to change any of the logic i believe

func (n NoopRuntime) GetFsImports() []string {
return []string{
"gocloud.dev/blob",
"_ \"gocloud.dev/blob/s3blob\"",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"_ \"gocloud.dev/blob/s3blob\"",
`_ "gocloud.dev/blob/s3blob"`,

nit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, caused updated tests to break as well so this should be fixed. Was leftover from the go imports pr that was updated

@@ -64,14 +74,23 @@ func UpdateImportsInFile(f *core.SourceFile, importsToAdd []string, importsToRem

// Determine which imports already exist and which we need to add
for _, i := range importsToAdd {
importChunks := strings.Split(i, "\"")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
importChunks := strings.Split(i, "\"")
importChunks := strings.Split(i, `"`)

nit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should be removed now since we take in imports

func (r *AwsRuntime) GetFsImports() []string {
return []string{
"gocloud.dev/blob",
"_ \"gocloud.dev/blob/s3blob\"",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"_ \"gocloud.dev/blob/s3blob\"",
`_ "gocloud.dev/blob/s3blob"`,

nit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

@@ -0,0 +1,18 @@
(short_var_declaration
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably won't handle:

var bucket, err = fileblob.OpenBucket(myDir, myConnector)

(presumably the (long) var_declaration)

or

var bucket, err
bucket, err = fileblob.OpenBucket(myDir, myConnector)

@@ -0,0 +1,4 @@
; Finds arguments in an arguments_list
(argument_list [
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the [ for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so i copied this over from python, must have just been leftover, will remove

Base automatically changed from go_imports to main February 10, 2023 15:01
@github-actions
Copy link

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 2%
github.com/klothoplatform/klotho/pkg/annotation 23%
github.com/klothoplatform/klotho/pkg/cli 4%
github.com/klothoplatform/klotho/pkg/core 21%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 54%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 59%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 39%
github.com/klothoplatform/klotho/pkg/input 63%
github.com/klothoplatform/klotho/pkg/lang 38%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 33%
github.com/klothoplatform/klotho/pkg/lang/javascript 47%
github.com/klothoplatform/klotho/pkg/lang/python 61%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 6%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 59%
github.com/klothoplatform/klotho/pkg/runtime 78%
github.com/klothoplatform/klotho/pkg/static_unit 33%
github.com/klothoplatform/klotho/pkg/validation 73%
github.com/klothoplatform/klotho/pkg/yaml_util 79%
Summary 41% (3952 / 9632)

@jhsinger-klotho jhsinger-klotho mentioned this pull request Feb 13, 2023
}

// GetArguements is passed a tree-sitter node, which is of type argument_list, and returns a list of in order Arguments
func GetArguements(args *sitter.Node) []Argument {
Copy link

Choose a reason for hiding this comment

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

typo:

- GetArguements
+ GetArguments

Comment on lines +18 to +31
nextMatch := doQuery(args, findArgs)
for {
match, found := nextMatch()
if !found {
break
}

arg := match["arg"]
if arg == nil {
continue
}

arguments = append(arguments, Argument{Content: arg.Content(), Type: arg.Type()})
}
Copy link

Choose a reason for hiding this comment

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

Totally optional, but you and also just do:

	selection := query.Select(query.Exec(language, args, findArgs), query.ParamNamed("arg"))
	for _, arg := range query.Collect(selection) {
		arguments = append(arguments, Argument{Content: arg.Content(), Type: arg.Type()})
	}

@@ -47,6 +47,16 @@ func GetImportsInFile(f *core.SourceFile) []Import {
return imports
}

func GetNamedImportInFile(f *core.SourceFile, namedImport string) Import {
imports := GetImportsInFile(f)
for _, i := range imports {
Copy link

Choose a reason for hiding this comment

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

minor-ish: I pretty much always assume i is an index in a for, so this threw me off at first. Maybe imp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah because i have changes in other prs i will go ahead and update in a future pr. Same with the above comments

@jhsinger-klotho jhsinger-klotho merged commit 330a3a7 into main Feb 15, 2023
@jhsinger-klotho jhsinger-klotho deleted the go_fs branch February 15, 2023 16:27
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.

3 participants