Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
24 changes: 4 additions & 20 deletions pre_commit_hooks/autopep8_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
25 changes: 5 additions & 20 deletions tests/autopep8_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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