22
33import contextlib
44import io
5+ import shutil
56
67from pre_commit .languages import helpers
78from pre_commit .util import CalledProcessError
1617class RubyEnv (helpers .Environment ):
1718 @property
1819 def env_prefix (self ):
19- return '. {{prefix}}{0}/bin/activate &&' .format (ENVIRONMENT_DIR )
20+ return '. {{prefix}}{0}/bin/activate &&' .format (
21+ helpers .environment_dir (ENVIRONMENT_DIR , self .language_version )
22+ )
2023
2124
2225@contextlib .contextmanager
23- def in_env (repo_cmd_runner ):
24- yield RubyEnv (repo_cmd_runner )
26+ def in_env (repo_cmd_runner , language_version ):
27+ yield RubyEnv (repo_cmd_runner , language_version )
2528
2629
2730def _install_rbenv (repo_cmd_runner , version = 'default' ):
31+ directory = helpers .environment_dir (ENVIRONMENT_DIR , version )
32+
2833 with tarfile_open (resource_filename ('rbenv.tar.gz' )) as tf :
2934 tf .extractall (repo_cmd_runner .path ('.' ))
35+ shutil .move (
36+ repo_cmd_runner .path ('rbenv' ), repo_cmd_runner .path (directory ),
37+ )
3038
3139 # Only install ruby-build if the version is specified
3240 if version != 'default' :
3341 # ruby-download
3442 with tarfile_open (resource_filename ('ruby-download.tar.gz' )) as tf :
35- tf .extractall (repo_cmd_runner .path ('rbenv' , 'plugins' ))
43+ tf .extractall (repo_cmd_runner .path (directory , 'plugins' ))
3644
3745 # ruby-build
3846 with tarfile_open (resource_filename ('ruby-build.tar.gz' )) as tf :
39- tf .extractall (repo_cmd_runner .path ('rbenv' , 'plugins' ))
47+ tf .extractall (repo_cmd_runner .path (directory , 'plugins' ))
4048
41- activate_path = repo_cmd_runner .path ('rbenv' , 'bin' , 'activate' )
49+ activate_path = repo_cmd_runner .path (directory , 'bin' , 'activate' )
4250 with io .open (activate_path , 'w' ) as activate_file :
4351 # This is similar to how you would install rbenv to your home directory
4452 # However we do a couple things to make the executables exposed and
@@ -54,7 +62,7 @@ def _install_rbenv(repo_cmd_runner, version='default'):
5462 # directory
5563 "export GEM_HOME='{0}/gems'\n "
5664 'export PATH="$GEM_HOME/bin:$PATH"\n '
57- '\n ' .format (repo_cmd_runner .path ('rbenv' ))
65+ '\n ' .format (repo_cmd_runner .path (directory ))
5866 )
5967
6068 # If we aren't using the system ruby, add a version here
@@ -71,11 +79,12 @@ def _install_ruby(environment, version):
7179
7280
7381def install_environment (repo_cmd_runner , version = 'default' ):
74- with clean_path_on_failure (repo_cmd_runner .path ('rbenv' )):
82+ directory = helpers .environment_dir (ENVIRONMENT_DIR , version )
83+ with clean_path_on_failure (repo_cmd_runner .path (directory )):
7584 # TODO: this currently will fail if there's no version specified and
7685 # there's no system ruby installed. Is this ok?
7786 _install_rbenv (repo_cmd_runner , version = version )
78- with in_env (repo_cmd_runner ) as ruby_env :
87+ with in_env (repo_cmd_runner , version ) as ruby_env :
7988 if version != 'default' :
8089 _install_ruby (ruby_env , version )
8190 ruby_env .run (
@@ -84,5 +93,5 @@ def install_environment(repo_cmd_runner, version='default'):
8493
8594
8695def run_hook (repo_cmd_runner , hook , file_args ):
87- with in_env (repo_cmd_runner ) as env :
96+ with in_env (repo_cmd_runner , hook [ 'language_version' ] ) as env :
8897 return helpers .run_hook (env , hook , file_args )
0 commit comments