mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +04:00
Merge pull request #1268 from pre-commit/remove_prce
Remove deprecated `pcre` language
This commit is contained in:
commit
300eb6b902
9 changed files with 18 additions and 139 deletions
|
|
@ -82,14 +82,6 @@ def _subtle_line(s, use_color):
|
||||||
def _run_single_hook(classifier, hook, skips, cols, verbose, use_color):
|
def _run_single_hook(classifier, hook, skips, cols, verbose, use_color):
|
||||||
filenames = classifier.filenames_for_hook(hook)
|
filenames = classifier.filenames_for_hook(hook)
|
||||||
|
|
||||||
if hook.language == 'pcre':
|
|
||||||
logger.warning(
|
|
||||||
'`{}` (from {}) uses the deprecated pcre language.\n'
|
|
||||||
'The pcre language is scheduled for removal in pre-commit 2.x.\n'
|
|
||||||
'The pygrep language is a more portable (and usually drop-in) '
|
|
||||||
'replacement.'.format(hook.id, hook.src),
|
|
||||||
)
|
|
||||||
|
|
||||||
if hook.id in skips or hook.alias in skips:
|
if hook.id in skips or hook.alias in skips:
|
||||||
output.write(
|
output.write(
|
||||||
get_hook_message(
|
get_hook_message(
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ from pre_commit.languages import docker_image
|
||||||
from pre_commit.languages import fail
|
from pre_commit.languages import fail
|
||||||
from pre_commit.languages import golang
|
from pre_commit.languages import golang
|
||||||
from pre_commit.languages import node
|
from pre_commit.languages import node
|
||||||
from pre_commit.languages import pcre
|
|
||||||
from pre_commit.languages import pygrep
|
from pre_commit.languages import pygrep
|
||||||
from pre_commit.languages import python
|
from pre_commit.languages import python
|
||||||
from pre_commit.languages import python_venv
|
from pre_commit.languages import python_venv
|
||||||
|
|
@ -59,7 +58,6 @@ languages = {
|
||||||
'fail': fail,
|
'fail': fail,
|
||||||
'golang': golang,
|
'golang': golang,
|
||||||
'node': node,
|
'node': node,
|
||||||
'pcre': pcre,
|
|
||||||
'pygrep': pygrep,
|
'pygrep': pygrep,
|
||||||
'python': python,
|
'python': python,
|
||||||
'python_venv': python_venv,
|
'python_venv': python_venv,
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from pre_commit.languages import helpers
|
|
||||||
from pre_commit.xargs import xargs
|
|
||||||
|
|
||||||
|
|
||||||
ENVIRONMENT_DIR = None
|
|
||||||
GREP = 'ggrep' if sys.platform == 'darwin' else 'grep'
|
|
||||||
get_default_version = helpers.basic_get_default_version
|
|
||||||
healthy = helpers.basic_healthy
|
|
||||||
install_environment = helpers.no_install
|
|
||||||
|
|
||||||
|
|
||||||
def run_hook(hook, file_args, color):
|
|
||||||
# For PCRE the entry is the regular expression to match
|
|
||||||
cmd = (GREP, '-H', '-n', '-P') + tuple(hook.args) + (hook.entry,)
|
|
||||||
|
|
||||||
# Grep usually returns 0 for matches, and nonzero for non-matches so we
|
|
||||||
# negate it here.
|
|
||||||
return xargs(cmd, file_args, negate=True, color=color)
|
|
||||||
|
|
@ -149,7 +149,7 @@ def _hook(*hook_dicts, **kwargs):
|
||||||
def _non_cloned_repository_hooks(repo_config, store, root_config):
|
def _non_cloned_repository_hooks(repo_config, store, root_config):
|
||||||
def _prefix(language_name, deps):
|
def _prefix(language_name, deps):
|
||||||
language = languages[language_name]
|
language = languages[language_name]
|
||||||
# pcre / pygrep / script / system / docker_image do not have
|
# pygrep / script / system / docker_image do not have
|
||||||
# environments so they work out of the current directory
|
# environments so they work out of the current directory
|
||||||
if language.ENVIRONMENT_DIR is None:
|
if language.ENVIRONMENT_DIR is None:
|
||||||
return Prefix(os.getcwd())
|
return Prefix(os.getcwd())
|
||||||
|
|
|
||||||
|
|
@ -107,11 +107,9 @@ def xargs(cmd, varargs, **kwargs):
|
||||||
"""A simplified implementation of xargs.
|
"""A simplified implementation of xargs.
|
||||||
|
|
||||||
color: Make a pty if on a platform that supports it
|
color: Make a pty if on a platform that supports it
|
||||||
negate: Make nonzero successful and zero a failure
|
|
||||||
target_concurrency: Target number of partitions to run concurrently
|
target_concurrency: Target number of partitions to run concurrently
|
||||||
"""
|
"""
|
||||||
color = kwargs.pop('color', False)
|
color = kwargs.pop('color', False)
|
||||||
negate = kwargs.pop('negate', False)
|
|
||||||
target_concurrency = kwargs.pop('target_concurrency', 1)
|
target_concurrency = kwargs.pop('target_concurrency', 1)
|
||||||
max_length = kwargs.pop('_max_length', _get_platform_max_length())
|
max_length = kwargs.pop('_max_length', _get_platform_max_length())
|
||||||
cmd_fn = cmd_output_p if color else cmd_output_b
|
cmd_fn = cmd_output_p if color else cmd_output_b
|
||||||
|
|
@ -135,8 +133,6 @@ def xargs(cmd, varargs, **kwargs):
|
||||||
results = thread_map(run_cmd_partition, partitions)
|
results = thread_map(run_cmd_partition, partitions)
|
||||||
|
|
||||||
for proc_retcode, proc_out, _ in results:
|
for proc_retcode, proc_out, _ in results:
|
||||||
if negate:
|
|
||||||
proc_retcode = not proc_retcode
|
|
||||||
retcode = max(retcode, proc_retcode)
|
retcode = max(retcode, proc_retcode)
|
||||||
stdout += proc_out
|
stdout += proc_out
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import pytest
|
||||||
|
|
||||||
from pre_commit import parse_shebang
|
from pre_commit import parse_shebang
|
||||||
from pre_commit.languages.docker import docker_is_running
|
from pre_commit.languages.docker import docker_is_running
|
||||||
from pre_commit.languages.pcre import GREP
|
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
from testing.auto_namedtuple import auto_namedtuple
|
from testing.auto_namedtuple import auto_namedtuple
|
||||||
|
|
||||||
|
|
@ -68,16 +67,6 @@ xfailif_broken_deep_listdir = pytest.mark.xfail(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def platform_supports_pcre():
|
|
||||||
output = cmd_output(GREP, '-P', "Don't", 'CHANGELOG.md', retcode=None)
|
|
||||||
return output[0] == 0 and "Don't use readlink -f" in output[1]
|
|
||||||
|
|
||||||
|
|
||||||
xfailif_no_pcre_support = pytest.mark.xfail(
|
|
||||||
not platform_supports_pcre(),
|
|
||||||
reason='grep -P is not supported on this platform',
|
|
||||||
)
|
|
||||||
|
|
||||||
xfailif_no_symlink = pytest.mark.xfail(
|
xfailif_no_symlink = pytest.mark.xfail(
|
||||||
not hasattr(os, 'symlink'),
|
not hasattr(os, 'symlink'),
|
||||||
reason='Symlink is not supported on this platform',
|
reason='Symlink is not supported on this platform',
|
||||||
|
|
|
||||||
|
|
@ -734,32 +734,6 @@ def test_local_hook_fails(cap_out, store, repo_with_passing_hook):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_pcre_deprecation_warning(cap_out, store, repo_with_passing_hook):
|
|
||||||
config = {
|
|
||||||
'repo': 'local',
|
|
||||||
'hooks': [{
|
|
||||||
'id': 'pcre-hook',
|
|
||||||
'name': 'pcre-hook',
|
|
||||||
'language': 'pcre',
|
|
||||||
'entry': '.',
|
|
||||||
}],
|
|
||||||
}
|
|
||||||
add_config_to_repo(repo_with_passing_hook, config)
|
|
||||||
|
|
||||||
_test_run(
|
|
||||||
cap_out,
|
|
||||||
store,
|
|
||||||
repo_with_passing_hook,
|
|
||||||
opts={},
|
|
||||||
expected_outputs=[
|
|
||||||
b'[WARNING] `pcre-hook` (from local) uses the deprecated '
|
|
||||||
b'pcre language.',
|
|
||||||
],
|
|
||||||
expected_ret=0,
|
|
||||||
stage=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_meta_hook_passes(cap_out, store, repo_with_passing_hook):
|
def test_meta_hook_passes(cap_out, store, repo_with_passing_hook):
|
||||||
add_config_to_repo(repo_with_passing_hook, sample_meta_config())
|
add_config_to_repo(repo_with_passing_hook, sample_meta_config())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,12 @@ import pytest
|
||||||
|
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit import five
|
from pre_commit import five
|
||||||
from pre_commit import parse_shebang
|
|
||||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||||
from pre_commit.clientlib import load_manifest
|
from pre_commit.clientlib import load_manifest
|
||||||
from pre_commit.envcontext import envcontext
|
from pre_commit.envcontext import envcontext
|
||||||
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 node
|
||||||
from pre_commit.languages import pcre
|
|
||||||
from pre_commit.languages import python
|
from pre_commit.languages import python
|
||||||
from pre_commit.languages import ruby
|
from pre_commit.languages import ruby
|
||||||
from pre_commit.languages import rust
|
from pre_commit.languages import rust
|
||||||
|
|
@ -37,7 +35,6 @@ 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 skipif_cant_run_swift
|
from testing.util import skipif_cant_run_swift
|
||||||
from testing.util import xfailif_broken_deep_listdir
|
from testing.util import xfailif_broken_deep_listdir
|
||||||
from testing.util import xfailif_no_pcre_support
|
|
||||||
from testing.util import xfailif_no_venv
|
from testing.util import xfailif_no_venv
|
||||||
from testing.util import xfailif_windows_no_ruby
|
from testing.util import xfailif_windows_no_ruby
|
||||||
|
|
||||||
|
|
@ -426,13 +423,13 @@ def test_output_isatty(tempdir_factory, store):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _make_grep_repo(language, entry, store, args=()):
|
def _make_grep_repo(entry, store, args=()):
|
||||||
config = {
|
config = {
|
||||||
'repo': 'local',
|
'repo': 'local',
|
||||||
'hooks': [{
|
'hooks': [{
|
||||||
'id': 'grep-hook',
|
'id': 'grep-hook',
|
||||||
'name': 'grep-hook',
|
'name': 'grep-hook',
|
||||||
'language': language,
|
'language': 'pygrep',
|
||||||
'entry': entry,
|
'entry': entry,
|
||||||
'args': args,
|
'args': args,
|
||||||
'types': ['text'],
|
'types': ['text'],
|
||||||
|
|
@ -451,55 +448,27 @@ def greppable_files(tmpdir):
|
||||||
yield tmpdir
|
yield tmpdir
|
||||||
|
|
||||||
|
|
||||||
class TestPygrep(object):
|
def test_grep_hook_matching(greppable_files, store):
|
||||||
language = 'pygrep'
|
hook = _make_grep_repo('ello', store)
|
||||||
|
|
||||||
def test_grep_hook_matching(self, greppable_files, store):
|
|
||||||
hook = _make_grep_repo(self.language, 'ello', store)
|
|
||||||
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
|
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert _norm_out(out) == b"f1:1:hello'hi\n"
|
assert _norm_out(out) == b"f1:1:hello'hi\n"
|
||||||
|
|
||||||
def test_grep_hook_case_insensitive(self, greppable_files, store):
|
|
||||||
hook = _make_grep_repo(self.language, 'ELLO', store, args=['-i'])
|
def test_grep_hook_case_insensitive(greppable_files, store):
|
||||||
|
hook = _make_grep_repo('ELLO', store, args=['-i'])
|
||||||
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
|
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
assert _norm_out(out) == b"f1:1:hello'hi\n"
|
assert _norm_out(out) == b"f1:1:hello'hi\n"
|
||||||
|
|
||||||
@pytest.mark.parametrize('regex', ('nope', "foo'bar", r'^\[INFO\]'))
|
|
||||||
def test_grep_hook_not_matching(self, regex, greppable_files, store):
|
@pytest.mark.parametrize('regex', ('nope', "foo'bar", r'^\[INFO\]'))
|
||||||
hook = _make_grep_repo(self.language, regex, store)
|
def test_grep_hook_not_matching(regex, greppable_files, store):
|
||||||
|
hook = _make_grep_repo(regex, store)
|
||||||
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
|
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
|
||||||
assert (ret, out) == (0, b'')
|
assert (ret, out) == (0, b'')
|
||||||
|
|
||||||
|
|
||||||
@xfailif_no_pcre_support # pragma: windows no cover
|
|
||||||
class TestPCRE(TestPygrep):
|
|
||||||
"""organized as a class for xfailing pcre"""
|
|
||||||
language = 'pcre'
|
|
||||||
|
|
||||||
def test_pcre_hook_many_files(self, greppable_files, store):
|
|
||||||
# This is intended to simulate lots of passing files and one failing
|
|
||||||
# file to make sure it still fails. This is not the case when naively
|
|
||||||
# using a system hook with `grep -H -n '...'`
|
|
||||||
hook = _make_grep_repo('pcre', 'ello', store)
|
|
||||||
ret, out = hook.run((os.devnull,) * 15000 + ('f1',), color=False)
|
|
||||||
assert ret == 1
|
|
||||||
assert _norm_out(out) == b"f1:1:hello'hi\n"
|
|
||||||
|
|
||||||
def test_missing_pcre_support(self, greppable_files, store):
|
|
||||||
def no_grep(exe, **kwargs):
|
|
||||||
assert exe == pcre.GREP
|
|
||||||
return None
|
|
||||||
|
|
||||||
with mock.patch.object(parse_shebang, 'find_executable', no_grep):
|
|
||||||
hook = _make_grep_repo('pcre', 'ello', store)
|
|
||||||
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
|
|
||||||
assert ret == 1
|
|
||||||
expected = 'Executable `{}` not found'.format(pcre.GREP).encode()
|
|
||||||
assert out == expected
|
|
||||||
|
|
||||||
|
|
||||||
def _norm_pwd(path):
|
def _norm_pwd(path):
|
||||||
# Under windows bash's temp and windows temp is different.
|
# Under windows bash's temp and windows temp is different.
|
||||||
# This normalizes to the bash /tmp
|
# This normalizes to the bash /tmp
|
||||||
|
|
|
||||||
|
|
@ -154,23 +154,6 @@ exit_cmd = parse_shebang.normalize_cmd(('bash', '-c', 'exit $1', '--'))
|
||||||
max_length = len(' '.join(exit_cmd)) + 3
|
max_length = len(' '.join(exit_cmd)) + 3
|
||||||
|
|
||||||
|
|
||||||
def test_xargs_negate():
|
|
||||||
ret, _ = xargs.xargs(
|
|
||||||
exit_cmd, ('1',), negate=True, _max_length=max_length,
|
|
||||||
)
|
|
||||||
assert ret == 0
|
|
||||||
|
|
||||||
ret, _ = xargs.xargs(
|
|
||||||
exit_cmd, ('1', '0'), negate=True, _max_length=max_length,
|
|
||||||
)
|
|
||||||
assert ret == 1
|
|
||||||
|
|
||||||
|
|
||||||
def test_xargs_negate_command_not_found():
|
|
||||||
ret, _ = xargs.xargs(('cmd-not-found',), ('1',), negate=True)
|
|
||||||
assert ret != 0
|
|
||||||
|
|
||||||
|
|
||||||
def test_xargs_retcode_normal():
|
def test_xargs_retcode_normal():
|
||||||
ret, _ = xargs.xargs(exit_cmd, ('0',), _max_length=max_length)
|
ret, _ = xargs.xargs(exit_cmd, ('0',), _max_length=max_length)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue