Skip to content

Commit 97e3371

Browse files
committed
Remove deprecated pcre language
1 parent 3fadbef commit 97e3371

File tree

9 files changed

+22
-143
lines changed

9 files changed

+22
-143
lines changed

pre_commit/commands/run.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ def _subtle_line(s, use_color):
8282
def _run_single_hook(classifier, hook, skips, cols, verbose, use_color):
8383
filenames = classifier.filenames_for_hook(hook)
8484

85-
if hook.language == 'pcre':
86-
logger.warning(
87-
'`{}` (from {}) uses the deprecated pcre language.\n'
88-
'The pcre language is scheduled for removal in pre-commit 2.x.\n'
89-
'The pygrep language is a more portable (and usually drop-in) '
90-
'replacement.'.format(hook.id, hook.src),
91-
)
92-
9385
if hook.id in skips or hook.alias in skips:
9486
output.write(
9587
get_hook_message(

pre_commit/languages/all.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pre_commit.languages import fail
77
from pre_commit.languages import golang
88
from pre_commit.languages import node
9-
from pre_commit.languages import pcre
109
from pre_commit.languages import pygrep
1110
from pre_commit.languages import python
1211
from pre_commit.languages import python_venv
@@ -59,7 +58,6 @@
5958
'fail': fail,
6059
'golang': golang,
6160
'node': node,
62-
'pcre': pcre,
6361
'pygrep': pygrep,
6462
'python': python,
6563
'python_venv': python_venv,

pre_commit/languages/pcre.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

pre_commit/repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _hook(*hook_dicts, **kwargs):
149149
def _non_cloned_repository_hooks(repo_config, store, root_config):
150150
def _prefix(language_name, deps):
151151
language = languages[language_name]
152-
# pcre / pygrep / script / system / docker_image do not have
152+
# pygrep / script / system / docker_image do not have
153153
# environments so they work out of the current directory
154154
if language.ENVIRONMENT_DIR is None:
155155
return Prefix(os.getcwd())

pre_commit/xargs.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ def xargs(cmd, varargs, **kwargs):
107107
"""A simplified implementation of xargs.
108108
109109
color: Make a pty if on a platform that supports it
110-
negate: Make nonzero successful and zero a failure
111110
target_concurrency: Target number of partitions to run concurrently
112111
"""
113112
color = kwargs.pop('color', False)
114-
negate = kwargs.pop('negate', False)
115113
target_concurrency = kwargs.pop('target_concurrency', 1)
116114
max_length = kwargs.pop('_max_length', _get_platform_max_length())
117115
cmd_fn = cmd_output_p if color else cmd_output_b
@@ -135,8 +133,6 @@ def run_cmd_partition(run_cmd):
135133
results = thread_map(run_cmd_partition, partitions)
136134

137135
for proc_retcode, proc_out, _ in results:
138-
if negate:
139-
proc_retcode = not proc_retcode
140136
retcode = max(retcode, proc_retcode)
141137
stdout += proc_out
142138

testing/util.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from pre_commit import parse_shebang
1111
from pre_commit.languages.docker import docker_is_running
12-
from pre_commit.languages.pcre import GREP
1312
from pre_commit.util import cmd_output
1413
from testing.auto_namedtuple import auto_namedtuple
1514

@@ -68,16 +67,6 @@ def broken_deep_listdir(): # pragma: no cover (platform specific)
6867
)
6968

7069

71-
def platform_supports_pcre():
72-
output = cmd_output(GREP, '-P', "Don't", 'CHANGELOG.md', retcode=None)
73-
return output[0] == 0 and "Don't use readlink -f" in output[1]
74-
75-
76-
xfailif_no_pcre_support = pytest.mark.xfail(
77-
not platform_supports_pcre(),
78-
reason='grep -P is not supported on this platform',
79-
)
80-
8170
xfailif_no_symlink = pytest.mark.xfail(
8271
not hasattr(os, 'symlink'),
8372
reason='Symlink is not supported on this platform',

tests/commands/run_test.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -734,32 +734,6 @@ def test_local_hook_fails(cap_out, store, repo_with_passing_hook):
734734
)
735735

736736

737-
def test_pcre_deprecation_warning(cap_out, store, repo_with_passing_hook):
738-
config = {
739-
'repo': 'local',
740-
'hooks': [{
741-
'id': 'pcre-hook',
742-
'name': 'pcre-hook',
743-
'language': 'pcre',
744-
'entry': '.',
745-
}],
746-
}
747-
add_config_to_repo(repo_with_passing_hook, config)
748-
749-
_test_run(
750-
cap_out,
751-
store,
752-
repo_with_passing_hook,
753-
opts={},
754-
expected_outputs=[
755-
b'[WARNING] `pcre-hook` (from local) uses the deprecated '
756-
b'pcre language.',
757-
],
758-
expected_ret=0,
759-
stage=False,
760-
)
761-
762-
763737
def test_meta_hook_passes(cap_out, store, repo_with_passing_hook):
764738
add_config_to_repo(repo_with_passing_hook, sample_meta_config())
765739

tests/repository_test.py

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212

1313
import pre_commit.constants as C
1414
from pre_commit import five
15-
from pre_commit import parse_shebang
1615
from pre_commit.clientlib import CONFIG_SCHEMA
1716
from pre_commit.clientlib import load_manifest
1817
from pre_commit.envcontext import envcontext
1918
from pre_commit.languages import golang
2019
from pre_commit.languages import helpers
2120
from pre_commit.languages import node
22-
from pre_commit.languages import pcre
2321
from pre_commit.languages import python
2422
from pre_commit.languages import ruby
2523
from pre_commit.languages import rust
@@ -37,7 +35,6 @@
3735
from testing.util import skipif_cant_run_docker
3836
from testing.util import skipif_cant_run_swift
3937
from testing.util import xfailif_broken_deep_listdir
40-
from testing.util import xfailif_no_pcre_support
4138
from testing.util import xfailif_no_venv
4239
from testing.util import xfailif_windows_no_ruby
4340

@@ -426,13 +423,13 @@ def test_output_isatty(tempdir_factory, store):
426423
)
427424

