Completed
Pull Request — master (#1152)
by Lasse
01:50
created

bears.python.PyImportSortBear   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %
Metric Value
dl 0
loc 13
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 12 2
1
from isort import SortImports
2
3
from coalib.bears.LocalBear import LocalBear
4
from coalib.results.Diff import Diff
5
from coalib.results.Result import Result
6
7
8
class PyImportSortBear(LocalBear):
9
    def run(self, filename, file):
10
        """
11
        Sorts imports for python.
12
        """
13
        new_file = SortImports(
14
            file_contents=''.join(file)).output.splitlines(True)
15
        if new_file != file:
16
            diff = Diff.from_string_arrays(file, new_file)
17
            yield Result(self,
18
                         "Imports can be sorted.",
19
                         affected_code=diff.affected_code(filename),
20
                         diffs={filename: diff})
21