question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ruby hooks failing with rbenv installed

See original GitHub issue

Pre-commit has been failing for the past few weeks.

https://gist.github.com/ThatGerber/d6533155848076b25e5e0d5cb02e20eb

Seems to be an issue with the ruby (rbenv) environment.

Tried running pre-commit clean && pre-commit but it returns the same issue. Setting rbenv global 2.2.4 and rbenv shell 2.2.4 does help either.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, May 17, 2016

Ah I can reproduce with the following (in a docker container)

    2  apt-get update
    3  apt-get install git libssl-dev libreadline-dev nano virtualenv python
    4  git clone http://github.com/rbenv/rbenv ~/.rbenv
    5  cd ~/.rbenv/
    7  git checkout 9fdce5d
   13  cd ~/.rbenv/
   15  apt-get install build-essential
   16  apt-get install curl
   17  ./src/configure 
   18  make -C src
  # Add the rbenv stuff to bashrc
   26  nano ~/.bashrc 
   27  . ~/.bashrc
   29  git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
   33  apt-get install libyaml-dev
   36  rbenv install 2.2.4
   38  rbenv global 2.2.4
...
    2  cd ~
    3  virtualenv venv
    4  . venv/bin/activate
    6  apt-get install python-dev python3-dev -y
    7  pip install pre-commit
    8  git clone git://github.com/pre-commit/demo-repo
    9  cd demo-repo/
   # Remove all the hooks except for the ruby one
   10  nano .pre-commit-config.yaml 
   13  pre-commit run --all-files

And then:

(venv) root@1fcbf03f029a:~/demo-repo# pre-commit run --all-files
[INFO] Initializing environment for git://github.com/pre-commit/mirrors-scss-lint.
[INFO] Installing environment for git://github.com/pre-commit/mirrors-scss-lint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: Command: (u'/bin/bash', u'/root/.rbenv/shims/gem', 'build', '__fake_gem.gemspec')
Return code: 1
Expected return code: 0
Output: (none)
Errors: 
    rbenv: version `default' is not installed (set by RBENV_VERSION environment variable)

This patch seems to fix it \o/

--- a/pre_commit/languages/ruby.py
+++ b/pre_commit/languages/ruby.py
@@ -19,16 +19,18 @@ ENVIRONMENT_DIR = 'rbenv'


 def get_env_patch(venv, language_version):
-    return (
+    patches = (
         ('GEM_HOME', os.path.join(venv, 'gems')),
         ('RBENV_ROOT', venv),
-        ('RBENV_VERSION', language_version),
         ('PATH', (
             os.path.join(venv, 'gems', 'bin'), os.pathsep,
             os.path.join(venv, 'shims'), os.pathsep,
             os.path.join(venv, 'bin'), os.pathsep, Var('PATH'),
         )),
     )
+    if language_version != 'default':
+        patches += (('RBENV_VERSION', language_version),)
+    return patches


 @contextlib.contextmanager
0reactions
asottilecommented, May 17, 2016

This should be fixed in 0.8.1, please check it out!

Thanks again for the report 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git post-receive hook not using ruby version specified by rbenv
I'm deploying code to an ubuntu server which I've declared as a git remote with git push prod master . But it's using...
Read more >
Plugins - RubyGems Guides
Automatically runs rbenv rehash after installing or uninstalling gems. This plugin is deprecated since its behavior is now included in rbenv core. rubygems-desc....
Read more >
doc/troubleshooting/ruby.md · main - GitLab Development Kit
The installation of the thrift v0.14.0 gem during bundle install can fail with the following error due to a known bug.
Read more >
[Solved]-rbenv won't hold a global version-ruby
You're running into this issue because rbenv is designed to work on a per user basis, not as a "global" program. You've seen...
Read more >
Rbenv — How it works - Medium
You install different ruby versions with rbenv install version and ... I happen to read more on other topics like rbenv hooks and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found