mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2324 from pre-commit/local-hooks-py27
fix python 2.7 `repo: local` hooks
This commit is contained in:
commit
f5af0a9ff4
4 changed files with 14 additions and 12 deletions
|
|
@ -17,7 +17,7 @@ repos:
|
||||||
rev: v3.0.1
|
rev: v3.0.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: reorder-python-imports
|
- id: reorder-python-imports
|
||||||
exclude: ^testing/resources/python3_hooks_repo/
|
exclude: ^(pre_commit/resources/|testing/resources/python3_hooks_repo/)
|
||||||
args: [--py37-plus, --add-import, 'from __future__ import annotations']
|
args: [--py37-plus, --add-import, 'from __future__ import annotations']
|
||||||
- repo: https://github.com/asottile/add-trailing-comma
|
- repo: https://github.com/asottile/add-trailing-comma
|
||||||
rev: v2.2.1
|
rev: v2.2.1
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,4 @@
|
||||||
name: Python 3 Hook
|
name: Python 3 Hook
|
||||||
entry: python3-hook
|
entry: python3-hook
|
||||||
language: python
|
language: python
|
||||||
language_version: python3
|
|
||||||
files: \.py$
|
files: \.py$
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
|
@ -876,7 +875,7 @@ def test_tags_on_repositories(in_tmpdir, tempdir_factory, store):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def local_python_config():
|
def local_python_config():
|
||||||
# Make a "local" hooks repo that just installs our other hooks repo
|
# Make a "local" hooks repo that just installs our other hooks repo
|
||||||
repo_path = get_resource_path('python_hooks_repo')
|
repo_path = get_resource_path('python3_hooks_repo')
|
||||||
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
|
||||||
hooks = [
|
hooks = [
|
||||||
dict(hook, additional_dependencies=[repo_path]) for hook in manifest
|
dict(hook, additional_dependencies=[repo_path]) for hook in manifest
|
||||||
|
|
@ -884,17 +883,23 @@ def local_python_config():
|
||||||
return {'repo': 'local', 'hooks': hooks}
|
return {'repo': 'local', 'hooks': hooks}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail( # pragma: win32 no cover
|
|
||||||
sys.platform == 'win32',
|
|
||||||
reason='microsoft/azure-pipelines-image-generation#989',
|
|
||||||
)
|
|
||||||
def test_local_python_repo(store, local_python_config):
|
def test_local_python_repo(store, local_python_config):
|
||||||
hook = _get_hook(local_python_config, store, 'foo')
|
hook = _get_hook(local_python_config, store, 'python3-hook')
|
||||||
# language_version should have been adjusted to the interpreter version
|
# language_version should have been adjusted to the interpreter version
|
||||||
assert hook.language_version != C.DEFAULT
|
assert hook.language_version != C.DEFAULT
|
||||||
ret, out = _hook_run(hook, ('filename',), color=False)
|
ret, out = _hook_run(hook, ('filename',), color=False)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert _norm_out(out) == b"['filename']\nHello World\n"
|
assert _norm_out(out) == b"3\n['filename']\nHello World\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_local_python_repo_python2(store, local_python_config):
|
||||||
|
local_python_config['hooks'][0]['language_version'] = 'python2'
|
||||||
|
hook = _get_hook(local_python_config, store, 'python3-hook')
|
||||||
|
# language_version should have been adjusted to the interpreter version
|
||||||
|
assert hook.language_version != C.DEFAULT
|
||||||
|
ret, out = _hook_run(hook, ('filename',), color=False)
|
||||||
|
assert ret == 0
|
||||||
|
assert _norm_out(out) == b"2\n['filename']\nHello World\n"
|
||||||
|
|
||||||
|
|
||||||
def test_default_language_version(store, local_python_config):
|
def test_default_language_version(store, local_python_config):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue