From 526904b1596ea461616a7b8b20ebd959454b57fc Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 11 Oct 2018 17:19:35 -0700 Subject: [PATCH] Remove autopep8-wrapper in favor of autopep8 --- .pre-commit-config.yaml | 5 ++++- README.md | 11 ++++++----- pre_commit_hooks/autopep8_wrapper.py | 24 ++++-------------------- setup.py | 4 +--- tests/autopep8_wrapper_test.py | 25 +++++-------------------- 5 files changed, 20 insertions(+), 49 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 72705f09..41f77d8e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,6 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer - - id: autopep8-wrapper - id: check-docstring-first - id: check-json - id: check-added-large-files @@ -13,6 +12,10 @@ repos: - id: name-tests-test - id: requirements-txt-fixer - id: flake8 +- repo: https://github.com/pre-commit/mirrors-autopep8 + rev: v1.4 + hooks: + - id: autopep8 - repo: https://github.com/pre-commit/pre-commit rev: v1.7.0 hooks: diff --git a/README.md b/README.md index f7f8d921..df42a88b 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,6 @@ Add this to your `.pre-commit-config.yaml` ### Hooks available -- `autopep8-wrapper` - Runs autopep8 over python source. - - Ignore PEP 8 violation types with `args: ['-i', '--ignore=E000,...']` or - through configuration of the `[pycodestyle]` section in - setup.cfg / tox.ini. - `check-added-large-files` - Prevent giant files from being committed. - Specify what is "too large" with `args: ['--maxkb=123']` (default=500kB). - If `git-lfs` is installed, lfs files will be skipped @@ -86,7 +82,6 @@ Add this to your `.pre-commit-config.yaml` `master` is the default if no argument is set. - `-b` / `--branch` may be specified multiple times to protect multiple branches. -- `pyflakes` - Run pyflakes on your python files. - `pretty-format-json` - Checks that all your JSON files are pretty. "Pretty" here means that keys are sorted and indented. You can configure this with the following commandline options: @@ -102,6 +97,12 @@ Add this to your `.pre-commit-config.yaml` `args: ['--markdown-linebreak-ext=*']` to preserve them for all files, or `args: ['--no-markdown-linebreak-ext']` to disable and always trim. +### Deprecated / replaced hooks + +- `autopep8-wrapper`: instead use + [mirrors-autopep8](https://github.com/pre-commit/mirrors-autopep8) +- `pyflakes`: instead use `flake8` + ### As a standalone package If you'd like to use these hooks, they're also available as a standalone diff --git a/pre_commit_hooks/autopep8_wrapper.py b/pre_commit_hooks/autopep8_wrapper.py index 087fe3fa..9951924d 100644 --- a/pre_commit_hooks/autopep8_wrapper.py +++ b/pre_commit_hooks/autopep8_wrapper.py @@ -2,28 +2,12 @@ from __future__ import print_function from __future__ import unicode_literals -import io -import sys - -import autopep8 - def main(argv=None): - argv = argv if argv is not None else sys.argv[1:] - args = autopep8.parse_args(argv, apply_config=True) - - retv = 0 - for filename in args.files: - with io.open(filename, encoding='UTF-8') as f: - original_contents = f.read() - new_contents = autopep8.fix_code(original_contents, args) - if original_contents != new_contents: - print('Fixing {}'.format(filename)) - retv = 1 - with io.open(filename, 'w', encoding='UTF-8') as output_file: - output_file.write(new_contents) - - return retv + raise SystemExit( + 'autopep8-wrapper is deprecated. Instead use autopep8 directly via ' + 'https://github.com/pre-commit/mirrors-autopep8', + ) if __name__ == '__main__': diff --git a/setup.py b/setup.py index 138b3c4e..20b9f91a 100644 --- a/setup.py +++ b/setup.py @@ -24,9 +24,7 @@ packages=find_packages(exclude=('tests*', 'testing*')), install_requires=[ - # quickfix to prevent pycodestyle conflicts - 'flake8!=2.5.3', - 'autopep8>=1.3', + 'flake8', 'pyyaml', 'six', ], diff --git a/tests/autopep8_wrapper_test.py b/tests/autopep8_wrapper_test.py index 780752cb..615ec25c 100644 --- a/tests/autopep8_wrapper_test.py +++ b/tests/autopep8_wrapper_test.py @@ -6,23 +6,8 @@ from pre_commit_hooks.autopep8_wrapper import main -@pytest.mark.parametrize( - ('input_src', 'expected_ret', 'output_src'), - ( - ('print(1 + 2)\n', 1, 'print(1 + 2)\n'), - ('print(1 + 2)\n', 0, 'print(1 + 2)\n'), - ), -) -def test_main_failing(tmpdir, input_src, expected_ret, output_src): - path = tmpdir.join('test.py') - path.write(input_src) - ret = main([path.strpath, '-i', '-v']) - assert ret == expected_ret - assert path.read() == output_src - - -def test_respects_config_file(tmpdir): - with tmpdir.as_cwd(): - tmpdir.join('setup.cfg').write('[pycodestyle]\nignore=E221') - tmpdir.join('test.py').write('print(1 + 2)\n') - assert main(['test.py', '-i', '-v']) == 0 +def test_invariantly_fails(): + with pytest.raises(SystemExit) as excinfo: + main() + msg, = excinfo.value.args + assert 'https://github.com/pre-commit/mirrors-autopep8' in msg