@@ -10,6 +10,28 @@ def prettier_format():
10
10
command = f'npx prettier --write "**/*.{ suffix } "'
11
11
os .system (command )
12
12
13
+ # format php code
14
+ for root , _ , files in os .walk (path ):
15
+ for name in files :
16
+ if name .endswith ('.php' ):
17
+ p1 = root + '/' + name
18
+ with open (p1 , 'r' , encoding = 'utf-8' ) as f :
19
+ content = f .read ()
20
+ content = '<?php\n ' + content
21
+ with open (p1 , 'w' , encoding = 'utf-8' ) as f :
22
+ f .write (content )
23
+ command = 'npx prettier --write "**/*.php"'
24
+ os .system (command )
25
+ for root , _ , files in os .walk (path ):
26
+ for name in files :
27
+ if name .endswith ('.php' ):
28
+ p1 = root + '/' + name
29
+ with open (p1 , 'r' , encoding = 'utf-8' ) as f :
30
+ content = f .read ()
31
+ content = content .replace ('<?php\n ' , '' )
32
+ with open (p1 , 'w' , encoding = 'utf-8' ) as f :
33
+ f .write (content )
34
+
13
35
14
36
def clang_format ():
15
37
"""Format code with clang-format"""
@@ -49,7 +71,8 @@ def clang_format():
49
71
os .remove (p2 )
50
72
51
73
52
- def format_py ():
74
+ def black_format ():
75
+ """Format python code with black"""
53
76
command = 'black -S .'
54
77
os .system (command )
55
78
@@ -60,7 +83,7 @@ def format_py():
60
83
with open (p1 , 'r' , encoding = 'utf-8' ) as f :
61
84
content = f .read ()
62
85
x = content
63
- res = re .findall (f '```python\n (.*?)```' , content , re .S )
86
+ res = re .findall ('```python\n (.*?)```' , content , re .S )
64
87
if not res :
65
88
continue
66
89
print (p1 )
@@ -77,38 +100,14 @@ def format_py():
77
100
os .remove (p2 )
78
101
79
102
80
- def format_php ():
81
- for root , _ , files in os .walk (path ):
82
- for name in files :
83
- if name .endswith ('.php' ):
84
- p1 = root + '/' + name
85
- with open (p1 , 'r' , encoding = 'utf-8' ) as f :
86
- content = f .read ()
87
- content = '<?php\n ' + content
88
- with open (p1 , 'w' , encoding = 'utf-8' ) as f :
89
- f .write (content )
90
- command = f'npx prettier --write "**/*.php"'
91
- os .system (command )
92
- for root , _ , files in os .walk (path ):
93
- for name in files :
94
- if name .endswith ('.php' ):
95
- p1 = root + '/' + name
96
- with open (p1 , 'r' , encoding = 'utf-8' ) as f :
97
- content = f .read ()
98
- content = content .replace ('<?php\n ' , '' )
99
- with open (p1 , 'w' , encoding = 'utf-8' ) as f :
100
- f .write (content )
101
-
102
-
103
103
def git_add ():
104
104
"""Git add all files"""
105
105
command = 'git add .'
106
106
os .system (command )
107
107
108
108
109
109
if __name__ == '__main__' :
110
+ prettier_format ()
111
+ black_format ()
110
112
# clang_format()
111
- # prettier_format()
112
- # format_py()
113
- # git_add()
114
- format_php ()
113
+ git_add ()
0 commit comments