1
1
# -*- coding: utf-8 -*-
2
2
3
- import isort
4
-
3
+ from contextlib import redirect_stdout
4
+ from difflib import Differ
5
+ from difflib import unified_diff
6
+ from io import StringIO
7
+ from pathlib import Path
5
8
6
- if hasattr (isort , 'api' ): # isort 5
7
- from contextlib import redirect_stdout
8
- from difflib import unified_diff
9
- from io import StringIO
10
- from pathlib import Path
9
+ import isort
10
+ import warnings
11
11
12
- import warnings
13
- else :
14
- from difflib import Differ
15
- from testfixtures import OutputCapture
16
12
17
13
__version__ = '4.1.2.dev0'
18
14
@@ -46,7 +42,6 @@ def __init__(self, tree, filename, lines):
46
42
47
43
@classmethod
48
44
def add_options (cls , parser ):
49
-
50
45
parser .add_option (
51
46
'--isort-show-traceback' ,
52
47
action = 'store_true' ,
@@ -68,7 +63,8 @@ def run(self):
68
63
file_path = self .filename
69
64
else :
70
65
file_path = None
71
- with OutputCapture () as buffer :
66
+ buffer = StringIO ()
67
+ with redirect_stdout (buffer ):
72
68
sort_result = isort .SortImports (
73
69
file_path = file_path ,
74
70
file_contents = '' .join (self .lines ),
@@ -129,7 +125,7 @@ def _format_isort_output(self, isort_buffer):
129
125
valid_lines = ['' ]
130
126
valid_lines += [
131
127
line
132
- for line in isort_buffer .output . getvalue ().splitlines ()
128
+ for line in isort_buffer .getvalue ().splitlines ()
133
129
if line .strip ().split (' ' , 1 )[0 ] not in filtering_out
134
130
]
135
131
0 commit comments