-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuff_auto.py
52 lines (41 loc) · 1.66 KB
/
Ruff_auto.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
# Libs >>>
import os
import subprocess
# Main func >>>
def run_ruff():
# Ensure Logs\others directory exists
if not os.path.exists("Logs\\others"):
os.makedirs("Logs\\others")
# Define the log file paths
lint_log_path = os.path.join("Logs\\others", "ruff_lint_log.txt")
format_log_path = os.path.join("Logs\\others", "ruff_format_log.txt")
# Define the ruff commands for linting and formatting
lint_command = ["ruff", "check", ".", "--output-format=text"]
format_command = ["ruff", "format", "."]
# Run the lint command and capture output
with open(lint_log_path, "w") as lint_log:
lint_result = subprocess.run(lint_command, capture_output=True, text=True)
lint_log.write(lint_result.stdout)
if lint_result.stderr:
lint_log.write(lint_result.stderr)
# Run the format command and capture output
with open(format_log_path, "w") as format_log:
format_result = subprocess.run(format_command, capture_output=True, text=True)
format_log.write(format_result.stdout)
if format_result.stderr:
format_log.write(format_result.stderr)
# Print success or error messages
if lint_result.returncode == 0:
print("Linting completed successfully.")
else:
print(
f"Linting encountered issues. Please check the log file for more details: {lint_log_path}"
)
if format_result.returncode == 0:
print("Formatting completed successfully.")
else:
print(
f"Formatting encountered issues. Please check the log file for more details: {format_log_path}"
)
if __name__ == "__main__":
run_ruff()