From f123e64c2579da3e9bf4d1464845acadbfb2ae54 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 14 Mar 2014 10:45:00 -0700 Subject: [PATCH] Ruby should work now --- .pre-commit-config.yaml | 10 +++++++++- pre_commit/languages/ruby.py | 33 +++++++++++++++++++++++++++++++-- scripts/__rvm-env.sh | 19 +++++++++++++++++++ setup.py | 5 ++++- 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100755 scripts/__rvm-env.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1fc358a5..2e2af43b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,4 +13,12 @@ hooks: - id: jshint - files: '*.js' \ No newline at end of file + files: '*.js' + +- + repo: git@github.com:pre-commit/scss-lint + sha: 425536b1b77d9e836068edde4fb3101bea6e7dd8 + hooks: + - + id: scss-lint + files: '*.scss' diff --git a/pre_commit/languages/ruby.py b/pre_commit/languages/ruby.py index e2e40da4..361ba13f 100644 --- a/pre_commit/languages/ruby.py +++ b/pre_commit/languages/ruby.py @@ -1,7 +1,36 @@ +import contextlib +from plumbum import local + +from pre_commit.languages import helpers + + +RVM_ENV = 'rvm_env' + + +class RubyEnv(object): + def __init__(self): + self.env_prefix = '. {0}/.rvm/scripts/rvm'.format(RVM_ENV) + + def run(self, cmd, **kwargs): + return local['bash']['-c', ' '.join([self.env_prefix, cmd])].run(**kwargs) + + +@contextlib.contextmanager +def in_env(): + yield RubyEnv() + + def install_environment(): - raise NotImplementedError + # Return immediately if we already have a virtualenv + if local.path(RVM_ENV).exists(): + return + + local['__rvm-env.sh'][RVM_ENV]() + with in_env() as env: + env.run('bundle install') def run_hook(hook, file_args): - raise NotImplementedError \ No newline at end of file + with in_env() as env: + return helpers.run_hook(env, hook, file_args) \ No newline at end of file diff --git a/scripts/__rvm-env.sh b/scripts/__rvm-env.sh new file mode 100755 index 00000000..d4dbd567 --- /dev/null +++ b/scripts/__rvm-env.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +if [ $# -ne 1 ] || [ $1 = "--help" ] || [ $1 = "-h" ]; then + echo "usage: $0 RVM_ENV_DIR [--help]" + echo " RVM_ENV_DIR - Directory to create rvm environment in" + exit 1 +fi + + +# Get the rvm installer. This is a known version that works reasonably well +RVM_INSTALLER=https://raw.github.com/wayneeseguin/rvm/d80282de1f2b2b1ff51740e05d9f5d84ebf3209f/binscripts/rvm-installer + +env_dir=$1 +mkdir "$env_dir" || exit 1 +full_env_dir=`pwd`"/$env_dir" + + +\curl -L "$RVM_INSTALLER" | HOME=$full_env_dir bash -s -- stable --user-install --ignore-dotfiles || exit 1 +bash -c '. '"$env_dir"'/.rvm/scripts/rvm && rvm install ruby' || exit 1 diff --git a/setup.py b/setup.py index cb17fcdf..c50827d5 100644 --- a/setup.py +++ b/setup.py @@ -23,5 +23,8 @@ setup( 'validate-config = pre_commit.entry_points:validate_config_func', 'validate-manifest = pre_commit.entry_points:validate_manifest_func', ], - } + }, + scripts=[ + 'scripts/__rvm-env.sh', + ], )