mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 04:50:20 -06:00
Attempt ruby-download before ruby-build.
This commit is contained in:
@@ -4,6 +4,7 @@ import contextlib
|
||||
import io
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
from pre_commit.prefixed_command_runner import CalledProcessError
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
|
||||
|
||||
@@ -28,6 +29,12 @@ def _install_rbenv(repo_cmd_runner, version='default'):
|
||||
|
||||
# Only install ruby-build if the version is specified
|
||||
if version != 'default':
|
||||
# ruby-download
|
||||
repo_cmd_runner.run([
|
||||
'git', 'clone', 'git://github.com/garnieretienne/rvm-download',
|
||||
'{prefix}rbenv/plugins/ruby-download',
|
||||
])
|
||||
# ruby-build
|
||||
repo_cmd_runner.run([
|
||||
'git', 'clone', 'git://github.com/sstephenson/ruby-build',
|
||||
'{prefix}rbenv/plugins/ruby-build',
|
||||
@@ -57,6 +64,14 @@ def _install_rbenv(repo_cmd_runner, version='default'):
|
||||
activate_file.write('export RBENV_VERSION="{0}"\n'.format(version))
|
||||
|
||||
|
||||
def _install_ruby(environment, version):
|
||||
try:
|
||||
environment.run('rbenv download {0}'.format(version))
|
||||
except CalledProcessError:
|
||||
# Failed to download from mirror for some reason, build it instead
|
||||
environment.run('rbenv install {0}'.format(version))
|
||||
|
||||
|
||||
def install_environment(repo_cmd_runner, version='default'):
|
||||
with clean_path_on_failure(repo_cmd_runner.path('rbenv')):
|
||||
# TODO: this currently will fail if there's no version specified and
|
||||
@@ -64,7 +79,7 @@ def install_environment(repo_cmd_runner, version='default'):
|
||||
_install_rbenv(repo_cmd_runner, version=version)
|
||||
with in_env(repo_cmd_runner) as ruby_env:
|
||||
if version != 'default':
|
||||
ruby_env.run('rbenv install {0}'.format(version))
|
||||
_install_ruby(ruby_env, version)
|
||||
ruby_env.run(
|
||||
'cd {prefix} && gem build *.gemspec && gem install *.gem',
|
||||
)
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
name: Ruby Hook
|
||||
entry: ruby_hook
|
||||
language: ruby
|
||||
language_version: 1.9.3-p547
|
||||
language_version: 1.9.3-p484
|
||||
files: \.rb$
|
||||
@@ -93,8 +93,8 @@ def ruby_hooks_repo(dummy_git_repo):
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def ruby_1_9_3_p547_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'ruby_1_9_3_p547_hooks_repo')
|
||||
def ruby_1_9_3_hooks_repo(dummy_git_repo):
|
||||
yield _make_repo(dummy_git_repo, 'ruby_1_9_3_hooks_repo')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
@@ -149,8 +149,8 @@ def config_for_ruby_hooks_repo(ruby_hooks_repo):
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_ruby_1_9_3_p547_hooks_repo(ruby_1_9_3_p547_hooks_repo):
|
||||
yield _make_config(ruby_1_9_3_p547_hooks_repo, 'ruby_hook')
|
||||
def config_for_ruby_1_9_3_hooks_repo(ruby_1_9_3_hooks_repo):
|
||||
yield _make_config(ruby_1_9_3_hooks_repo, 'ruby_hook')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
|
||||
@@ -44,11 +44,11 @@ def test_run_versioned_node_hook(config_for_node_0_11_8_hooks_repo, store):
|
||||
@pytest.mark.herpderp
|
||||
@skipif_slowtests_false
|
||||
@pytest.mark.integration
|
||||
def test_run_versioned_ruby_hook(config_for_ruby_1_9_3_p547_hooks_repo, store):
|
||||
repo = Repository.create(config_for_ruby_1_9_3_p547_hooks_repo, store)
|
||||
def test_run_versioned_ruby_hook(config_for_ruby_1_9_3_hooks_repo, store):
|
||||
repo = Repository.create(config_for_ruby_1_9_3_hooks_repo, store)
|
||||
ret = repo.run_hook('ruby_hook', [])
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == '1.9.3\n547\nHello world from a ruby hook\n'
|
||||
assert ret[1] == '1.9.3\n484\nHello world from a ruby hook\n'
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
|
||||
Reference in New Issue
Block a user