@@ -43,6 +43,7 @@ def fix_code(code, directory):
43
43
# Get black config from pyproject.toml
44
44
line_length = black .DEFAULT_LINE_LENGTH
45
45
string_normalization = True
46
+ target_versions = set ()
46
47
pyproject_path = os .path .join (directory , "pyproject.toml" )
47
48
if toml is not None and os .path .exists (pyproject_path ):
48
49
pyproject_config = toml .load (pyproject_path )
@@ -51,16 +52,25 @@ def fix_code(code, directory):
51
52
line_length = black_config ["line-length" ]
52
53
if "skip-string-normalization" in black_config :
53
54
string_normalization = not black_config ["skip-string-normalization" ]
55
+ if "target-version" in black_config :
56
+ target_versions = {
57
+ black .TargetVersion [v .upper ()] for v in black_config ["target-version" ]
58
+ }
59
+
54
60
try :
55
61
if parse_version (black .__version__ ) < parse_version ("19.0" ):
56
62
reformatted_source = black .format_file_contents (
57
- src_contents = code , line_length = line_length , fast = False )
63
+ src_contents = code , line_length = line_length , fast = False
64
+ )
58
65
else :
59
66
fm = black .FileMode (
60
67
line_length = line_length ,
61
- string_normalization = string_normalization )
68
+ string_normalization = string_normalization ,
69
+ target_versions = target_versions ,
70
+ )
62
71
reformatted_source = black .format_file_contents (
63
- src_contents = code , fast = False , mode = fm )
72
+ src_contents = code , fast = False , mode = fm
73
+ )
64
74
return reformatted_source
65
75
except black .NothingChanged :
66
76
return code
0 commit comments