disable automatic toolchain switching for golang hooks by AleksaC · Pull Request #3304 · pre-commit/pre-commit
Repository navigation
disable automatic toolchain switching for golang hooks - #3304
Merged
asottile merged 1 commit into pre-commit:main from AleksaC:go-toolchain Nov 25, 2024
Merged
disable automatic toolchain switching for golang hooks #3304 asottile merged 1 commit into pre-commit:main from AleksaC:go-toolchain
Conversation
AleksaC commented Sep 18, 2024
Copy link Copy Markdown
Contributor
Resolves #3300
I only disabled the toolchain switching if the version is not system. I did this because system is the default if go is installed globally and no language_version is explicitly specified. In this case users likely doesn't care which version of go is used as long as their hooks are working, so I think it makes more sense to allow the toolchain switching since it doesn't break user expectations and other than a small performance hit on hook installation doesn't have negative impact.
If we were to disable toolchain switching regardless of the version, many hooks would break since many environments lag with their go version. For example, in GitHub-hosted runners for GitHub Actions the pre-installed go version is 1.21 which is two versions behind the current version, so it's likely that a lot of hooks work thanks to automatic toolchain switching without even knowing.
AleksaC commented Sep 19, 2024
Copy link Copy Markdown
Contributor
Author
|
Unrelated to this PR, but mypy fails with pre-commit/pre_commit/xargs.py Line 31 in de85900
Replacing try/except with |
View reviewed changes
Comment thread pre_commit/languages/golang.py
| env = no_git_env(dict(os.environ, GOPATH=gopath)) | ||
| env.pop('GOBIN', None) | ||
| if version != 'system': | ||
| env['GOTOOLCHAIN'] = 'local' |
View reviewed changes
Comment thread tests/languages/golang_test.py
Outdated
| exe='golang-version-test', | ||
| ) | ||
|
|
||
| assert 'go.mod requires go >= 1.23.1' in excinfo.value |
View reviewed changes
Comment thread tests/languages/golang_test.py
Outdated
| language=golang, | ||
| version='1.22.0', | ||
| exe='go fmt', | ||
| file_args=(str(main_file)), |
View reviewed changes
Comment thread pre_commit/languages/golang.py
|
|
||
| return ( | ||
| ('GOROOT', os.path.join(venv, '.go')), | ||
| ('GOTOOLCHAIN', 'local'), |
Outdated
Comment on lines +225 to +226
| with monkeypatch.context() as m: | ||
| m.chdir(str(test_dir)) |
disable automatic toolchain switching for golang hooks
109628c
asottile
force-pushed
the
go-toolchain
branch
from
122528a to
109628c
Compare
November 25, 2024 23:47 asottile approved these changes Nov 25, 2024
View reviewed changes
asottile left a comment
Copy link Copy Markdown
Member
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
asottile enabled auto-merge November 25, 2024 23:48 asottile merged commitcb14bc2
into
pre-commit : main
Nov 25, 2024
WojasKrk
suggested changes
Jan 21, 2025
View reviewed changes
WojasKrk left a comment
Copy link Copy Markdown
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
X
pre-commit locked as off-topic and limited conversation to collaborators Jan 21, 2025 Sign up for free to subscribe to this conversation on GitHub . Already have an account? Sign in .