Repository: pre-commit/pre-commit-hooks

Issue:
Autopep8 doesn't respect pep8 section in setup.cfg
Since https://github.com/hhatto/autopep8/pull/167 autopep8 has started reading the ```pep8``` section from ```tox.ini``` or ```setup.cfg``` of a project. However, the autopep8 hook ignores this as it calls ```autopep8.parse_args()``` and ```autopep8.fix_code()``` without a second value (which defaults to ```False```).

Any way we could get this to work?

Discussion:

Patch:
diff --git a/pre_commit_hooks/autopep8_wrapper.py b/pre_commit_hooks/autopep8_wrapper.py
index a79a120..f6f55fb 100644
--- a/pre_commit_hooks/autopep8_wrapper.py
+++ b/pre_commit_hooks/autopep8_wrapper.py
@@ -10,7 +10,7 @@ import autopep8
 
 def main(argv=None):
     argv = argv if argv is not None else sys.argv[1:]
-    args = autopep8.parse_args(argv)
+    args = autopep8.parse_args(argv, apply_config=True)
 
     retv = 0
     for filename in args.files:
diff --git a/setup.py b/setup.py
index 4fb9139..b86acd1 100644
--- a/setup.py
+++ b/setup.py
@@ -27,7 +27,7 @@ setup(
     packages=find_packages('.', exclude=('tests*', 'testing*')),
     install_requires=[
         'argparse',
-        'autopep8',
+        'autopep8>=1.1',
         'flake8',
         'plumbum',
         'pyflakes',


Test patch:
diff --git a/tests/autopep8_wrapper_test.py b/tests/autopep8_wrapper_test.py
index f32e8a0..9a395c9 100644
--- a/tests/autopep8_wrapper_test.py
+++ b/tests/autopep8_wrapper_test.py
@@ -2,7 +2,7 @@ from __future__ import absolute_import
 from __future__ import unicode_literals
 
 import io
-import os.path
+import os
 
 import pytest
 
@@ -17,9 +17,30 @@ from pre_commit_hooks.autopep8_wrapper import main
     ),
 )
 def test_main_failing(tmpdir, input_src, expected_ret, output_src):
-    filename = os.path.join(tmpdir.strpath, 'test.py')
+    filename = tmpdir.join('test.py').strpath
     with io.open(filename, 'w') as file_obj:
         file_obj.write(input_src)
     ret = main([filename, '-i', '-v'])
     assert ret == expected_ret
     assert io.open(filename).read() == output_src
+
+
+@pytest.yield_fixture
+def in_tmpdir(tmpdir):
+    pwd = os.getcwd()
+    os.chdir(tmpdir.strpath)
+    try:
+        yield
+    finally:
+        os.chdir(pwd)
+
+
+@pytest.mark.usefixtures('in_tmpdir')
+def test_respects_config_file():
+    with io.open('setup.cfg', 'w') as setup_cfg:
+        setup_cfg.write('[pep8]\nignore=E221')
+
+    with io.open('test.py', 'w') as test_py:
+        test_py.write('print(1    + 2)\n')
+
+    assert main(['test.py', '-i', '-v']) == 0