mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 10:01:46 +04:00
Add support for python and ruby local hooks
This commit is contained in:
parent
e5669ca135
commit
377cffbd27
12 changed files with 54 additions and 11 deletions
|
|
@ -58,6 +58,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
): # pragma: windows no cover
|
||||
assert repo_cmd_runner.exists('Dockerfile'), (
|
||||
'No Dockerfile was found in the hook repository'
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
):
|
||||
helpers.assert_version_default('golang', version)
|
||||
directory = repo_cmd_runner.path(
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
): # pragma: windows no cover
|
||||
additional_dependencies = tuple(additional_dependencies)
|
||||
assert repo_cmd_runner.exists('package.json')
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
):
|
||||
"""Installation for pcre type is a noop."""
|
||||
raise AssertionError('Cannot install pcre repo.')
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
):
|
||||
additional_dependencies = tuple(additional_dependencies)
|
||||
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
|
||||
|
|
@ -73,10 +74,12 @@ def install_environment(
|
|||
else:
|
||||
venv_cmd.extend(['-p', os.path.realpath(sys.executable)])
|
||||
repo_cmd_runner.run(venv_cmd, cwd='/')
|
||||
to_install = () if is_local_hook else ('.')
|
||||
to_install += additional_dependencies
|
||||
with in_env(repo_cmd_runner, version):
|
||||
helpers.run_setup_cmd(
|
||||
repo_cmd_runner,
|
||||
('pip', 'install', '.') + additional_dependencies,
|
||||
('pip', 'install') + to_install,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
): # pragma: windows no cover
|
||||
additional_dependencies = tuple(additional_dependencies)
|
||||
directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
|
||||
|
|
@ -115,15 +116,18 @@ def install_environment(
|
|||
_install_ruby(repo_cmd_runner, version)
|
||||
# Need to call this after installing to set up the shims
|
||||
helpers.run_setup_cmd(repo_cmd_runner, ('rbenv', 'rehash'))
|
||||
helpers.run_setup_cmd(
|
||||
repo_cmd_runner,
|
||||
('gem', 'build') + repo_cmd_runner.star('.gemspec'),
|
||||
)
|
||||
if not is_local_hook:
|
||||
helpers.run_setup_cmd(
|
||||
repo_cmd_runner,
|
||||
('gem', 'build') + repo_cmd_runner.star('.gemspec'),
|
||||
)
|
||||
to_install = () if is_local_hook else repo_cmd_runner.star('.gem')
|
||||
to_install += additional_dependencies
|
||||
helpers.run_setup_cmd(
|
||||
repo_cmd_runner,
|
||||
(
|
||||
('gem', 'install', '--no-ri', '--no-rdoc') +
|
||||
repo_cmd_runner.star('.gem') + additional_dependencies
|
||||
to_install
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
):
|
||||
"""Installation for script type is a noop."""
|
||||
raise AssertionError('Cannot install script repo.')
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
): # pragma: windows no cover
|
||||
helpers.assert_version_default('swift', version)
|
||||
helpers.assert_no_additional_deps('swift', additional_dependencies)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ def install_environment(
|
|||
repo_cmd_runner,
|
||||
version='default',
|
||||
additional_dependencies=(),
|
||||
is_local_hook = False,
|
||||
):
|
||||
"""Installation for system type is a noop."""
|
||||
raise AssertionError('Cannot install system repo.')
|
||||
|
|
|
|||
|
|
@ -179,6 +179,7 @@ class Repository(object):
|
|||
language.install_environment(
|
||||
self.cmd_runner, language_version,
|
||||
self.additional_dependencies[language_name][language_version],
|
||||
is_local_hooks(self.repo_config),
|
||||
)
|
||||
# Write our state to indicate we're installed
|
||||
write_state(venv, language_name, language_version)
|
||||
|
|
|
|||
|
|
@ -66,14 +66,14 @@ def modify_config(path='.', commit=True):
|
|||
cmd_output('git', 'commit', '-am', 'update config', cwd=path)
|
||||
|
||||
|
||||
def config_with_local_hooks():
|
||||
def config_with_local_hooks(language='pcre'):
|
||||
return OrderedDict((
|
||||
('repo', 'local'),
|
||||
('hooks', [OrderedDict((
|
||||
('id', 'do_not_commit'),
|
||||
('name', 'Block if "DO NOT COMMIT" is found'),
|
||||
('entry', 'DO NOT COMMIT'),
|
||||
('language', 'pcre'),
|
||||
('id', language),
|
||||
('name', language),
|
||||
('entry', language),
|
||||
('language', language),
|
||||
('files', '^(.*)$'),
|
||||
))])
|
||||
))
|
||||
|
|
|
|||
|
|
@ -571,6 +571,34 @@ def test_additional_golang_dependencies_installed(
|
|||
assert 'hello' in binaries
|
||||
|
||||
|
||||
@skipif_slowtests_false
|
||||
@xfailif_windows_no_ruby
|
||||
@pytest.mark.integration
|
||||
def test_install_local_ruby_hook(
|
||||
tempdir_factory, store,
|
||||
): # pragma: no cover (non-windows)
|
||||
config = config_with_local_hooks('ruby')
|
||||
config['hooks'][0]['additional_dependencies'] = ['thread_safe']
|
||||
repo = Repository.create(config, store)
|
||||
repo.require_installed()
|
||||
with ruby.in_env(repo.cmd_runner, 'default'):
|
||||
output = cmd_output('gem', 'list', '--local')[1]
|
||||
assert 'thread_safe' in output
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_install_local_python_hook(
|
||||
tempdir_factory, store,
|
||||
): # pragma: no cover (non-windows)
|
||||
config = config_with_local_hooks('python')
|
||||
config['hooks'][0]['additional_dependencies'] = ['mccabe']
|
||||
repo = Repository.create(config, store)
|
||||
repo.require_installed()
|
||||
with python.in_env(repo.cmd_runner, 'default'):
|
||||
output = cmd_output('pip', 'freeze', '-l')[1]
|
||||
assert 'mccabe' in output
|
||||
|
||||
|
||||
def test_reinstall(tempdir_factory, store, log_info_mock):
|
||||
path = make_repo(tempdir_factory, 'python_hooks_repo')
|
||||
config = make_config_from_repo(path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue