-
Notifications
You must be signed in to change notification settings - Fork 3
/
cosmetics.py
54 lines (44 loc) · 1.32 KB
/
cosmetics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import sys
from collections import namedtuple
from pathlib import Path
import black
from autoflake import fix_file
from isort import SortImports
AutoflakeArgs = namedtuple(
"AutoflakeArgs",
"remove_all_unused_imports "
"ignore_init_module_imports "
"remove_duplicate_keys "
"remove_unused_variables "
"in_place imports "
"expand_star_imports "
"check",
)
def remove_unused_imports(output_file_name: str) -> None:
fix_file(
output_file_name,
args=AutoflakeArgs(
remove_all_unused_imports=True,
ignore_init_module_imports=False,
imports=None,
expand_star_imports=False,
remove_duplicate_keys=False,
remove_unused_variables=True,
in_place=True,
check=False,
),
standard_out=sys.stdout,
)
def format_with_black(output_file_name: str) -> None:
black.format_file_in_place(
Path(output_file_name),
mode=black.FileMode(line_length=110),
fast=False,
write_back=black.WriteBack.YES,
)
def sort_imports(output_file_name: str) -> None:
SortImports(output_file_name)
def apply_cosmetics(output_file_name: str) -> None:
remove_unused_imports(output_file_name)
sort_imports(output_file_name)
format_with_black(output_file_name)