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
Is there a deterministic way of checking whether bundle exec is necessary? #486
Sort of related to #433, I've recently found out that bundle exec adds a significant amount of time to commands as opposed to the naked command when the binstub doesn't exist. This is especially important when running linters as a pre-commit hook.
I posted on lefthook's discussion board about this, but our team mostly uses chruby in local environments because it's in our onboarding guide, and y'all seem to more likely to know the answer to this: is there a deterministic or even near-deterministic way of checking whether bundle exec is necessary?
I came up with this pretty naive exec-wrapper script:
All except bundle exec rubocop will pick the latest version of rubocop installed and not the one specified in the Gemfile for the project, which can lead to failures, etc.
I see, that's exactly the answer I was looking for. What if we were using postmodern's gem_home gem or some other "gemset" tool? Is that still a thing? gem_home itself looks pretty out of date.
Sure, I'll file an issue there. I first noticed this when someone else mentioned it happening with them as well in an attempt to improve rubocop boot time.
IMHO gemset tools are pretty much useless nowadays. Having a dedicated gem_home for an app to avoid bundle exec would only work if you wipe out the entire gem home every time you update a gem in Gemfile/Gemfile.lock and then reinstall everything, and only if there are no extra gems installed in the default gem home. Basically, very messy and won't be practical I think. It would also not work if the a default/bundled gems of that Ruby is more recent than what you use (would pick that version instead).
It might be possible to check if vendor/bundle exists and add the $ruby/$ruby_api_version/bin directory to PATH. However, like you pointed out, you might not want all executables to automatically use the bundled version. Also, installing gems into vendor/bundle per-project might consume extra disk space.
I've been using this bash alias to selectively make certain common executables "bundle aware".
It would be nice if rubygems handled this automatically in it's own binstubs which are generated when you install a gem with executables.
yeah, I'm trying to avoidbundle exec for linting because it's so much faster without bundle exec (and runs fine w/ chruby)
I went from greater than 2s running rubocop on 1 staged file to 190ms (with some other tweaks), but bundle exec is a huge chunk of that -- at least 500ms and sometimes up to 1000ms on my machine.
Maybe instead of trying to genericize for all commands, I'll write a specific wrapper for Rubocop. If the Rubocop server is running, then the files have been loaded already and there shouldn't be a need for bundle exec
Activity
eregon commentedon Jan 5, 2023
All except
bundle exec rubocopwill pick the latest version of rubocop installed and not the one specified in the Gemfile for the project, which can lead to failures, etc.That big an overhead for
bundle execseems too much though, could you open an issue at https://github.com/rubygems/rubygems/issues ?mculp commentedon Jan 5, 2023
I see, that's exactly the answer I was looking for. What if we were using postmodern's
gem_homegem or some other "gemset" tool? Is that still a thing?gem_homeitself looks pretty out of date.Sure, I'll file an issue there. I first noticed this when someone else mentioned it happening with them as well in an attempt to improve rubocop boot time.
eregon commentedon Jan 5, 2023
IMHO gemset tools are pretty much useless nowadays. Having a dedicated gem_home for an app to avoid bundle exec would only work if you wipe out the entire gem home every time you update a gem in Gemfile/Gemfile.lock and then reinstall everything, and only if there are no extra gems installed in the default gem home. Basically, very messy and won't be practical I think. It would also not work if the a default/bundled gems of that Ruby is more recent than what you use (would pick that version instead).
postmodern commentedon Jan 6, 2023
It might be possible to check if
vendor/bundleexists and add the$ruby/$ruby_api_version/bindirectory toPATH. However, like you pointed out, you might not want all executables to automatically use the bundled version. Also, installing gems intovendor/bundleper-project might consume extra disk space.I've been using this bash alias to selectively make certain common executables "bundle aware".
It would be nice if rubygems handled this automatically in it's own binstubs which are generated when you install a gem with executables.
mculp commentedon Jan 9, 2023
yeah, I'm trying to avoid
bundle execfor linting because it's so much faster withoutbundle exec(and runs fine w/ chruby)I went from greater than 2s running rubocop on 1 staged file to 190ms (with some other tweaks), but
bundle execis a huge chunk of that -- at least 500ms and sometimes up to 1000ms on my machine.Maybe instead of trying to genericize for all commands, I'll write a specific wrapper for Rubocop. If the Rubocop server is running, then the files have been loaded already and there shouldn't be a need for
bundle exec