prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  bug: rbenv: no such command `install'
  fails: https://travis-ci.com/github/mozilla-platform-ops/ronin_puppet/jobs/420816191
  passes: https://travis-ci.com/github/mozilla-platform-ops/ronin_puppet/jobs/420881311
  
  The difference in the failing job is pre-commit 2.8.1 (passing is using 2.7.1). It seems similar to https://stackoverflow.com/questions/17618113/the-command-rbenv-install-is-missing... perhaps Travis doesn't include that particular bit.
  
  failure log snippet:
  ```
  $ pre-commit run --all-files
  
  [INFO] Installing environment for https://github.com/chriskuehl/puppet-pre-commit-hooks.git.
  
  [INFO] Once installed this environment will be reused.
  
  [INFO] This may take a few minutes...
  
  An unexpected error has occurred: CalledProcessError: command: ('/bin/bash', '/home/travis/.cache/pre-commit/repoz146d2mg/rbenv-default/bin/rbenv', 'install', 'default')
  
  return code: 1
  
  expected return code: 0
  
  stdout: (none)
  
  stderr:
  
      rbenv: no such command `install'
  
      
  
  Check the log at /home/travis/.cache/pre-commit/pre-commit.log
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pre_commit/languages/ruby.py`
  Content:
  ```
  1 import contextlib
  2 import functools
  3 import os.path
  4 import shutil
  5 import tarfile
  6 from typing import Generator
  7 from typing import Sequence
  8 from typing import Tuple
  9 
  10 import pre_commit.constants as C
  11 from pre_commit.envcontext import envcontext
  12 from pre_commit.envcontext import PatchesT
  13 from pre_commit.envcontext import UNSET
  14 from pre_commit.envcontext import Var
  15 from pre_commit.hook import Hook
  16 from pre_commit.languages import helpers
  17 from pre_commit.prefix import Prefix
  18 from pre_commit.util import CalledProcessError
  19 from pre_commit.util import clean_path_on_failure
  20 from pre_commit.util import resource_bytesio
  21 
  22 ENVIRONMENT_DIR = 'rbenv'
  23 healthy = helpers.basic_healthy
  24 
  25 
  26 @functools.lru_cache(maxsize=1)
  27 def get_default_version() -> str:
  28     if all(helpers.exe_exists(exe) for exe in ('ruby', 'gem')):
  29         return 'system'
  30     else:
  31         return C.DEFAULT
  32 
  33 
  34 def get_env_patch(
  35         venv: str,
  36         language_version: str,
  37 ) -> PatchesT:
  38     patches: PatchesT = (
  39         ('GEM_HOME', os.path.join(venv, 'gems')),
  40         ('GEM_PATH', UNSET),
  41         ('BUNDLE_IGNORE_CONFIG', '1'),
  42     )
  43     if language_version == 'system':
  44         patches += (
  45             (
  46                 'PATH', (
  47                     os.path.join(venv, 'gems', 'bin'), os.pathsep,
  48                     Var('PATH'),
  49                 ),
  50             ),
  51         )
  52     else:  # pragma: win32 no cover
  53         patches += (
  54             ('RBENV_ROOT', venv),
  55             ('RBENV_VERSION', language_version),
  56             (
  57                 'PATH', (
  58                     os.path.join(venv, 'gems', 'bin'), os.pathsep,
  59                     os.path.join(venv, 'shims'), os.pathsep,
  60                     os.path.join(venv, 'bin'), os.pathsep, Var('PATH'),
  61                 ),
  62             ),
  63         )
  64     return patches
  65 
  66 
  67 @contextlib.contextmanager
  68 def in_env(
  69         prefix: Prefix,
  70         language_version: str,
  71 ) -> Generator[None, None, None]:
  72     envdir = prefix.path(
  73         helpers.environment_dir(ENVIRONMENT_DIR, language_version),
  74     )
  75     with envcontext(get_env_patch(envdir, language_version)):
  76         yield
  77 
  78 
  79 def _extract_resource(filename: str, dest: str) -> None:
  80     with resource_bytesio(filename) as bio:
  81         with tarfile.open(fileobj=bio) as tf:
  82             tf.extractall(dest)
  83 
  84 
  85 def _install_rbenv(
  86         prefix: Prefix,
  87         version: str,
  88 ) -> None:  # pragma: win32 no cover
  89     directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
  90 
  91     _extract_resource('rbenv.tar.gz', prefix.path('.'))
  92     shutil.move(prefix.path('rbenv'), prefix.path(directory))
  93 
  94     # Only install ruby-build if the version is specified
  95     if version != C.DEFAULT:
  96         plugins_dir = prefix.path(directory, 'plugins')
  97         _extract_resource('ruby-download.tar.gz', plugins_dir)
  98         _extract_resource('ruby-build.tar.gz', plugins_dir)
  99 
  100 
  101 def _install_ruby(
  102         prefix: Prefix,
  103         version: str,
  104 ) -> None:  # pragma: win32 no cover
  105     try:
  106         helpers.run_setup_cmd(prefix, ('rbenv', 'download', version))
  107     except CalledProcessError:  # pragma: no cover (usually find with download)
  108         # Failed to download from mirror for some reason, build it instead
  109         helpers.run_setup_cmd(prefix, ('rbenv', 'install', version))
  110 
  111 
  112 def install_environment(
  113         prefix: Prefix, version: str, additional_dependencies: Sequence[str],
  114 ) -> None:
  115     additional_dependencies = tuple(additional_dependencies)
  116     directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
  117     with clean_path_on_failure(prefix.path(directory)):
  118         if version != 'system':  # pragma: win32 no cover
  119             _install_rbenv(prefix, version)
  120             with in_env(prefix, version):
  121                 # Need to call this before installing so rbenv's directories
  122                 # are set up
  123                 helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))
  124                 # XXX: this will *always* fail if `version == C.DEFAULT`
  125                 _install_ruby(prefix, version)
  126                 # Need to call this after installing to set up the shims
  127                 helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))
  128 
  129         with in_env(prefix, version):
  130             helpers.run_setup_cmd(
  131                 prefix, ('gem', 'build', *prefix.star('.gemspec')),
  132             )
  133             helpers.run_setup_cmd(
  134                 prefix,
  135                 (
  136                     'gem', 'install',
  137                     '--no-document', '--no-format-executable',
  138                     *prefix.star('.gem'), *additional_dependencies,
  139                 ),
  140             )
  141 
  142 
  143 def run_hook(
  144         hook: Hook,
  145         file_args: Sequence[str],
  146         color: bool,
  147 ) -> Tuple[int, bytes]:
  148     with in_env(hook.prefix, hook.language_version):
  149         return helpers.run_xargs(hook, hook.cmd, file_args, color=color)
  150
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pre_commit/languages/ruby.py b/pre_commit/languages/ruby.py
  --- a/pre_commit/languages/ruby.py
  +++ b/pre_commit/languages/ruby.py
  @@ -121,8 +121,8 @@
                   # Need to call this before installing so rbenv's directories
                   # are set up
                   helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))
  -                # XXX: this will *always* fail if `version == C.DEFAULT`
  -                _install_ruby(prefix, version)
  +                if version != C.DEFAULT:
  +                    _install_ruby(prefix, version)
                   # Need to call this after installing to set up the shims
                   helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))
  
verification_info: {"golden_diff": "diff --git a/pre_commit/languages/ruby.py b/pre_commit/languages/ruby.py\n--- a/pre_commit/languages/ruby.py\n+++ b/pre_commit/languages/ruby.py\n@@ -121,8 +121,8 @@\n                 # Need to call this before installing so rbenv's directories\n                 # are set up\n                 helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))\n-                # XXX: this will *always* fail if `version == C.DEFAULT`\n-                _install_ruby(prefix, version)\n+                if version != C.DEFAULT:\n+                    _install_ruby(prefix, version)\n                 # Need to call this after installing to set up the shims\n                 helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))\n", "issue": "bug: rbenv: no such command `install'\nfails: https://travis-ci.com/github/mozilla-platform-ops/ronin_puppet/jobs/420816191\r\npasses: https://travis-ci.com/github/mozilla-platform-ops/ronin_puppet/jobs/420881311\r\n\r\nThe difference in the failing job is pre-commit 2.8.1 (passing is using 2.7.1). It seems similar to https://stackoverflow.com/questions/17618113/the-command-rbenv-install-is-missing... perhaps Travis doesn't include that particular bit.\r\n\r\nfailure log snippet:\r\n```\r\n$ pre-commit run --all-files\r\n\r\n[INFO] Installing environment for https://github.com/chriskuehl/puppet-pre-commit-hooks.git.\r\n\r\n[INFO] Once installed this environment will be reused.\r\n\r\n[INFO] This may take a few minutes...\r\n\r\nAn unexpected error has occurred: CalledProcessError: command: ('/bin/bash', '/home/travis/.cache/pre-commit/repoz146d2mg/rbenv-default/bin/rbenv', 'install', 'default')\r\n\r\nreturn code: 1\r\n\r\nexpected return code: 0\r\n\r\nstdout: (none)\r\n\r\nstderr:\r\n\r\n    rbenv: no such command `install'\r\n\r\n    \r\n\r\nCheck the log at /home/travis/.cache/pre-commit/pre-commit.log\r\n```\n", "before_files": [{"content": "import contextlib\nimport functools\nimport os.path\nimport shutil\nimport tarfile\nfrom typing import Generator\nfrom typing import Sequence\nfrom typing import Tuple\n\nimport pre_commit.constants as C\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import UNSET\nfrom pre_commit.envcontext import Var\nfrom pre_commit.hook import Hook\nfrom pre_commit.languages import helpers\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import CalledProcessError\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import resource_bytesio\n\nENVIRONMENT_DIR = 'rbenv'\nhealthy = helpers.basic_healthy\n\n\n@functools.lru_cache(maxsize=1)\ndef get_default_version() -> str:\n    if all(helpers.exe_exists(exe) for exe in ('ruby', 'gem')):\n        return 'system'\n    else:\n        return C.DEFAULT\n\n\ndef get_env_patch(\n        venv: str,\n        language_version: str,\n) -> PatchesT:\n    patches: PatchesT = (\n        ('GEM_HOME', os.path.join(venv, 'gems')),\n        ('GEM_PATH', UNSET),\n        ('BUNDLE_IGNORE_CONFIG', '1'),\n    )\n    if language_version == 'system':\n        patches += (\n            (\n                'PATH', (\n                    os.path.join(venv, 'gems', 'bin'), os.pathsep,\n                    Var('PATH'),\n                ),\n            ),\n        )\n    else:  # pragma: win32 no cover\n        patches += (\n            ('RBENV_ROOT', venv),\n            ('RBENV_VERSION', language_version),\n            (\n                'PATH', (\n                    os.path.join(venv, 'gems', 'bin'), os.pathsep,\n                    os.path.join(venv, 'shims'), os.pathsep,\n                    os.path.join(venv, 'bin'), os.pathsep, Var('PATH'),\n                ),\n            ),\n        )\n    return patches\n\n\n@contextlib.contextmanager\ndef in_env(\n        prefix: Prefix,\n        language_version: str,\n) -> Generator[None, None, None]:\n    envdir = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, language_version),\n    )\n    with envcontext(get_env_patch(envdir, language_version)):\n        yield\n\n\ndef _extract_resource(filename: str, dest: str) -> None:\n    with resource_bytesio(filename) as bio:\n        with tarfile.open(fileobj=bio) as tf:\n            tf.extractall(dest)\n\n\ndef _install_rbenv(\n        prefix: Prefix,\n        version: str,\n) -> None:  # pragma: win32 no cover\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n\n    _extract_resource('rbenv.tar.gz', prefix.path('.'))\n    shutil.move(prefix.path('rbenv'), prefix.path(directory))\n\n    # Only install ruby-build if the version is specified\n    if version != C.DEFAULT:\n        plugins_dir = prefix.path(directory, 'plugins')\n        _extract_resource('ruby-download.tar.gz', plugins_dir)\n        _extract_resource('ruby-build.tar.gz', plugins_dir)\n\n\ndef _install_ruby(\n        prefix: Prefix,\n        version: str,\n) -> None:  # pragma: win32 no cover\n    try:\n        helpers.run_setup_cmd(prefix, ('rbenv', 'download', version))\n    except CalledProcessError:  # pragma: no cover (usually find with download)\n        # Failed to download from mirror for some reason, build it instead\n        helpers.run_setup_cmd(prefix, ('rbenv', 'install', version))\n\n\ndef install_environment(\n        prefix: Prefix, version: str, additional_dependencies: Sequence[str],\n) -> None:\n    additional_dependencies = tuple(additional_dependencies)\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n    with clean_path_on_failure(prefix.path(directory)):\n        if version != 'system':  # pragma: win32 no cover\n            _install_rbenv(prefix, version)\n            with in_env(prefix, version):\n                # Need to call this before installing so rbenv's directories\n                # are set up\n                helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))\n                # XXX: this will *always* fail if `version == C.DEFAULT`\n                _install_ruby(prefix, version)\n                # Need to call this after installing to set up the shims\n                helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))\n\n        with in_env(prefix, version):\n            helpers.run_setup_cmd(\n                prefix, ('gem', 'build', *prefix.star('.gemspec')),\n            )\n            helpers.run_setup_cmd(\n                prefix,\n                (\n                    'gem', 'install',\n                    '--no-document', '--no-format-executable',\n                    *prefix.star('.gem'), *additional_dependencies,\n                ),\n            )\n\n\ndef run_hook(\n        hook: Hook,\n        file_args: Sequence[str],\n        color: bool,\n) -> Tuple[int, bytes]:\n    with in_env(hook.prefix, hook.language_version):\n        return helpers.run_xargs(hook, hook.cmd, file_args, color=color)\n", "path": "pre_commit/languages/ruby.py"}], "after_files": [{"content": "import contextlib\nimport functools\nimport os.path\nimport shutil\nimport tarfile\nfrom typing import Generator\nfrom typing import Sequence\nfrom typing import Tuple\n\nimport pre_commit.constants as C\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import UNSET\nfrom pre_commit.envcontext import Var\nfrom pre_commit.hook import Hook\nfrom pre_commit.languages import helpers\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import CalledProcessError\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import resource_bytesio\n\nENVIRONMENT_DIR = 'rbenv'\nhealthy = helpers.basic_healthy\n\n\n@functools.lru_cache(maxsize=1)\ndef get_default_version() -> str:\n    if all(helpers.exe_exists(exe) for exe in ('ruby', 'gem')):\n        return 'system'\n    else:\n        return C.DEFAULT\n\n\ndef get_env_patch(\n        venv: str,\n        language_version: str,\n) -> PatchesT:\n    patches: PatchesT = (\n        ('GEM_HOME', os.path.join(venv, 'gems')),\n        ('GEM_PATH', UNSET),\n        ('BUNDLE_IGNORE_CONFIG', '1'),\n    )\n    if language_version == 'system':\n        patches += (\n            (\n                'PATH', (\n                    os.path.join(venv, 'gems', 'bin'), os.pathsep,\n                    Var('PATH'),\n                ),\n            ),\n        )\n    else:  # pragma: win32 no cover\n        patches += (\n            ('RBENV_ROOT', venv),\n            ('RBENV_VERSION', language_version),\n            (\n                'PATH', (\n                    os.path.join(venv, 'gems', 'bin'), os.pathsep,\n                    os.path.join(venv, 'shims'), os.pathsep,\n                    os.path.join(venv, 'bin'), os.pathsep, Var('PATH'),\n                ),\n            ),\n        )\n    return patches\n\n\n@contextlib.contextmanager\ndef in_env(\n        prefix: Prefix,\n        language_version: str,\n) -> Generator[None, None, None]:\n    envdir = prefix.path(\n        helpers.environment_dir(ENVIRONMENT_DIR, language_version),\n    )\n    with envcontext(get_env_patch(envdir, language_version)):\n        yield\n\n\ndef _extract_resource(filename: str, dest: str) -> None:\n    with resource_bytesio(filename) as bio:\n        with tarfile.open(fileobj=bio) as tf:\n            tf.extractall(dest)\n\n\ndef _install_rbenv(\n        prefix: Prefix,\n        version: str,\n) -> None:  # pragma: win32 no cover\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n\n    _extract_resource('rbenv.tar.gz', prefix.path('.'))\n    shutil.move(prefix.path('rbenv'), prefix.path(directory))\n\n    # Only install ruby-build if the version is specified\n    if version != C.DEFAULT:\n        plugins_dir = prefix.path(directory, 'plugins')\n        _extract_resource('ruby-download.tar.gz', plugins_dir)\n        _extract_resource('ruby-build.tar.gz', plugins_dir)\n\n\ndef _install_ruby(\n        prefix: Prefix,\n        version: str,\n) -> None:  # pragma: win32 no cover\n    try:\n        helpers.run_setup_cmd(prefix, ('rbenv', 'download', version))\n    except CalledProcessError:  # pragma: no cover (usually find with download)\n        # Failed to download from mirror for some reason, build it instead\n        helpers.run_setup_cmd(prefix, ('rbenv', 'install', version))\n\n\ndef install_environment(\n        prefix: Prefix, version: str, additional_dependencies: Sequence[str],\n) -> None:\n    additional_dependencies = tuple(additional_dependencies)\n    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)\n    with clean_path_on_failure(prefix.path(directory)):\n        if version != 'system':  # pragma: win32 no cover\n            _install_rbenv(prefix, version)\n            with in_env(prefix, version):\n                # Need to call this before installing so rbenv's directories\n                # are set up\n                helpers.run_setup_cmd(prefix, ('rbenv', 'init', '-'))\n                if version != C.DEFAULT:\n                    _install_ruby(prefix, version)\n                # Need to call this after installing to set up the shims\n                helpers.run_setup_cmd(prefix, ('rbenv', 'rehash'))\n\n        with in_env(prefix, version):\n            helpers.run_setup_cmd(\n                prefix, ('gem', 'build', *prefix.star('.gemspec')),\n            )\n            helpers.run_setup_cmd(\n                prefix,\n                (\n                    'gem', 'install',\n                    '--no-document', '--no-format-executable',\n                    *prefix.star('.gem'), *additional_dependencies,\n                ),\n            )\n\n\ndef run_hook(\n        hook: Hook,\n        file_args: Sequence[str],\n        color: bool,\n) -> Tuple[int, bytes]:\n    with in_env(hook.prefix, hook.language_version):\n        return helpers.run_xargs(hook, hook.cmd, file_args, color=color)\n", "path": "pre_commit/languages/ruby.py"}]}