1
0
Fork 0

Adding upstream version 3.0.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 21:36:33 +01:00
parent ca00e08dce
commit 2ba952a000
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
31 changed files with 215 additions and 350 deletions

View file

@ -36,5 +36,5 @@ runs:
testing/get-coursier.sh testing/get-coursier.sh
testing/get-dart.sh testing/get-dart.sh
testing/get-swift.sh testing/get-swift.sh
- uses: asottile/workflows/.github/actions/latest-git@v1.2.0 - uses: asottile/workflows/.github/actions/latest-git@v1.4.0
if: inputs.env == 'py38' && runner.os == 'Linux' if: inputs.env == 'py38' && runner.os == 'Linux'

View file

@ -12,12 +12,12 @@ concurrency:
jobs: jobs:
main-windows: main-windows:
uses: asottile/workflows/.github/workflows/tox.yml@v1.2.0 uses: asottile/workflows/.github/workflows/tox.yml@v1.4.0
with: with:
env: '["py38"]' env: '["py38"]'
os: windows-latest os: windows-latest
main-linux: main-linux:
uses: asottile/workflows/.github/workflows/tox.yml@v1.2.0 uses: asottile/workflows/.github/workflows/tox.yml@v1.4.0
with: with:
env: '["py38", "py39", "py310"]' env: '["py38", "py39", "py310"]'
os: ubuntu-latest os: ubuntu-latest

View file

@ -1,3 +1,11 @@
3.0.3 - 2023-02-01
==================
### Fixes
- Revert "Prevent local `Gemfile` from interfering with hook execution.".
- #2739 issue by @Roguelazer.
- #2740 PR by @asottile.
3.0.2 - 2023-01-29 3.0.2 - 2023-01-29
================== ==================

View file

