(self, filename, write=False, doctests_only=False)
Refactors a file.
Refactors a file.
Refactors a file .
def refactor_file(self, filename, write=False, doctests_only=False):
        """Refactors a file."""
        input, encoding = self._read_python_source(filename)
        if input is None:
            # Reading the file failed.
            return
        input += "\n" # Silence certain parse errors
        if doctests_only:
            self.log_debug("Refactoring doctests in %s", filename)
            output = self.refactor_docstring(input, filename)
            if self.write_unchanged_files or output != input:
                self.processed_file(output, filename, input, write, encoding)
            else:
                self.log_debug("No doctest changes in %s", filename)
        else:
            tree = self.refactor_string(input, filename)
            if self.write_unchanged_files or (tree and tree.was_changed):
                # The [:-1] is to take off the \n we added earlier
                self.processed_file(str(tree)[:-1], filename,
                                    write=write, encoding=encoding)
            else:
                self.log_debug("No changes in %s", filename)
def refactor_file ( self , filename , write = False , doctests_only = False ) : input , encoding = self . _read_python_source ( filename ) if input is None : # Reading the file failed. return input += "\n" # Silence certain parse errors if doctests_only : self . log_debug ( "Refactoring doctests in %s" , filename ) output = self . refactor_docstring ( input , filename ) if self . write_unchanged_files or output != input : self . processed_file ( output , filename , input , write , encoding ) else : self . log_debug ( "No doctest changes in %s" , filename ) else : tree = self . refactor_string ( input , filename ) if self . write_unchanged_files or ( tree and tree . was_changed ) : # The [:-1] is to take off the \n we added earlier self . processed_file ( str ( tree ) [ : - 1 ] , filename , write = write , encoding = encoding ) else : self . log_debug ( "No changes in %s" , filename )