-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonSpaceLines.py
59 lines (33 loc) · 1.17 KB
/
PythonSpaceLines.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
import logging
import re
import sys
from json import dump, dumps
from pathlib import Path
import black
def FormatPythonFile(filePath: Path) -> None:
"""
Formats a Python file using the Black API.
"""
fileContent = Path(filePath).read_text()
formattedContent = black.format_str(fileContent, mode=black.Mode())
Path(filePath).write_text(formattedContent)
def FormatNewlines(filePath: Path) -> None:
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s: %(message)s")
if not filePath.is_file():
logging.error(f"File not found - {filePath}")
sys.exit(1)
with open(filePath, "r") as file:
codeContent = file.read()
def FormatFile(filePath: Path) -> None:
FormatNewlines(filePath=filePath)
FormatPythonFile(filePath=filePath)
if __name__ == "__main__":
currentFilePath = Path(__file__).resolve()
logging.debug(f"Current file path: {currentFilePath}")
FormatFile(currentFilePath)
raise SystemExit
if len(sys.argv) != 2:
print("Usage: python PythonSpaceLines.py <filePath>")
print(f"Received arguments: {sys.argv}")
sys.exit(1)
FormatFile(sys.argv[1])