-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev.py
144 lines (120 loc) · 3.1 KB
/
dev.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
import asyncio
import json
import os
import subprocess
import sys
import isort
# for each py files exclude from specific folders, sort import
excluded_folders = [
"venv",
"__pycache__",
".mypycache",
".mypy_cache",
"build",
"dist",
"docs",
"cache",
]
"""List of folders to exclude from formatting"""
def print_file(path_name: str) -> None:
"""
Prints the file name.
Args:
path_name (str): The path name of the file.
Returns:
None
"""
print(f"Formatting file: {path_name}")
return None
def format_scripts():
"""
Formats all python scripts in project file
Returns:
None
"""
for root, dirs, files in os.walk("."):
# exclude the folders in the excluded_folders list
dirs[:] = [d for d in dirs if d not in excluded_folders]
for file in files:
if file.endswith(".py"):
# print full path of the file
file_path = os.path.join(root, file)
print_file(file_path)
# sort imports in the file
isort.file(file_path)
# format the file using autopep8
subprocess.run(
[
"autopep8",
"--in-place",
"--aggressive",
"--aggressive",
file_path,
],
check=True,
)
elif file.endswith(".json"):
file_path = os.path.join(root, file)
print_file(file_path)
with open(file_path, "r+") as f:
data = json.load(f)
f.seek(0)
json.dump(data, f, indent=2)
f.truncate()
async def loop_test():
"""
Do a test for each API calls
Returns:
None
"""
sub = subprocess.Popen(
[
sys.executable,
"-m",
"coverage",
"run",
]
)
sub.wait()
sub = subprocess.Popen(
[
sys.executable,
"-m",
"coverage",
"report",
]
)
sub.wait()
sub = subprocess.Popen(
[
sys.executable,
"-m",
"coverage",
"xml",
]
)
sub.wait()
async def main():
"""
Main function of the script
Return:
None
"""
answer_test = input("Do you want to test all API calls? (y/N): ")
answer_test = answer_test.lower() == "y"
if answer_test:
print("Testing API calls found in classes folder")
await loop_test()
else:
print("Alright, I won't test the API calls.")
# ask if user want to format all files
answer_format = input("Do you want to format all files? (y/N): ")
answer_format = answer_format.lower() == "y"
# walk through the current directory
if answer_format:
format_scripts()
else:
print("Alright, I won't format the files.")
if __name__ == "__main__":
asyncio.run(main())