import autopep8

from coalib.bearlib.abstractions.Lint import Lint
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
from coalib.bears.LocalBear import LocalBear
from coalib.settings.Setting import typed_list


class PEP8Bear(Lint, LocalBear):
    diff_message = "The code does not comply to PEP8."
    gives_corrected = True

    def lint(self, filename, file, **kwargs):
        new_file = autopep8.fix_code(''.join(file), options=kwargs)
        output = new_file.splitlines(True)
        return self.process_output(output, filename, file)

    def run(self,
            filename,
            file,
            max_line_length: int=80,
            tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
            pep_ignore: typed_list(str)=(),
            pep_select: typed_list(str)=()):
        """
        Detects and fixes PEP8 incompliant code. This bear will not change
        functionality of the code in any way.

        :param max_line_length: Maximum number of characters for a line.
        :param tab_width:       Number of spaces per indent level.
        :param pep_ignore:      A list of errors/warnings to ignore.
        :param pep_select:      A list of errors/warnings to exclusively apply.
        """
        return self.lint(filename,
                         file,
                         ignore=pep_ignore,
                         select=pep_select,
                         max_line_length=max_line_length,
                         indent_size=tab_width)

@@ -367,16 +367,30 @@
 e, file,
+ apply_config,
  **kwarg
@@ -459,16 +459,80 @@
 s=kwargs
+,%0A                                     apply_config=apply_config
 )%0A      
@@ -869,16 +869,59 @@
 (str)=()
+,%0A            local_pep8_config: bool=False
 ):%0A     
@@ -1080,16 +1080,18 @@
 _length:
+  
  Maximum
@@ -1149,16 +1149,18 @@
 b_width:
+  
        N
@@ -1221,24 +1221,26 @@
 gnore:      
+  
 A list of er
@@ -1290,16 +1290,18 @@
 _select:
+  
       A 
@@ -1338,21 +1338,212 @@
 lusively
- appl
+%0A                                  apply.%0A        :param local_pep8_config: Set to true if autopep8 should use a config%0A                                  file as if run normally from this director
 y.%0A     
@@ -1607,32 +1607,89 @@
           file,%0A
+                         apply_config=local_pep8_config,%0A
                 

Add local_pep8_config option