428425

429-
def _make_grep_repo(language, entry, store, args=()):
426+
def _make_grep_repo(entry, store, args=()):
430427
config = {
431428
'repo': 'local',
432429
'hooks': [{
433430
'id': 'grep-hook',
434431
'name': 'grep-hook',
435-
'language': language,
432+
'language': 'pygrep',
436433
'entry': entry,
437434
'args': args,
438435
'types': ['text'],
@@ -451,53 +448,25 @@ def greppable_files(tmpdir):
451448
yield tmpdir
452449

453450

454-
class TestPygrep(object):
455-
language = 'pygrep'
456-
457-
def test_grep_hook_matching(self, greppable_files, store):
458-
hook = _make_grep_repo(self.language, 'ello', store)
459-
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
460-
assert ret == 1
461-
assert _norm_out(out) == b"f1:1:hello'hi\n"
462-
463-
def test_grep_hook_case_insensitive(self, greppable_files, store):
464-
hook = _make_grep_repo(self.language, 'ELLO', store, args=['-i'])
465-
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
466-
assert ret == 1
467-
assert _norm_out(out) == b"f1:1:hello'hi\n"
468-
469-
@pytest.mark.parametrize('regex', ('nope', "foo'bar", r'^\[INFO\]'))
470-
def test_grep_hook_not_matching(self, regex, greppable_files, store):
471-
hook = _make_grep_repo(self.language, regex, store)
472-
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
473-
assert (ret, out) == (0, b'')
474-
475-
476-
@xfailif_no_pcre_support # pragma: windows no cover
477-
class TestPCRE(TestPygrep):
478-
"""organized as a class for xfailing pcre"""
479-
language = 'pcre'
480-
481-
def test_pcre_hook_many_files(self, greppable_files, store):
482-
# This is intended to simulate lots of passing files and one failing
483-
# file to make sure it still fails. This is not the case when naively
484-
# using a system hook with `grep -H -n '...'`
485-
hook = _make_grep_repo('pcre', 'ello', store)
486-
ret, out = hook.run((os.devnull,) * 15000 + ('f1',), color=False)
487-
assert ret == 1
488-
assert _norm_out(out) == b"f1:1:hello'hi\n"
489-
490-
def test_missing_pcre_support(self, greppable_files, store):
491-
def no_grep(exe, **kwargs):
492-
assert exe == pcre.GREP
493-
return None
494-
495-
with mock.patch.object(parse_shebang, 'find_executable', no_grep):
496-
hook = _make_grep_repo('pcre', 'ello', store)
497-
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
498-
assert ret == 1
499-
expected = 'Executable `{}` not found'.format(pcre.GREP).encode()
500-
assert out == expected
451+
def test_grep_hook_matching(greppable_files, store):
452+
hook = _make_grep_repo('ello', store)
453+
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
454+
assert ret == 1
455+
assert _norm_out(out) == b"f1:1:hello'hi\n"
456+
457+
458+
def test_grep_hook_case_insensitive(greppable_files, store):
459+
hook = _make_grep_repo('ELLO', store, args=['-i'])
460+
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
461+
assert ret == 1
462+
assert _norm_out(out) == b"f1:1:hello'hi\n"
463+
464+
465+
@pytest.mark.parametrize('regex', ('nope', "foo'bar", r'^\[INFO\]'))
466+
def test_grep_hook_not_matching(regex, greppable_files, store):
467+
hook = _make_grep_repo(regex, store)
468+
ret, out = hook.run(('f1', 'f2', 'f3'), color=False)
469+
assert (ret, out) == (0, b'')
501470

502471

503472
def _norm_pwd(path):

tests/xargs_test.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,6 @@ def test_xargs_smoke():
154154
max_length = len(' '.join(exit_cmd)) + 3
155155

156156

157-
def test_xargs_negate():
158-
ret, _ = xargs.xargs(
159-
exit_cmd, ('1',), negate=True, _max_length=max_length,
160-
)
161-
assert ret == 0
162-
163-
ret, _ = xargs.xargs(
164-
exit_cmd, ('1', '0'), negate=True, _max_length=max_length,
165-
)
166-
assert ret == 1
167-
168-
169-
def test_xargs_negate_command_not_found():
170-
ret, _ = xargs.xargs(('cmd-not-found',), ('1',), negate=True)
171-
assert ret != 0
172-
173-
174157
def test_xargs_retcode_normal():
175158
ret, _ = xargs.xargs(exit_cmd, ('0',), _max_length=max_length)
176159
assert ret == 0

0 commit comments

Comments
 (0)