mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Attempt ruby-download before ruby-build.
This commit is contained in:
parent
09650b814a
commit
07664a80ca
7 changed files with 24 additions and 9 deletions
|
|
@ -4,6 +4,7 @@ import contextlib
|
||||||
import io
|
import io
|
||||||
|
|
||||||
from pre_commit.languages import helpers
|
from pre_commit.languages import helpers
|
||||||
|
from pre_commit.prefixed_command_runner import CalledProcessError
|
||||||
from pre_commit.util import clean_path_on_failure
|
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
|
# Only install ruby-build if the version is specified
|
||||||
if version != 'default':
|
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([
|
repo_cmd_runner.run([
|
||||||
'git', 'clone', 'git://github.com/sstephenson/ruby-build',
|
'git', 'clone', 'git://github.com/sstephenson/ruby-build',
|
||||||
'{prefix}rbenv/plugins/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))
|
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'):
|
def install_environment(repo_cmd_runner, version='default'):
|
||||||
with clean_path_on_failure(repo_cmd_runner.path('rbenv')):
|
with clean_path_on_failure(repo_cmd_runner.path('rbenv')):
|
||||||
# TODO: this currently will fail if there's no version specified and
|
# 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)
|
_install_rbenv(repo_cmd_runner, version=version)
|
||||||
with in_env(repo_cmd_runner) as ruby_env:
|
with in_env(repo_cmd_runner) as ruby_env:
|
||||||
if version != 'default':
|
if version != 'default':
|
||||||
ruby_env.run('rbenv install {0}'.format(version))
|
_install_ruby(ruby_env, version)
|
||||||
ruby_env.run(
|
ruby_env.run(
|
||||||
'cd {prefix} && gem build *.gemspec && gem install *.gem',
|
'cd {prefix} && gem build *.gemspec && gem install *.gem',
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@
|
||||||
name: Ruby Hook
|
name: Ruby Hook
|
||||||
entry: ruby_hook
|
entry: ruby_hook
|
||||||
language: ruby
|
language: ruby
|
||||||
language_version: 1.9.3-p547
|
language_version: 1.9.3-p484
|
||||||
files: \.rb$
|
files: \.rb$
|
||||||
|
|
@ -93,8 +93,8 @@ def ruby_hooks_repo(dummy_git_repo):
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def ruby_1_9_3_p547_hooks_repo(dummy_git_repo):
|
def ruby_1_9_3_hooks_repo(dummy_git_repo):
|
||||||
yield _make_repo(dummy_git_repo, 'ruby_1_9_3_p547_hooks_repo')
|
yield _make_repo(dummy_git_repo, 'ruby_1_9_3_hooks_repo')
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
|
|
@ -149,8 +149,8 @@ def config_for_ruby_hooks_repo(ruby_hooks_repo):
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def config_for_ruby_1_9_3_p547_hooks_repo(ruby_1_9_3_p547_hooks_repo):
|
def config_for_ruby_1_9_3_hooks_repo(ruby_1_9_3_hooks_repo):
|
||||||
yield _make_config(ruby_1_9_3_p547_hooks_repo, 'ruby_hook')
|
yield _make_config(ruby_1_9_3_hooks_repo, 'ruby_hook')
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@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
|
@pytest.mark.herpderp
|
||||||
@skipif_slowtests_false
|
@skipif_slowtests_false
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_run_versioned_ruby_hook(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_p547_hooks_repo, store)
|
repo = Repository.create(config_for_ruby_1_9_3_hooks_repo, store)
|
||||||
ret = repo.run_hook('ruby_hook', [])
|
ret = repo.run_hook('ruby_hook', [])
|
||||||
assert ret[0] == 0
|
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
|
@pytest.mark.integration
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue