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

feat: enable working directory #15

Merged
merged 6 commits into from Mar 9, 2022

Conversation

nissim-natanov-outreach
Copy link
Contributor

@nissim-natanov-outreach nissim-natanov-outreach commented Mar 7, 2022

This PR enables working directory support for all packages.Load call. It is required when running unit tests in isolated directories with their own go.mod files - in this case the packages.Load call must be executed inside that directory.

This PR preserves the original ParseDocs method signature for back compat, introducing new DocsParser to process the comments.

This PR also removes the use of go/importer package. It does not support the new go/modules well and both of its Import and ImportFrom methods are marked as deprecated. The golang.org/x/tools/go/packages is supposed to supersede the go/importer package, and it is already heavily used to parse docs and find convert methods, so there is no reason using the go/importer anymore. Moreover, there is no need to re-parse sources ... so I updated code to store the scope on the Converter itself.

@codecov-commenter
Copy link

codecov-commenter commented Mar 8, 2022

Codecov Report

Merging #15 (2808039) into main (a0f0141) will increase coverage by 0.22%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #15      +/-   ##
==========================================
+ Coverage   93.38%   93.61%   +0.22%     
==========================================
  Files          22       22              
  Lines        1043     1049       +6     
==========================================
+ Hits          974      982       +8     
+ Misses         52       51       -1     
+ Partials       17       16       -1     
Impacted Files Coverage Δ
generator/generator.go 97.26% <ø> (ø)
comments/parse_docs.go 96.89% <100.00%> (+0.09%) ⬆️
generator/generate.go 93.54% <100.00%> (+5.66%) ⬆️
generator/packages.go 92.00% <100.00%> (+0.33%) ⬆️
runner.go 90.90% <100.00%> (+1.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0f0141...2808039. Read the comment docs.

@nissim-natanov-outreach
Copy link
Contributor Author

@jmattheis Jannis, please take a look at this PR, share your thoughts!

Copy link
Owner

@jmattheis jmattheis left a comment

Choose a reason for hiding this comment

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

Hey @nissim-natanov-outreach, thanks for this PR. See sub comments.

comments/parse_docs.go Show resolved Hide resolved
comments/parse_docs.go Outdated Show resolved Hide resolved
comments/parse_docs.go Outdated Show resolved Hide resolved
generator/generate.go Show resolved Hide resolved
@@ -17,6 +15,7 @@ import (
type Config struct {
Name string
ExtendMethods []string
WorkingDir string
Copy link
Owner

Choose a reason for hiding this comment

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

This PR enables working directory support for all packages.Load call. It is required when running unit tests in isolated directories with their own go.mod files - in this case the packages.Load call must be executed inside that directory.

Just to make clear, I understand this correctly. You have a repository with multiple go modules inside, and one goverter call should create converters for all these modules? Was it possible before this change to call goverter multiple times inside the directories of your go module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My use case is slightly different: unit tests. Our codegen tool wraps goverter codegen and invokes it as a library (not via cmd line). When our unit test runs, it creates a temporary directory, drops a go.mod with sources and invokes a codegen (and repeats it few times for different test cases). In each test case we need goverter to work in a scope of that temp (unit test) directory, and ignore the current dir.

P.S. I also noticed by removing go/importer usage the tool became a bit faster. I am not sure what was wrong with the go/importer (other than its lack of support for working dirs), but I did notice a big drop in exec time:

  • with go/importer and unit test forced to do chdir before goverter: ~15-20s
  • with current code: no need to do chdir: ~3-5s

Copy link
Owner

@jmattheis jmattheis Mar 9, 2022

Choose a reason for hiding this comment

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

Thanks for the explanation, and the pref improvements are a good side effect.

@nissim-natanov-outreach
Copy link
Contributor Author

comments addressed, PTAL

@jmattheis jmattheis merged commit 58ba62d into jmattheis:main Mar 9, 2022
@nissim-natanov-outreach nissim-natanov-outreach deleted the nn/working_dir branch March 9, 2022 18:13
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.

None yet

3 participants