Skip to content

Commit f5af0a9

Browse files
authored
Merge pull request #2324 from pre-commit/local-hooks-py27
fix python 2.7 `repo: local` hooks
2 parents c5a39ae + 1722448 commit f5af0a9

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
rev: v3.0.1
1818
hooks:
1919
- id: reorder-python-imports
20-
exclude: ^testing/resources/python3_hooks_repo/
20+
exclude: ^(pre_commit/resources/|testing/resources/python3_hooks_repo/)
2121
args: [--py37-plus, --add-import, 'from __future__ import annotations']
2222
- repo: https://github.com/asottile/add-trailing-comma
2323
rev: v2.2.1

pre_commit/resources/empty_template_setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from setuptools import setup
42

53

testing/resources/python3_hooks_repo/.pre-commit-hooks.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
name: Python 3 Hook
33
entry: python3-hook
44
language: python
5-
language_version: python3
65
files: \.py$

tests/repository_test.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os.path
44
import shutil
5-
import sys
65
from typing import Any
76
from unittest import mock
87

@@ -876,25 +875,31 @@ def test_tags_on_repositories(in_tmpdir, tempdir_factory, store):
876875
@pytest.fixture
877876
def local_python_config():
878877
# Make a "local" hooks repo that just installs our other hooks repo
879-
repo_path = get_resource_path('python_hooks_repo')
878+
repo_path = get_resource_path('python3_hooks_repo')
880879
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
881880
hooks = [
882881
dict(hook, additional_dependencies=[repo_path]) for hook in manifest
883882
]
884883
return {'repo': 'local', 'hooks': hooks}
885884

886885

887-
@pytest.mark.xfail( # pragma: win32 no cover
888-
sys.platform == 'win32',
889-
reason='microsoft/azure-pipelines-image-generation#989',
890-
)
891886
def test_local_python_repo(store, local_python_config):
892-
hook = _get_hook(local_python_config, store, 'foo')
887+
hook = _get_hook(local_python_config, store, 'python3-hook')
888+
# language_version should have been adjusted to the interpreter version
889+
assert hook.language_version != C.DEFAULT
890+
ret, out = _hook_run(hook, ('filename',), color=False)
891+
assert ret == 0
892+
assert _norm_out(out) == b"3\n['filename']\nHello World\n"
893+
894+
895+
def test_local_python_repo_python2(store, local_python_config):
896+
local_python_config['hooks'][0]['language_version'] = 'python2'
897+
hook = _get_hook(local_python_config, store, 'python3-hook')
893898
# language_version should have been adjusted to the interpreter version
894899
assert hook.language_version != C.DEFAULT
895900
ret, out = _hook_run(hook, ('filename',), color=False)
896901
assert ret == 0
897-
assert _norm_out(out) == b"['filename']\nHello World\n"
902+
assert _norm_out(out) == b"2\n['filename']\nHello World\n"
898903

899904

900905
def test_default_language_version(store, local_python_config):

0 commit comments

Comments
 (0)