Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

disable automatic toolchain switching for golang hooks#3304

Merged
asottile merged 1 commit intopre-commit:mainfrom
AleksaC:go-toolchain
Nov 25, 2024
Merged

disable automatic toolchain switching for golang hooks#3304
asottile merged 1 commit intopre-commit:mainfrom
AleksaC:go-toolchain

Conversation

@AleksaC
Copy link
Contributor

Resolves#3300

I only disabled the toolchain switching if the version is notsystem. I did this becausesystem is the default if go is installed globally and nolanguage_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 is1.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
Copy link
ContributorAuthor

Unrelated to this PR, but mypy fails withModule has no attribute "sched_getaffinity" likely because it's not available on MacOS:

returnlen(os.sched_getaffinity(0))

Replacing try/except withhasattr would fix it, but I didn't want to change it because it's outside the scope of the current PR.

env = no_git_env(dict(os.environ, GOPATH=gopath))
env.pop('GOBIN', None)
if version != 'system':
env['GOTOOLCHAIN'] = 'local'
Copy link
Member

Choose a reason for hiding this comment

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

I think (?) this should be part ofget_env_patch ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

From what I can seeget_env_patch is only called fromin_env which is used when running the hook and not during the installation. This should only be relevant during installation because that's when the build happens.

I ran the test to make sure it works this way and it breaks when I move it.

Copy link
Member

Choose a reason for hiding this comment

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

hmmm I guess? but what about for hooks that just callgofmt -- I know the rust toolchain gets grumbly when the versions mismatch -- does something like this survive?

-repo:localhooks:    -id:gofmtname:gofmtlanguage:golangentry:gofmt -l -wtypes:[go]

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

gofmt doesn't seem to care about this option, butgo fmt performs the toolchain switch. Looking at the code it seems that anygo command will try to perform atoolchain switch.

I guess the variable should be set in both places then.

asottile reacted with thumbs up emoji
exe='golang-version-test',
)

assert 'go.mod requires go >= 1.23.1' in excinfo.value
Copy link
Member

Choose a reason for hiding this comment

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

this line is never run because it is indented

language=golang,
version='1.22.0',
exe='go fmt',
file_args=(str(main_file)),
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 just a parenthesized string and should be a tuple I believe -- I'm kinda surprised the type checker was ok with this? (oh duh,str is aSequence[str] so it just kinda lets it happen)


return (
('GOROOT', os.path.join(venv, '.go')),
('GOTOOLCHAIN', 'local'),
Copy link
Member

Choose a reason for hiding this comment

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

does this break withlanguage_version: system? this seems different than the install code below

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

If thelanguage_version issystem the function is going to return before reaching that line, so it's consistent with the install code.

Comment on lines +225 to +226
with monkeypatch.context() as m:
m.chdir(str(test_dir))
Copy link
Member

Choose a reason for hiding this comment

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

there's a helper for this I believe (I think it's calledwith chdir(...)? orwith cwd(...))

Copy link
Member

@asottileasottile left a comment

Choose a reason for hiding this comment

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

@asottileasottile merged commitcb14bc2 intopre-commit:mainNov 25, 2024
Copy link

@WojasKrkWojasKrk left a comment

Choose a reason for hiding this comment

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

X

@pre-commitpre-commit locked asoff-topicand limited conversation to collaboratorsJan 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@asottileasottileasottile approved these changes

+1 more reviewer

@WojasKrkWojasKrkWojasKrk requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Disable automatic toolchain switching in golang

3 participants

@AleksaC@asottile@WojasKrk

[8]ページ先頭

©2009-2026 Movatter.jp