You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Dev] pre-commit rubocop hook attempts to install for non-Ruby file changes #47937
Describe the bug, including details regarding any error messages, version, and platform.
The below description and proposed solution was generated by claude when I ran into this issue, so while I'm happy to make the change myself, please can someone verify this makes sense to do?
Describe the bug
The rubocop pre-commit hook attempts to install its environment even when committing changes that don't touch any Ruby files. This causes errors for developers who don't have Ruby installed, even when they're only working on R, Python, or other components.
Current behavior:
When committing changes to non-Ruby files (e.g., R package files), pre-commit tries to install the rubocop environment and fails if Ruby is not installed:
[INFO] Installing environment for https://github.com/rubocop/rubocop.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('gem', 'build', 'rubocop.gemspec')
return code: 1
stdout:
Executable gem not found
Root cause:
In .pre-commit-config.yaml, the rubocop hook (lines 247-258) has an exclude filter but is missing a files filter:
I think that the Rubocob hook is initialized with files: \.rb$.
How about using nice pre-commit run --show-diff-on-failure --color=always --all-files r for R development?
Just for additional context, I was on a fresh Ubuntu install and whichever pre-commit command ran was activated by the RStudio IDE when I hit the commit button. I solved it by just installing it but it might trip up other contributors.
I've also had similar issues in VS Code - I think it's an "interacting with git in an IDE" problem.
If it's possible, I'd prefer to find a solution which doesn't require using a specific command as I think it'll be off-putting to new or occasional contributors.
I had a bit more of a look into it, that wasn't the actual problem and it doesn't solve the issue. The rubocop hook itself is configured to run on only Ruby files, so including the files filter or not becomes redundant.
There is still the issue that it tries to install regardless of whether it's a Ruby PR or not.
See below for LLM summary of what I tried.
I'm going to remove the instructions to use pre-commit from the R docs as it creates a barrier for new contributors, but otherwise I think no changes needed here as none of the alternatives suggested seem like good options.
I feel this is going to create barriers for new contributors in other implementations if they try to use pre-commit. Maybe we want to update the docs to mention that it'll install everything?
After investigating, the proposed fix (files: .rb$ filter) doesn't actually solve the issue. Here's why:
What we found:
The files filter in pre-commit only controls which files are checked, not whether the environment is installed
Pre-commit attempts to install ALL hook environments upfront, regardless of file filters
The rubocop environment installation requires gem to build the rubocop.gemspec file
Without Ruby/gem installed, installation fails with "Executable gem not found" before it even gets to the file filtering stage
Testing:
Uninstalled Ruby completely
Tested with and without files: .rb$ filter
Both cases failed with the same error when pre-commit tried to initialize environments
The error occurs even when committing only non-Ruby files
Why this is problematic:
IDE git integration (RStudio, VS Code) runs pre-commit automatically
Can't use workarounds like SKIP=rubocop environment variable from an IDE
Can't control which pre-commit command the IDE runs
Possible solutions:
Make rubocop a local hook with a wrapper script that checks if Ruby exists first
Accept that Ruby needs to be installed as a dev dependency for anyone using pre-commit
Use a custom git hook wrapper that sets SKIP automatically
Remove rubocop from pre-commit entirely and run it separately
The fundamental issue is that pre-commit's design installs all environments upfront, and there's no way to make an environment optional based on what's available on the system.
Hm, I haven't ran into anything similar. In Python we use:
pre-commit run --show-diff-on-failure --color=always --all-files python
that is what @kou suggested, the command is included in the dev docs and it works very well.
Having auto-fix GitHub Actions for new contributors sounds cool too! Was there any similar discussion about GitHub Actions when implementing pre-commit @kou ?
@AlenkaF Absolutely; that works great from the command line, but not from an IDE where it'll try to run all of the pre-commit hooks and not just the Python one, which is where folks could get tripped up if they don't have Ruby (or R if not R folks!) installed, so perhaps worth us mentioning in the docs?
Ah, got it. I am sure that is an issue in R, that's unfortunate.
In Python, though, I am not sure how many devs use IDE to run that? How does VS Code run pre-commit automatically?
Ah, got it. I am sure that is an issue in R, that's unfortunate. In Python, though, I am not sure how many devs use IDE to run that? How does VS Code run pre-commit automatically?
If the user has pre-commit installed/configured and then clicks on the button in the UI in VS Code to commit/push (rather than using the terminal) it will automatically run all hooks.
Activity
kou commentedon Oct 26, 2025
I think that the Rubocob hook is initialized with
files: \.rb$.How about using
nice pre-commit run --show-diff-on-failure --color=always --all-files rfor R development?thisisnic commentedon Oct 26, 2025
Just for additional context, I was on a fresh Ubuntu install and whichever pre-commit command ran was activated by the RStudio IDE when I hit the commit button. I solved it by just installing it but it might trip up other contributors.
I've also had similar issues in VS Code - I think it's an "interacting with git in an IDE" problem.
If it's possible, I'd prefer to find a solution which doesn't require using a specific command as I think it'll be off-putting to new or occasional contributors.
thisisnic commentedon Oct 26, 2025
I took a look and it doesn't look like it is, looking at lines 243-254 below.
https://github.com/apache/arrow/blob/main/.pre-commit-config.yaml
thisisnic commentedon Oct 28, 2025
I had a bit more of a look into it, that wasn't the actual problem and it doesn't solve the issue. The rubocop hook itself is configured to run on only Ruby files, so including the
filesfilter or not becomes redundant.There is still the issue that it tries to install regardless of whether it's a Ruby PR or not.
See below for LLM summary of what I tried.
I'm going to remove the instructions to use pre-commit from the R docs as it creates a barrier for new contributors, but otherwise I think no changes needed here as none of the alternatives suggested seem like good options.
I feel this is going to create barriers for new contributors in other implementations if they try to use pre-commit. Maybe we want to update the docs to mention that it'll install everything?
CC @AlenkaF as well.
claude summary below
After investigating, the proposed fix (files: .rb$ filter) doesn't actually solve the issue. Here's why:
What we found:
Testing:
Why this is problematic:
Possible solutions:
The fundamental issue is that pre-commit's design installs all environments upfront, and there's no way to make an environment optional based on what's available on the system.
kou commentedon Oct 29, 2025
How about implementing auto-fix GitHub Actions for new contributors so that they don't need to run pre-commit on local?
I think that something like the following will work:
thisisnic commentedon Oct 29, 2025
I really like this idea, sounds good!
AlenkaF commentedon Oct 29, 2025
Hm, I haven't ran into anything similar. In Python we use:
pre-commit run --show-diff-on-failure --color=always --all-files pythonthat is what @kou suggested, the command is included in the dev docs and it works very well.
Having auto-fix GitHub Actions for new contributors sounds cool too! Was there any similar discussion about GitHub Actions when implementing pre-commit @kou ?
thisisnic commentedon Oct 29, 2025
@AlenkaF Absolutely; that works great from the command line, but not from an IDE where it'll try to run all of the pre-commit hooks and not just the Python one, which is where folks could get tripped up if they don't have Ruby (or R if not R folks!) installed, so perhaps worth us mentioning in the docs?
AlenkaF commentedon Oct 29, 2025
Ah, got it. I am sure that is an issue in R, that's unfortunate.
In Python, though, I am not sure how many devs use IDE to run that? How does VS Code run pre-commit automatically?
thisisnic commentedon Oct 29, 2025
If the user has pre-commit installed/configured and then clicks on the button in the UI in VS Code to commit/push (rather than using the terminal) it will automatically run all hooks.
AlenkaF commentedon Oct 30, 2025
Ah, good to know. Thanks!
I think it would be worth mentioning that in the docs, yes 👍
kou commentedon Oct 31, 2025
No. But the "autotone" job may be related. We had the "autotune" job: #6932
But it didn't work. So it was removed: #44649
The "autotune" job runs on apache/arrow. But #47937 (comment) runs on fork. I think that we can fix the permission problem by this.
apacheGH-47937: [dev][R] Replace linr with jarl for R linting / pre-c…
GH-46646: [dev][R] Replace linr with jarl for R linting / pre-commit …