mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 09:04:41 +04:00
Use cpanminus if available for perl pre-commit dependencies
cpanminus is broadly compatible with our syntax use of cpan, but can offer additional benefits such as Pkg::Name@Version definitions, as well as built-in modules to reduce the environment requirements on the system when resolving dependencies. Tests have been updated to ensure functionality works with either utility.
This commit is contained in:
parent
8189370615
commit
51248d1727
2 changed files with 19 additions and 4 deletions
|
|
@ -45,6 +45,13 @@ def install_environment(
|
||||||
lang_base.assert_version_default('perl', version)
|
lang_base.assert_version_default('perl', version)
|
||||||
|
|
||||||
with in_env(prefix, version):
|
with in_env(prefix, version):
|
||||||
lang_base.setup_cmd(
|
if lang_base.exe_exists('cpanm'):
|
||||||
prefix, ('cpan', '-T', '.', *additional_dependencies),
|
lang_base.setup_cmd(
|
||||||
)
|
prefix,
|
||||||
|
('cpanm', '.', *additional_dependencies),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
lang_base.setup_cmd(
|
||||||
|
prefix,
|
||||||
|
('cpan', '-T', '.', *additional_dependencies),
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from pre_commit.languages import perl
|
from pre_commit.languages import perl
|
||||||
from pre_commit.store import _make_local_repo
|
from pre_commit.store import _make_local_repo
|
||||||
from pre_commit.util import make_executable
|
from pre_commit.util import make_executable
|
||||||
|
|
@ -56,7 +60,10 @@ sub hello {
|
||||||
assert ret == (0, b'Hello from perl-commit Perl!\n')
|
assert ret == (0, b'Hello from perl-commit Perl!\n')
|
||||||
|
|
||||||
|
|
||||||
def test_perl_additional_dependencies(tmp_path):
|
@pytest.mark.parametrize('cpanm', [True, False])
|
||||||
|
@patch('pre_commit.lang_base.exe_exists')
|
||||||
|
def test_perl_additional_dependencies(mock_exe_exists, cpanm, tmp_path):
|
||||||
|
mock_exe_exists.return_value = cpanm
|
||||||
_make_local_repo(str(tmp_path))
|
_make_local_repo(str(tmp_path))
|
||||||
|
|
||||||
ret, out = run_language(
|
ret, out = run_language(
|
||||||
|
|
@ -65,5 +72,6 @@ def test_perl_additional_dependencies(tmp_path):
|
||||||
'perltidy --version',
|
'perltidy --version',
|
||||||
deps=('SHANCOCK/Perl-Tidy-20211029.tar.gz',),
|
deps=('SHANCOCK/Perl-Tidy-20211029.tar.gz',),
|
||||||
)
|
)
|
||||||
|
mock_exe_exists.assert_called_once_with('cpanm')
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert out.startswith(b'This is perltidy, v20211029')
|
assert out.startswith(b'This is perltidy, v20211029')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue