Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 07664a8

Browse files
committed
Attempt ruby-download before ruby-build.
1 parent 09650b8 commit 07664a8

7 files changed

Lines changed: 24 additions & 9 deletions

File tree

pre_commit/languages/ruby.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io
55

66
from pre_commit.languages import helpers
7+
from pre_commit.prefixed_command_runner import CalledProcessError
78
from pre_commit.util import clean_path_on_failure
89

910

@@ -28,6 +29,12 @@ def _install_rbenv(repo_cmd_runner, version='default'):
2829

2930
# Only install ruby-build if the version is specified
3031
if version != 'default':
32+
# ruby-download
33+
repo_cmd_runner.run([
34+
'git', 'clone', 'git://github.com/garnieretienne/rvm-download',
35+
'{prefix}rbenv/plugins/ruby-download',
36+
])
37+
# ruby-build
3138
repo_cmd_runner.run([
3239
'git', 'clone', 'git://github.com/sstephenson/ruby-build',
3340
'{prefix}rbenv/plugins/ruby-build',
@@ -57,14 +64,22 @@ def _install_rbenv(repo_cmd_runner, version='default'):
5764
activate_file.write('export RBENV_VERSION="{0}"\n'.format(version))
5865

5966

67+
def _install_ruby(environment, version):
68+
try:
69+
environment.run('rbenv download {0}'.format(version))
70+
except CalledProcessError:
71+
# Failed to download from mirror for some reason, build it instead
72+
environment.run('rbenv install {0}'.format(version))
73+
74+
6075
def install_environment(repo_cmd_runner, version='default'):
6176
with clean_path_on_failure(repo_cmd_runner.path('rbenv')):
6277
# TODO: this currently will fail if there's no version specified and
6378
# there's no system ruby installed. Is this ok?
6479
_install_rbenv(repo_cmd_runner, version=version)
6580
with in_env(repo_cmd_runner) as ruby_env:
6681
if version != 'default':
67-
ruby_env.run('rbenv install {0}'.format(version))
82+
_install_ruby(ruby_env, version)
6883
ruby_env.run(
6984
'cd {prefix} && gem build *.gemspec && gem install *.gem',
7085
)
File renamed without changes.

testing/resources/ruby_1_9_3_p547_hooks_repo/bin/ruby_hook renamed to testing/resources/ruby_1_9_3_hooks_repo/bin/ruby_hook

File renamed without changes.

testing/resources/ruby_1_9_3_p547_hooks_repo/hooks.yaml renamed to testing/resources/ruby_1_9_3_hooks_repo/hooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
name: Ruby Hook
33
entry: ruby_hook
44
language: ruby
5-
language_version: 1.9.3-p547
5+
language_version: 1.9.3-p484
66
files: \.rb$

testing/resources/ruby_1_9_3_p547_hooks_repo/ruby_hook.gemspec renamed to testing/resources/ruby_1_9_3_hooks_repo/ruby_hook.gemspec

File renamed without changes.

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def ruby_hooks_repo(dummy_git_repo):
9393

9494

9595
@pytest.yield_fixture
96-
def ruby_1_9_3_p547_hooks_repo(dummy_git_repo):
97-
yield _make_repo(dummy_git_repo, 'ruby_1_9_3_p547_hooks_repo')
96+
def ruby_1_9_3_hooks_repo(dummy_git_repo):
97+
yield _make_repo(dummy_git_repo, 'ruby_1_9_3_hooks_repo')
9898

9999

100100
@pytest.yield_fixture
@@ -149,8 +149,8 @@ def config_for_ruby_hooks_repo(ruby_hooks_repo):
149149

150150

151151
@pytest.yield_fixture
152-
def config_for_ruby_1_9_3_p547_hooks_repo(ruby_1_9_3_p547_hooks_repo):
153-
yield _make_config(ruby_1_9_3_p547_hooks_repo, 'ruby_hook')
152+
def config_for_ruby_1_9_3_hooks_repo(ruby_1_9_3_hooks_repo):
153+
yield _make_config(ruby_1_9_3_hooks_repo, 'ruby_hook')
154154

155155

156156
@pytest.yield_fixture

tests/repository_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def test_run_versioned_node_hook(config_for_node_0_11_8_hooks_repo, store):
4444
@pytest.mark.herpderp
4545
@skipif_slowtests_false
4646
@pytest.mark.integration
47-
def test_run_versioned_ruby_hook(config_for_ruby_1_9_3_p547_hooks_repo, store):
48-
repo = Repository.create(config_for_ruby_1_9_3_p547_hooks_repo, store)
47+
def test_run_versioned_ruby_hook(config_for_ruby_1_9_3_hooks_repo, store):
48+
repo = Repository.create(config_for_ruby_1_9_3_hooks_repo, store)
4949
ret = repo.run_hook('ruby_hook', [])
5050
assert ret[0] == 0
51-
assert ret[1] == '1.9.3\n547\nHello world from a ruby hook\n'
51+
assert ret[1] == '1.9.3\n484\nHello world from a ruby hook\n'
5252

5353

5454
@pytest.mark.integration

0 commit comments

Comments
 (0)