-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_linters.py
More file actions
80 lines (64 loc) · 2.05 KB
/
install_linters.py
File metadata and controls
80 lines (64 loc) · 2.05 KB
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
import subprocess
class Linter:
name: str
installation_command_line: list[str]
check_command_line: list[str]
def __init__(self, name: str, installation_command_line: list[str], check_command_line: list[str]):
self.name = name
self.installation_command_line = installation_command_line
self.check_command_line = check_command_line
def _is_linter_installed(linter: Linter):
"""
Check if a linter has been installed.
Parameters:
linter: Linter
Returns:
bool: True if linter is installed, else False
"""
try:
subprocess.run(linter.check_command_line, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return True
except subprocess.CalledProcessError:
return False
def _install_linter(linter: Linter):
"""
Install a linter.
Parameters:
linter: Linter
"""
print("Installing Linter...")
try:
subprocess.run(linter.installation_command_line, check=True)
print(f"{linter.name} installed successfully!✅")
except subprocess.CalledProcessError:
print(f"Failed to install {linter.name}❌")
def install(linter: Linter):
# Check if linter s already installed
if _is_linter_installed(linter):
print(f"{linter.name} is already installed.✅")
else:
_install_linter(linter)
# Define the desired linters you want to support
linters = [
Linter(
name="detekt",
installation_command_line=["brew", "install", "detekt"],
check_command_line=["brew", "list", "detekt"]
),
Linter(
name="markdownlint-cli",
installation_command_line=["brew", "install", "markdownlint-cli"],
check_command_line=["brew", "list", "markdownlint-cli"]
),
Linter(
name="prettier",
installation_command_line=["npm", "install", "-g", "prettier"],
check_command_line=["prettier", "--version"]
),
]
def main():
for linter in linters:
print(f"Installing {linter.name}...")
install(linter)
if __name__ == "__main__":
main()