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

Add support for Go 1.16 #1815

Closed
rafikdraoui opened this issue Feb 24, 2021 · 5 comments · Fixed by #1818
Closed

Add support for Go 1.16 #1815

rafikdraoui opened this issue Feb 24, 2021 · 5 comments · Fixed by #1818
Labels

Comments

@rafikdraoui
Copy link
Contributor

Go 1.16 now rejects empty go.mod files (c.f. golang/go@d4986e0). This means that golang hooks cannot be installed anymore:

$ pre-commit install-hooks
[INFO] Initializing environment for local.
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/bin/go', 'get', './...')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    go: no module declaration in go.mod. To specify the module path:
    	go mod edit -module=example.com/mod
    
Check the log at /Users/rdraoui/.cache/pre-commit/pre-commit.log

I could get it to work by changing pre_commit/resources/empty_template_go.mod from an empty file to:

module example/mod

But I'm not all that familiar with how modules work in different Go versions, so maybe making that change has some other implications that I don't know about. This Go Wiki entry seems to suggest that empty go.mod files are legal, but maybe it's outdated... (c.f: #1428 (review))

The fix is compatible with Go 1.15.

I tried validating the fix by running the test suite (pytest tests -k golang), but I can't get it to pass with Go 1.15 and current master branch either.

@asottile
Copy link
Member

hmmm what an annoying change, why would they do this -- the patch seems unrelated to the issue it closes

@asottile
Copy link
Member

this is the minimal patch to fix repo: local for golang (as far as I can tell, all other usages of go work already):

$ git diff
diff --git a/pre_commit/resources/empty_template_go.mod b/pre_commit/resources/empty_template_go.mod
index e69de29..fc0ab8c 100644
--- a/pre_commit/resources/empty_template_go.mod
+++ b/pre_commit/resources/empty_template_go.mod
@@ -0,0 +1,3 @@
+go 1.11
+
+module pre-commit-dummy-empty-module

the testsuite however uses classical gopath-based modules which apparently are outright broken by go 1.16 unless GO111MODULE=auto is set (which is outside the control of pre-commit)

@rafikdraoui
Copy link
Contributor Author

In addition, adding the file testing/resources/golang_hooks_repo/go.mod with content module golang-hello-world makes the tests pass under all combinations of Go [1.15|1.16] + GO111MODULE=[""|"on"|"auto"]

I can make a PR if you want.

@asottile
Copy link
Member

sure! it seems surprising that such a testing file is necessary -- makes me think that all hook-producers will need to do the same as well

I wonder if there's something with our temporary GOPATH setup that might need adjusting as well

but yeah feel free to send a PR to get the ball rolling!

@asottile
Copy link
Member

hmm yeah it might just be that we need to copy the repo remote along here:

cmd = ('git', 'clone', '--recursive', '.', repo_src_dir)
helpers.run_setup_cmd(prefix, cmd)

This was referenced Mar 8, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants