Skip to content

Commit ff98426

Browse files
committed
script: apply black suggestions on gitlog2changelog.py
Apply on gitlog2changelog.py code change suggestions from Black Python code formatter.
1 parent 36f46fe commit ff98426

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

.aspell.en.pws

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 904
1+
personal_ws-1.1 en 905
22
ABBRVLIST
33
ActiveTcl
44
Adrien
@@ -423,6 +423,7 @@ foobin
423423
foocmd
424424
foreach
425425
formatModuleCacheContent
426+
formatter
426427
foss
427428
fpath
428429
frontend

script/gitlog2changelog.py.in

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ from textwrap import TextWrapper
88
import sys
99
import subprocess
1010

11-
rev_range = 'HEAD'
11+
rev_range = "HEAD"
1212

1313
if len(sys.argv) > 1:
1414
base = sys.argv[1]
15-
rev_range = '%s..HEAD' % base
15+
rev_range = "%s..HEAD" % base
1616

1717
# Execute git log with the desired command line options.
1818
# Support Python2 and Python3 (esp. 3.6 and earlier) semantics
@@ -22,25 +22,41 @@ fin_mode = 0
2222
fin_chop = 0
2323
try:
2424
p = subprocess.Popen(
25-
['git', 'log', '--pretty=medium', '--summary', '--stat', '--no-merges', '--date=short', ('%s' % rev_range)],
26-
encoding='utf-8', close_fds = True,
27-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
25+
[
26+
"git",
27+
"log",
28+
"--pretty=medium",
29+
"--summary",
30+
"--stat",
31+
"--no-merges",
32+
"--date=short",
33+
("%s" % rev_range),
34+
],
35+
encoding="utf-8",
36+
close_fds=True,
37+
stdout=subprocess.PIPE,
38+
stderr=subprocess.PIPE,
39+
)
2840
fin, ferr = p.communicate()
2941
if p.wait() != 0:
30-
print ("ERROR getting git changelog")
42+
print("ERROR getting git changelog")
3143
system.exit(1)
3244
fin = fin.splitlines()
3345
fin_mode = 3
3446
except TypeError:
35-
fin = os.popen('git log --pretty=medium --summary --stat --no-merges --date=short %s' % rev_range, 'r')
47+
fin = os.popen(
48+
"git log --pretty=medium --summary --stat --no-merges --date=short %s"
49+
% rev_range,
50+
"r",
51+
)
3652
fin_mode = 2
3753
fin_chop = 1
3854

3955
# Create a ChangeLog file in the current directory.
4056
if fin_mode == 3:
41-
fout = open('ChangeLog', 'w', encoding='UTF-8')
57+
fout = open("ChangeLog", "w", encoding="UTF-8")
4258
else:
43-
fout = open('ChangeLog', 'w')
59+
fout = open("ChangeLog", "w")
4460

4561
# Set up the loop variables in order to locate the blocks we want
4662
authorFound = False
@@ -52,12 +68,14 @@ messageNL = False
5268
files = ""
5369
prevAuthorLine = ""
5470

55-
wrapper = TextWrapper(initial_indent=" ", subsequent_indent=" ", width=78, break_on_hyphens=False)
71+
wrapper = TextWrapper(
72+
initial_indent=" ", subsequent_indent=" ", width=78, break_on_hyphens=False
73+
)
5674

5775
# The main part of the loop
5876
for line in fin:
5977
# The commit line marks the start of a new commit object.
60-
if line.startswith('commit'):
78+
if line.startswith("commit"):
6179
# Start all over again...
6280
authorFound = False
6381
dateFound = False
@@ -69,32 +87,32 @@ for line in fin:
6987
continue
7088
# Match the author line and extract the part we want
7189
# (Don't use startswith to allow Author override inside commit message.)
72-
elif 'Author:' in line:
73-
authorList = re.split(': ', line, 1)
90+
elif "Author:" in line:
91+
authorList = re.split(": ", line, 1)
7492
try:
7593
author = authorList[1]
76-
author = author[0:len(author) - fin_chop]
94+
author = author[0 : len(author) - fin_chop]
7795
authorFound = True
7896
except:
79-
print ("Could not parse authorList = '%s'" % (line))
97+
print("Could not parse authorList = '%s'" % (line))
8098

8199
# Match the date line
82-
elif line.startswith('Date:'):
83-
dateList = re.split(': ', line, 1)
100+
elif line.startswith("Date:"):
101+
dateList = re.split(": ", line, 1)
84102
try:
85103
date = dateList[1]
86-
date = date[0:len(date) - fin_chop]
104+
date = date[0 : len(date) - fin_chop]
87105
dateFound = True
88106
except:
89-
print ("Could not parse dateList = '%s'" % (line))
107+
print("Could not parse dateList = '%s'" % (line))
90108
# The Fossil-IDs are ignored:
91-
elif line.startswith(' Fossil-ID:') or line.startswith(' [[SVN:'):
109+
elif line.startswith(" Fossil-ID:") or line.startswith(" [[SVN:"):
92110
continue
93111
# The svn-id lines are ignored
94-
elif ' git-svn-id:' in line:
112+
elif " git-svn-id:" in line:
95113
continue
96114
# The sign off line is ignored too
97-
elif 'Signed-off-by' in line:
115+
elif "Signed-off-by" in line:
98116
continue
99117
# Extract the actual commit message for this commit
100118
elif authorFound & dateFound & messageFound == False:
@@ -112,12 +130,12 @@ for line in fin:
112130
else:
113131
message = message + " " + line.strip()
114132
# If this line is hit all of the files have been stored for this commit
115-
elif re.search('files? changed', line):
133+
elif re.search("files? changed", line):
116134
filesFound = True
117135
continue
118136
# Collect the files for this commit. FIXME: Still need to add +/- to files
119137
elif authorFound & dateFound & messageFound:
120-
fileList = re.split(' \| ', line, 2)
138+
fileList = re.split(" \| ", line, 2)
121139
if len(fileList) > 1:
122140
if len(files) > 0:
123141
files = files + ", " + fileList[0].strip()
@@ -145,8 +163,8 @@ for line in fin:
145163
namesF = None
146164
namesM = None
147165
try:
148-
namesM = sorted(re.split(r'[ ,]', message.split(":")[0]))
149-
namesF = sorted(re.split(r'[ ,]', files))
166+
namesM = sorted(re.split(r"[ ,]", message.split(":")[0]))
167+
namesF = sorted(re.split(r"[ ,]", files))
150168
except:
151169
pass
152170

@@ -158,7 +176,7 @@ for line in fin:
158176
# Write out the commit line
159177
fout.write(wrapper.fill(commitLine) + "\n")
160178

161-
#Now reset all the variables ready for a new commit block.
179+
# Now reset all the variables ready for a new commit block.
162180
authorFound = False
163181
dateFound = False
164182
messageFound = False

0 commit comments

Comments
 (0)