@ -39,7 +39,6 @@ def get_env_patch(
('GEM_HOME', os.path.join(venv, 'gems')), ('GEM_HOME', os.path.join(venv, 'gems')),
('GEM_PATH', UNSET), ('GEM_PATH', UNSET),
('BUNDLE_IGNORE_CONFIG', '1'), ('BUNDLE_IGNORE_CONFIG', '1'),
('BUNDLE_GEMFILE', os.devnull),
) )
if language_version == 'system': if language_version == 'system':
patches += ( patches += (

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = pre_commit name = pre_commit
version = 3.0.2 version = 3.0.3
description = A framework for managing and maintaining multi-language pre-commit hooks. description = A framework for managing and maintaining multi-language pre-commit hooks.
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown

View file

@ -3,7 +3,6 @@ from __future__ import annotations
import os import os
from typing import Sequence from typing import Sequence
import pre_commit.constants as C
from pre_commit.languages.all import Language from pre_commit.languages.all import Language
from pre_commit.prefix import Prefix from pre_commit.prefix import Prefix
@ -14,13 +13,16 @@ def run_language(
exe: str, exe: str,
args: Sequence[str] = (), args: Sequence[str] = (),
file_args: Sequence[str] = (), file_args: Sequence[str] = (),
version: str = C.DEFAULT, version: str | None = None,
deps: Sequence[str] = (), deps: Sequence[str] = (),
is_local: bool = False, is_local: bool = False,
) -> tuple[int, bytes]: ) -> tuple[int, bytes]:
prefix = Prefix(str(path)) prefix = Prefix(str(path))
version = version or language.get_default_version()
language.install_environment(prefix, version, deps) language.install_environment(prefix, version, deps)
health_error = language.health_check(prefix, version)
assert health_error is None, health_error
with language.in_env(prefix, version): with language.in_env(prefix, version):
ret, out = language.run_hook( ret, out = language.run_hook(
prefix, prefix,

View file

@ -1,5 +0,0 @@
- id: foo
name: Foo
entry: foo
language: node
files: \.js$

View file

@ -1,3 +0,0 @@
#!/usr/bin/env node
console.log('Hello World');

View file

@ -1,5 +0,0 @@
{
"name": "foo",
"version": "0.0.1",
"bin": {"foo": "./bin/main.js"}
}

View file

@ -1,6 +0,0 @@
- id: versioned-node-hook
name: Versioned node hook
entry: versioned-node-hook
language: node
language_version: 9.3.0
files: \.js$

View file

@ -1,4 +0,0 @@
#!/usr/bin/env node
console.log(process.version);
console.log('Hello World');

View file

@ -1,5 +0,0 @@
{
"name": "versioned-node-hook",
"version": "0.0.1",
"bin": {"versioned-node-hook": "./bin/main.js"}
}

View file

@ -1 +0,0 @@
*.gem

View file

@ -1,5 +0,0 @@
- id: ruby_hook
name: Ruby Hook
entry: ruby_hook
language: ruby
files: \.rb$

View file

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
puts 'Hello world from a ruby hook'

View file

@ -1,9 +0,0 @@
Gem::Specification.new do |s|
s.name = 'ruby_hook'
s.version = '0.1.0'
s.authors = ['Anthony Sottile']
s.summary = 'A ruby hook!'
s.description = 'A ruby hook!'
s.files = ['bin/ruby_hook']
s.executables = ['ruby_hook']
end

View file

@ -1 +0,0 @@
*.gem

View file

@ -1,6 +0,0 @@
- id: ruby_hook
name: Ruby Hook
entry: ruby_hook
language: ruby
language_version: 3.2.0
files: \.rb$

View file

@ -1,4 +0,0 @@
#!/usr/bin/env ruby
puts RUBY_VERSION
puts 'Hello world from a ruby hook'

View file

@ -1,9 +0,0 @@
Gem::Specification.new do |s|
s.name = 'ruby_hook'
s.version = '0.1.0'
s.authors = ['Anthony Sottile']
s.summary = 'A ruby hook!'
s.description = 'A ruby hook!'
s.files = ['bin/ruby_hook']
s.executables = ['ruby_hook']
end

View file

@ -1,5 +0,0 @@
- id: rust-hook
name: rust example hook
entry: rust-hello-world
language: rust
files: ''

View file

@ -1,3 +0,0 @@
[[package]]
name = "rust-hello-world"
version = "0.1.0"

View file

@ -1,3 +0,0 @@
[package]
name = "rust-hello-world"
version = "0.1.0"

View file

@ -1,3 +0,0 @@
fn main() {
println!("hello world");
}

View file

@ -1,9 +1,9 @@
from __future__ import annotations from __future__ import annotations
import re
from unittest import mock from unittest import mock
import pytest import pytest
import re_assert
import pre_commit.constants as C import pre_commit.constants as C
from pre_commit.languages import golang from pre_commit.languages import golang
@ -40,4 +40,4 @@ def test_golang_infer_go_version_default():
version = ACTUAL_INFER_GO_VERSION(C.DEFAULT) version = ACTUAL_INFER_GO_VERSION(C.DEFAULT)
assert version != C.DEFAULT assert version != C.DEFAULT
assert re.match(r'^\d+\.\d+\.\d+$', version) re_assert.Matches(r'^\d+\.\d+(?:\.\d+)?$').assert_matches(version)

View file

@ -13,7 +13,9 @@ from pre_commit import envcontext
from pre_commit import parse_shebang from pre_commit import parse_shebang
from pre_commit.languages import node from pre_commit.languages import node
from pre_commit.prefix import Prefix from pre_commit.prefix import Prefix
from pre_commit.store import _make_local_repo
from pre_commit.util import cmd_output from pre_commit.util import cmd_output
from testing.language_helpers import run_language
from testing.util import xfailif_windows from testing.util import xfailif_windows
@ -109,3 +111,42 @@ def test_installs_without_links_outside_env(tmpdir):
with node.in_env(prefix, 'system'): with node.in_env(prefix, 'system'):
assert cmd_output('foo')[1] == 'success!\n' assert cmd_output('foo')[1] == 'success!\n'
def _make_hello_world(tmp_path):
package_json = '''\
{"name": "t", "version": "0.0.1", "bin": {"node-hello": "./bin/main.js"}}
'''
tmp_path.joinpath('package.json').write_text(package_json)
bin_dir = tmp_path.joinpath('bin')
bin_dir.mkdir()
bin_dir.joinpath('main.js').write_text(
'#!/usr/bin/env node\n'
'console.log("Hello World");\n',
)
def test_node_hook_system(tmp_path):
_make_hello_world(tmp_path)
ret = run_language(tmp_path, node, 'node-hello')
assert ret == (0, b'Hello World\n')
def test_node_with_user_config_set(tmp_path):
cfg = tmp_path.joinpath('cfg')
cfg.write_text('cache=/dne\n')
with envcontext.envcontext((('NPM_CONFIG_USERCONFIG', str(cfg)),)):
test_node_hook_system(tmp_path)
@pytest.mark.parametrize('version', (C.DEFAULT, '18.13.0'))
def test_node_hook_versions(tmp_path, version):
_make_hello_world(tmp_path)
ret = run_language(tmp_path, node, 'node-hello', version=version)
assert ret == (0, b'Hello World\n')
def test_node_additional_deps(tmp_path):
_make_local_repo(str(tmp_path))
ret, out = run_language(tmp_path, node, 'npm ls -g', deps=('lodash',))
assert b' lodash@' in out

View file

@ -1,6 +1,5 @@
from __future__ import annotations from __future__ import annotations
import os.path
import tarfile import tarfile
from unittest import mock from unittest import mock
@ -8,10 +7,12 @@ import pytest
import pre_commit.constants as C import pre_commit.constants as C
from pre_commit import parse_shebang from pre_commit import parse_shebang
from pre_commit.envcontext import envcontext
from pre_commit.languages import ruby from pre_commit.languages import ruby
from pre_commit.prefix import Prefix from pre_commit.store import _make_local_repo
from pre_commit.util import cmd_output
from pre_commit.util import resource_bytesio from pre_commit.util import resource_bytesio
from testing.language_helpers import run_language
from testing.util import cwd
from testing.util import xfailif_windows from testing.util import xfailif_windows
@ -34,50 +35,6 @@ def test_uses_system_if_both_gem_and_ruby_are_available(find_exe_mck):
assert ACTUAL_GET_DEFAULT_VERSION() == 'system' assert ACTUAL_GET_DEFAULT_VERSION() == 'system'
@pytest.fixture
def fake_gem_prefix(tmpdir):
gemspec = '''\
Gem::Specification.new do |s|
s.name = 'pre_commit_placeholder_package'
s.version = '0.0.0'
s.summary = 'placeholder gem for pre-commit hooks'
s.authors = ['Anthony Sottile']
end
'''
tmpdir.join('placeholder_gem.gemspec').write(gemspec)
yield Prefix(tmpdir)
@xfailif_windows # pragma: win32 no cover
def test_install_ruby_system(fake_gem_prefix):
ruby.install_environment(fake_gem_prefix, 'system', ())
# Should be able to activate and use rbenv install
with ruby.in_env(fake_gem_prefix, 'system'):
_, out, _ = cmd_output('gem', 'list')
assert 'pre_commit_placeholder_package' in out
@xfailif_windows # pragma: win32 no cover
def test_install_ruby_default(fake_gem_prefix):
ruby.install_environment(fake_gem_prefix, C.DEFAULT, ())
# Should have created rbenv directory
assert os.path.exists(fake_gem_prefix.path('rbenv-default'))
# Should be able to activate using our script and access rbenv
with ruby.in_env(fake_gem_prefix, 'default'):
cmd_output('rbenv', '--help')
@xfailif_windows # pragma: win32 no cover
def test_install_ruby_with_version(fake_gem_prefix):
ruby.install_environment(fake_gem_prefix, '3.2.0', ())
# Should be able to activate and use rbenv install
with ruby.in_env(fake_gem_prefix, '3.2.0'):
cmd_output('rbenv', 'install', '--help')
@pytest.mark.parametrize( @pytest.mark.parametrize(
'filename', 'filename',
('rbenv.tar.gz', 'ruby-build.tar.gz', 'ruby-download.tar.gz'), ('rbenv.tar.gz', 'ruby-build.tar.gz', 'ruby-download.tar.gz'),
@ -87,3 +44,96 @@ def test_archive_root_stat(filename):
with tarfile.open(fileobj=f) as tarf: with tarfile.open(fileobj=f) as tarf:
root, _, _ = filename.partition('.') root, _, _ = filename.partition('.')
assert oct(tarf.getmember(root).mode) == '0o755' assert oct(tarf.getmember(root).mode) == '0o755'
def _setup_hello_world(tmp_path):
bin_dir = tmp_path.joinpath('bin')
bin_dir.mkdir()
bin_dir.joinpath('ruby_hook').write_text(
'#!/usr/bin/env ruby\n'
"puts 'Hello world from a ruby hook'\n",
)
gemspec = '''\
Gem::Specification.new do |s|
s.name = 'ruby_hook'
s.version = '0.1.0'
s.authors = ['Anthony Sottile']
s.summary = 'A ruby hook!'
s.description = 'A ruby hook!'
s.files = ['bin/ruby_hook']
s.executables = ['ruby_hook']
end
'''
tmp_path.joinpath('ruby_hook.gemspec').write_text(gemspec)
def test_ruby_hook_system(tmp_path):
assert ruby.get_default_version() == 'system'
_setup_hello_world(tmp_path)
ret = run_language(tmp_path, ruby, 'ruby_hook')
assert ret == (0, b'Hello world from a ruby hook\n')
def test_ruby_with_user_install_set(tmp_path):
gemrc = tmp_path.joinpath('gemrc')
gemrc.write_text('gem: --user-install\n')
with envcontext((('GEMRC', str(gemrc)),)):
test_ruby_hook_system(tmp_path)
def test_ruby_additional_deps(tmp_path):
_make_local_repo(tmp_path)
ret = run_language(
tmp_path,
ruby,
'ruby -e',
args=('require "tins"',),
deps=('tins',),
)
assert ret == (0, b'')
@xfailif_windows # pragma: win32 no cover
def test_ruby_hook_default(tmp_path):
_setup_hello_world(tmp_path)
out, ret = run_language(tmp_path, ruby, 'rbenv --help', version='default')
assert out == 0
assert ret.startswith(b'Usage: rbenv ')
@xfailif_windows # pragma: win32 no cover
def test_ruby_hook_language_version(tmp_path):
_setup_hello_world(tmp_path)
tmp_path.joinpath('bin', 'ruby_hook').write_text(
'#!/usr/bin/env ruby\n'
'puts RUBY_VERSION\n'
"puts 'Hello world from a ruby hook'\n",
)
ret = run_language(tmp_path, ruby, 'ruby_hook', version='3.2.0')
assert ret == (0, b'3.2.0\nHello world from a ruby hook\n')
@xfailif_windows # pragma: win32 no cover
def test_ruby_with_bundle_disable_shared_gems(tmp_path):
workdir = tmp_path.joinpath('workdir')
workdir.mkdir()
# this needs a `source` or there's a deprecation warning
# silencing this with `BUNDLE_GEMFILE` breaks some tools (#2739)
workdir.joinpath('Gemfile').write_text('source ""\ngem "lol_hai"\n')
# this bundle config causes things to be written elsewhere
bundle = workdir.joinpath('.bundle')
bundle.mkdir()
bundle.joinpath('config').write_text(
'BUNDLE_DISABLE_SHARED_GEMS: true\n'
'BUNDLE_PATH: vendor/gem\n',
)
with cwd(workdir):
# `3.2.0` has new enough `gem` reading `.bundle`
test_ruby_hook_language_version(tmp_path)

View file

@ -1,6 +1,5 @@
from __future__ import annotations from __future__ import annotations
from typing import Mapping
from unittest import mock from unittest import mock
import pytest import pytest
@ -8,8 +7,8 @@ import pytest
import pre_commit.constants as C import pre_commit.constants as C
from pre_commit import parse_shebang from pre_commit import parse_shebang
from pre_commit.languages import rust from pre_commit.languages import rust
from pre_commit.prefix import Prefix from pre_commit.store import _make_local_repo
from pre_commit.util import cmd_output from testing.language_helpers import run_language
ACTUAL_GET_DEFAULT_VERSION = rust.get_default_version.__wrapped__ ACTUAL_GET_DEFAULT_VERSION = rust.get_default_version.__wrapped__
@ -30,64 +29,78 @@ def test_uses_default_when_rust_is_not_available(cmd_output_b_mck):
assert ACTUAL_GET_DEFAULT_VERSION() == C.DEFAULT assert ACTUAL_GET_DEFAULT_VERSION() == C.DEFAULT
@pytest.mark.parametrize('language_version', (C.DEFAULT, '1.56.0')) def _make_hello_world(tmp_path):
def test_installs_with_bootstrapped_rustup(tmpdir, language_version): src_dir = tmp_path.joinpath('src')
tmpdir.join('src', 'main.rs').ensure().write( src_dir.mkdir()
src_dir.joinpath('main.rs').write_text(
'fn main() {\n' 'fn main() {\n'
' println!("Hello, world!");\n' ' println!("Hello, world!");\n'
'}\n', '}\n',
) )
tmpdir.join('Cargo.toml').ensure().write( tmp_path.joinpath('Cargo.toml').write_text(
'[package]\n' '[package]\n'
'name = "hello_world"\n' 'name = "hello_world"\n'
'version = "0.1.0"\n' 'version = "0.1.0"\n'
'edition = "2021"\n', 'edition = "2021"\n',
) )
prefix = Prefix(str(tmpdir))
find_executable_exes = []
original_find_executable = parse_shebang.find_executable def test_installs_rust_missing_rustup(tmp_path):
_make_hello_world(tmp_path)
def mocked_find_executable( # pretend like `rustup` doesn't exist so it gets bootstrapped
exe: str, *, env: Mapping[str, str] | None = None, calls = []
) -> str | None: orig = parse_shebang.find_executable
"""
Return `None` the first time `find_executable` is called to ensure
that the bootstrapping code is executed, then just let the function
work as normal.
Also log the arguments to ensure that everything works as expected. def mck(exe, env=None):
""" calls.append(exe)
find_executable_exes.append(exe) if len(calls) == 1:
if len(find_executable_exes) == 1: assert exe == 'rustup'
return None return None
return original_find_executable(exe, env=env) return orig(exe, env=env)
with mock.patch.object(parse_shebang, 'find_executable') as find_exe_mck: with mock.patch.object(parse_shebang, 'find_executable', side_effect=mck):
find_exe_mck.side_effect = mocked_find_executable ret = run_language(tmp_path, rust, 'hello_world', version='1.56.0')
rust.install_environment(prefix, language_version, ()) assert calls == ['rustup', 'rustup', 'cargo', 'hello_world']
assert find_executable_exes == ['rustup', 'rustup', 'cargo'] assert ret == (0, b'Hello, world!\n')
with rust.in_env(prefix, language_version):
assert cmd_output('hello_world')[1] == 'Hello, world!\n'
def test_installs_with_existing_rustup(tmpdir): @pytest.mark.parametrize('version', (C.DEFAULT, '1.56.0'))
tmpdir.join('src', 'main.rs').ensure().write( def test_language_version_with_rustup(tmp_path, version):
'fn main() {\n'
' println!("Hello, world!");\n'
'}\n',
)
tmpdir.join('Cargo.toml').ensure().write(
'[package]\n'
'name = "hello_world"\n'
'version = "0.1.0"\n'
'edition = "2021"\n',
)
prefix = Prefix(str(tmpdir))
assert parse_shebang.find_executable('rustup') is not None assert parse_shebang.find_executable('rustup') is not None
rust.install_environment(prefix, '1.56.0', ())
with rust.in_env(prefix, '1.56.0'): _make_hello_world(tmp_path)
assert cmd_output('hello_world')[1] == 'Hello, world!\n'
ret = run_language(tmp_path, rust, 'hello_world', version=version)
assert ret == (0, b'Hello, world!\n')
@pytest.mark.parametrize('dep', ('cli:shellharden:4.2.0', 'cli:shellharden'))
def test_rust_cli_additional_dependencies(tmp_path, dep):
_make_local_repo(str(tmp_path))
t_sh = tmp_path.joinpath('t.sh')
t_sh.write_text('echo $hi\n')
assert rust.get_default_version() == 'system'
ret = run_language(
tmp_path,
rust,
'shellharden --transform',
deps=(dep,),
args=(str(t_sh),),
)
assert ret == (0, b'echo "$hi"\n')
def test_run_lib_additional_dependencies(tmp_path):
_make_hello_world(tmp_path)
deps = ('shellharden:4.2.0', 'git-version')
ret = run_language(tmp_path, rust, 'hello_world', deps=deps)
assert ret == (0, b'Hello, world!\n')
bin_dir = tmp_path.joinpath('rustenv-system', 'bin')
assert bin_dir.is_dir()
assert not bin_dir.joinpath('shellharden').exists()
assert not bin_dir.joinpath('shellharden.exe').exists()

View file

@ -17,10 +17,7 @@ from pre_commit.envcontext import envcontext
from pre_commit.hook import Hook from pre_commit.hook import Hook
from pre_commit.languages import golang from pre_commit.languages import golang
from pre_commit.languages import helpers from pre_commit.languages import helpers
from pre_commit.languages import node
from pre_commit.languages import python from pre_commit.languages import python
from pre_commit.languages import ruby
from pre_commit.languages import rust
from pre_commit.languages.all import languages from pre_commit.languages.all import languages
from pre_commit.prefix import Prefix from pre_commit.prefix import Prefix
from pre_commit.repository import _hook_installed from pre_commit.repository import _hook_installed
@ -34,7 +31,6 @@ from testing.fixtures import modify_manifest
from testing.util import cwd from testing.util import cwd
from testing.util import get_resource_path from testing.util import get_resource_path
from testing.util import skipif_cant_run_docker from testing.util import skipif_cant_run_docker
from testing.util import xfailif_windows
def _norm_out(b): def _norm_out(b):
@ -196,84 +192,6 @@ def test_run_a_docker_image_hook(tempdir_factory, store, hook_id):
) )
def test_run_a_node_hook(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'node_hooks_repo',
'foo', [os.devnull], b'Hello World\n',
)
def test_run_a_node_hook_default_version(tempdir_factory, store):
# make sure that this continues to work for platforms where node is not
# installed at the system
with mock.patch.object(
node,
'get_default_version',
return_value=C.DEFAULT,
):
test_run_a_node_hook(tempdir_factory, store)
def test_run_versioned_node_hook(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'node_versioned_hooks_repo',
'versioned-node-hook', [os.devnull], b'v9.3.0\nHello World\n',
)
def test_node_hook_with_npm_userconfig_set(tempdir_factory, store, tmpdir):
cfg = tmpdir.join('cfg')
cfg.write('cache=/dne\n')
with mock.patch.dict(os.environ, NPM_CONFIG_USERCONFIG=str(cfg)):
test_run_a_node_hook(tempdir_factory, store)
def test_run_a_ruby_hook(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'ruby_hooks_repo',
'ruby_hook', [os.devnull], b'Hello world from a ruby hook\n',
)
def test_run_a_ruby_hook_with_user_install_set(tempdir_factory, store, tmpdir):
gemrc = tmpdir.join('gemrc')
gemrc.write('gem: --user-install\n')
with envcontext((('GEMRC', str(gemrc)),)):
test_run_a_ruby_hook(tempdir_factory, store)
@xfailif_windows # pragma: win32 no cover
def test_run_versioned_ruby_hook(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'ruby_versioned_hooks_repo',
'ruby_hook',
[os.devnull],
b'3.2.0\nHello world from a ruby hook\n',
)
@xfailif_windows # pragma: win32 no cover
def test_run_ruby_hook_with_disable_shared_gems(
tempdir_factory,
store,
tmpdir,
):
"""Make sure a Gemfile in the project doesn't interfere."""
tmpdir.join('Gemfile').write('gem "lol_hai"')
tmpdir.join('.bundle').mkdir()
tmpdir.join('.bundle', 'config').write(
'BUNDLE_DISABLE_SHARED_GEMS: true\n'
'BUNDLE_PATH: vendor/gem\n',
)
with cwd(tmpdir.strpath):
_test_hook_repo(
tempdir_factory, store, 'ruby_versioned_hooks_repo',
'ruby_hook',
[os.devnull],
b'3.2.0\nHello world from a ruby hook\n',
)
def test_system_hook_with_spaces(tempdir_factory, store): def test_system_hook_with_spaces(tempdir_factory, store):
_test_hook_repo( _test_hook_repo(
tempdir_factory, store, 'system_hook_with_spaces_repo', tempdir_factory, store, 'system_hook_with_spaces_repo',
@ -367,54 +285,6 @@ func main() {
assert _norm_out(out) == b'hello hello world\n' assert _norm_out(out) == b'hello hello world\n'
def test_rust_hook(tempdir_factory, store):
_test_hook_repo(
tempdir_factory, store, 'rust_hooks_repo',
'rust-hook', [], b'hello world\n',
)
@pytest.mark.parametrize('dep', ('cli:shellharden:3.1.0', 'cli:shellharden'))
def test_additional_rust_cli_dependencies_installed(
tempdir_factory, store, dep,
):
path = make_repo(tempdir_factory, 'rust_hooks_repo')
config = make_config_from_repo(path)
# A small rust package with no dependencies.
config['hooks'][0]['additional_dependencies'] = [dep]
hook = _get_hook(config, store, 'rust-hook')
envdir = helpers.environment_dir(
hook.prefix,
rust.ENVIRONMENT_DIR,
'system',
)
binaries = os.listdir(os.path.join(envdir, 'bin'))
# normalize for windows
binaries = [os.path.splitext(binary)[0] for binary in binaries]
assert 'shellharden' in binaries
def test_additional_rust_lib_dependencies_installed(
tempdir_factory, store,
):
path = make_repo(tempdir_factory, 'rust_hooks_repo')
config = make_config_from_repo(path)
# A small rust package with no dependencies.
deps = ['shellharden:3.1.0', 'git-version']
config['hooks'][0]['additional_dependencies'] = deps
hook = _get_hook(config, store, 'rust-hook')
envdir = helpers.environment_dir(
hook.prefix,
rust.ENVIRONMENT_DIR,
'system',
)
binaries = os.listdir(os.path.join(envdir, 'bin'))
# normalize for windows
binaries = [os.path.splitext(binary)[0] for binary in binaries]
assert 'rust-hello-world' in binaries
assert 'shellharden' not in binaries
def test_missing_executable(tempdir_factory, store): def test_missing_executable(tempdir_factory, store):
_test_hook_repo( _test_hook_repo(
tempdir_factory, store, 'not_found_exe', tempdir_factory, store, 'not_found_exe',
@ -579,27 +449,6 @@ def test_repository_state_compatibility(tempdir_factory, store, v):
assert _hook_installed(hook) is True assert _hook_installed(hook) is True
def test_additional_ruby_dependencies_installed(tempdir_factory, store):
path = make_repo(tempdir_factory, 'ruby_hooks_repo')
config = make_config_from_repo(path)
config['hooks'][0]['additional_dependencies'] = ['tins']
hook = _get_hook(config, store, 'ruby_hook')
with ruby.in_env(hook.prefix, hook.language_version):
output = cmd_output('gem', 'list', '--local')[1]
assert 'tins' in output
def test_additional_node_dependencies_installed(tempdir_factory, store):
path = make_repo(tempdir_factory, 'node_hooks_repo')
config = make_config_from_repo(path)
# Careful to choose a small package that's not depped by npm
config['hooks'][0]['additional_dependencies'] = ['lodash']
hook = _get_hook(config, store, 'foo')
with node.in_env(hook.prefix, hook.language_version):
output = cmd_output('npm', 'ls', '-g')[1]
assert 'lodash' in output
def test_additional_golang_dependencies_installed( def test_additional_golang_dependencies_installed(
tempdir_factory, store, tempdir_factory, store,
): ):
@ -637,23 +486,6 @@ def test_local_golang_additional_dependencies(store):
assert _norm_out(out) == b'Hello, Go examples!\n' assert _norm_out(out) == b'Hello, Go examples!\n'
def test_local_rust_additional_dependencies(store):
config = {
'repo': 'local',
'hooks': [{
'id': 'hello',
'name': 'hello',
'entry': 'hello',
'language': 'rust',
'additional_dependencies': ['cli:hello-cli:0.2.2'],
}],
}
hook = _get_hook(config, store, 'hello')
ret, out = _hook_run(hook, (), color=False)
assert ret == 0
assert _norm_out(out) == b'Hello World!\n'
def test_fail_hooks(store): def test_fail_hooks(store):
config = { config = {
'repo': 'local', 'repo': 'local',