-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
55 lines (44 loc) · 1.65 KB
/
fabfile.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
from pathlib import Path
import time
from fabric import task
import io
from contextlib import redirect_stderr
@task
def strip_hints(context):
return
start = time.time()
print(start)
errors = []
SOURCES = Path('legacy_strip_hints/')
STRIPPER = Path('strip_hints/bin/strip_hints.py')
for index, file_for_strip_tags in enumerate(SOURCES.rglob('*.py')):
if (index % 50) == 0:
print(index)
try:
context.run(f'python {STRIPPER.absolute()} {file_for_strip_tags.absolute()} --inplace', hide=True)
except Exception as error:
errors.append(str(file_for_strip_tags))
end = time.time()
print('elapsed time', end - start)
print('errors', len(errors))
Path('errors_strip_hints.txt').write_text('\n'.join(errors), newline='\n')
@task
def remove_unused_imports(context):
start = time.time()
print(start)
errors = []
SOURCES = Path('legacy_strip_hints/')
for index, file_for_strip_tags in enumerate(SOURCES.rglob('*.py')):
if (index % 50) == 0:
print(index)
err_catcher = io.StringIO()
with redirect_stderr(err_catcher):
context.run(f'autoflake --remove-all-unused-imports --in-place -v {file_for_strip_tags.absolute()}', standard_out = None, standard_error = None)
err_output = err_catcher.getvalue()
if err_output:
print('error', err_output, file_for_strip_tags)
errors.append(str(file_for_strip_tags))
end = time.time()
print('elapsed time', end - start)
print('errors', len(errors))
Path('errors_unused_imports.txt').write_text('\n'.join(errors), newline='\n')