Skip to content

Commit d5dcebf

Browse files
committed
Deprecate the pcre language
1 parent 65f60e2 commit d5dcebf

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

pre_commit/commands/run.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ def _run_single_hook(filenames, hook, repo, args, skips, cols):
6767
filenames = _filter_by_include_exclude(filenames, include, exclude)
6868
types, exclude_types = hook['types'], hook['exclude_types']
6969
filenames = _filter_by_types(filenames, types, exclude_types)
70+
71+
if hook['language'] == 'pcre':
72+
logger.warning(
73+
'`{}` (from {}) uses the deprecated pcre language.\n'
74+
'The pcre language is scheduled for removal in pre-commit 2.x.\n'
75+
'The pygrep language is a more portable (and usually drop-in) '
76+
'replacement.'.format(hook['id'], repo.repo_config['repo']),
77+
)
78+
7079
if hook['id'] in skips:
7180
output.write(get_hook_message(
7281
_hook_msg_start(hook, args.verbose),

tests/commands/run_test.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def test_push_hook(cap_out, repo_with_passing_hook, mock_out_store_directory):
529529
('id', 'do_not_commit'),
530530
('name', 'hook 2'),
531531
('entry', 'DO NOT COMMIT'),
532-
('language', 'pcre'),
532+
('language', 'pygrep'),
533533
('types', ['text']),
534534
('stages', ['push']),
535535
)),
@@ -592,7 +592,7 @@ def test_local_hook_passes(
592592
('id', 'do_not_commit'),
593593
('name', 'Block if "DO NOT COMMIT" is found'),
594594
('entry', 'DO NOT COMMIT'),
595-
('language', 'pcre'),
595+
('language', 'pygrep'),
596596
('files', '^(.*)$'),
597597
)),
598598
),
@@ -645,6 +645,35 @@ def test_local_hook_fails(
645645
)
646646

647647

648+
def test_pcre_deprecation_warning(
649+
cap_out, repo_with_passing_hook, mock_out_store_directory,
650+
):
651+
config = OrderedDict((
652+
('repo', 'local'),
653+
(
654+
'hooks', [OrderedDict((
655+
('id', 'pcre-hook'),
656+
('name', 'pcre-hook'),
657+
('language', 'pcre'),
658+
('entry', '.'),
659+
))],
660+
),
661+
))
662+
add_config_to_repo(repo_with_passing_hook, config)
663+
664+
_test_run(
665+
cap_out,
666+
repo_with_passing_hook,
667+
opts={},
668+
expected_outputs=[
669+
b'[WARNING] `pcre-hook` (from local) uses the deprecated '
670+
b'pcre language.',
671+
],
672+
expected_ret=0,
673+
stage=False,
674+
)
675+
676+
648677
def test_meta_hook_passes(
649678
cap_out, repo_with_passing_hook, mock_out_store_directory,
650679
):

0 commit comments

Comments
 (0)