Skip to content

Commit 1917edc

Browse files
committed
Improved formatting of 'scrips/create_changelog.py' using autopep8
1 parent 2a73bb1 commit 1917edc

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

scripts/create_changelog.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def merge_contributors(original_file, new_contributors):
6161
Side effects:
6262
- Modifies the original XML file in-place
6363
"""
64-
with open(original_file, 'r',encoding='utf-8') as f:
64+
with open(original_file, 'r', encoding='utf-8') as f:
6565
original_content = f.read()
6666
tree = ET.fromstring(original_content)
6767

@@ -75,7 +75,7 @@ def merge_contributors(original_file, new_contributors):
7575
sorted_contributors = sorted(
7676
tree.findall('contributor'),
7777
# Items which don't have a name attribute are placed at the end
78-
key=lambda x: unidecode(get_last_name(x.get('name', '\x7F'))) # '\x7F' is highest ASCII value
78+
key=lambda x: unidecode(get_last_name(x.get('name', '\x7F'))) # '\x7F' is highest ASCII value
7979
)
8080

8181
for cont in tree.findall('contributor'):
@@ -113,12 +113,12 @@ def merge_contributors(original_file, new_contributors):
113113
for contributor in sorted_contributors:
114114
contrib_line = '<contributor'
115115
for attr, value in contributor.attrib.items():
116-
contrib_line += f'\n {attr}="{html.escape(value,quote=False)}"'
116+
contrib_line += f'\n {attr}="{html.escape(value, quote=False)}"'
117117
contrib_line += '/>'
118118
xml_lines.append(contrib_line)
119119
xml_lines.append('</contributors>')
120120

121-
with open(original_file, 'w',encoding='utf-8') as f:
121+
with open(original_file, 'w', encoding='utf-8') as f:
122122
f.write('\n'.join(xml_lines))
123123

124124

@@ -151,16 +151,16 @@ def fetch_real_name(github_name):
151151
"""
152152
url = f"https://api.github.com/users/{github_name}"
153153
try:
154-
res = requests.get(url,headers=HEADERS)
154+
res = requests.get(url, headers=HEADERS)
155155
res.raise_for_status()
156156
user = res.json()
157157
if not user['name']:
158158
return
159159
name_parts = user['name'].split()
160-
if len(name_parts) < 2: # Full name is not available
160+
if len(name_parts) < 2: # Full name is not available
161161
return
162162
git_to_name[github_name] = user['name']
163-
new_names.append((user['name'],github_name))
163+
new_names.append((user['name'], github_name))
164164
except Exception as e:
165165
print(f"Failed to fetch real name for @{github_name} : {str(e)}")
166166

@@ -182,11 +182,11 @@ def update_names():
182182
fetch_real_name(c)
183183
for tag in all_info:
184184
for pr in all_info[tag]:
185-
pr['creator'] = git_to_name.get(pr['creator'],f"@{pr['creator']}")
186-
pr['authors'] = [git_to_name.get(a,f"@{a}") for a in pr['authors']]
187-
pr['reviewers'] = [git_to_name.get(r,f"@{r}") for r in pr['reviewers']]
188-
all_contribs = set([git_to_name.get(c,f"@{c}") for c in all_contribs])
189-
first_contribs = set([git_to_name.get(c,f"@{c}") for c in first_contribs])
185+
pr['creator'] = git_to_name.get(pr['creator'], f"@{pr['creator']}")
186+
pr['authors'] = [git_to_name.get(a, f"@{a}") for a in pr['authors']]
187+
pr['reviewers'] = [git_to_name.get(r, f"@{r}") for r in pr['reviewers']]
188+
all_contribs = set([git_to_name.get(c, f"@{c}") for c in all_contribs])
189+
first_contribs = set([git_to_name.get(c, f"@{c}") for c in first_contribs])
190190

191191

192192
def get_release_data(tag):
@@ -393,7 +393,7 @@ def save_to_file(filename, ver, date_of_release):
393393
file.write(f"their first contribution to Sage:\n\n")
394394
max_name_len = max([len(c) for c in all_contribs])
395395
for c in all_contribs:
396-
file.write(f" - {c}{' '*(max_name_len - len(c)) + ' [First contribution]' if c in first_contribs else ''}\n")
396+
file.write(f" - {c}{' ' * (max_name_len - len(c)) + ' [First contribution]' if c in first_contribs else ''}\n")
397397
file.write(f"\nRelease manager: {RELEASE_MANAGER}\n")
398398
pr_count = sum([len(all_info[tag]) for tag in all_info])
399399
file.write(f"\nWe merged {pr_count} pull requests in this release.")
@@ -407,6 +407,7 @@ def save_to_file(filename, ver, date_of_release):
407407

408408
print(f"Saved changelog to {filename}")
409409

410+
410411
def get_latest_stable_release():
411412
"""Fetch the latest stable release tag from the API.
412413
@@ -420,14 +421,15 @@ def get_latest_stable_release():
420421
res = res.json()
421422
tag = res['tag_name']
422423
date = get_release_date(res)
423-
return {"tag":tag,"date":date}
424+
return {"tag": tag, "date": date}
424425
except Exception as e:
425-
print(f"Failed to fetch latest stable release",e)
426+
print(f"Failed to fetch latest stable release", e)
426427
return None
427428

429+
428430
def update_config(ver: str, release_date: str, config_file_path: str):
429431
"""Update version and release date in the config file.
430-
432+
431433
Args:
432434
ver (str): New version to set
433435
release_date (str): Release date to set
@@ -438,11 +440,12 @@ def update_config(ver: str, release_date: str, config_file_path: str):
438440

439441
content = re.sub(r'release_date:\s*".*?"', f'release_date: "{release_date}"', content)
440442
content = re.sub(r'version:\s*".*?"', f'version: "{ver}"', content)
441-
content = re.sub(r'version_src:\s*".*?"',f'version_src: "{ver}"',content)
443+
content = re.sub(r'version_src:\s*".*?"', f'version_src: "{ver}"', content)
442444

443445
with open(config_file_path, 'w') as file:
444446
file.write(content)
445447

448+
446449
if __name__ == '__main__':
447450
parser = argparse.ArgumentParser(description="Fetch release data from GitHub and extract PR info")
448451
parser.add_argument('version', type=str, help="The release version (e.g., 10.1)")
@@ -487,13 +490,13 @@ def update_config(ver: str, release_date: str, config_file_path: str):
487490
save_to_file(filepath, ver, date_of_release)
488491
latest_release = get_latest_stable_release()
489492
if latest_release:
490-
update_config(latest_release['tag'],latest_release['date'],'conf/config.yaml')
493+
update_config(latest_release['tag'], latest_release['date'], 'conf/config.yaml')
491494
else:
492495
print("No information found.")
493496
exit(1)
494497

495498
if new_names:
496-
merge_contributors('conf/contributors.xml',new_names)
499+
merge_contributors('conf/contributors.xml', new_names)
497500
print("Added new contributors to conf/contributors.xml")
498501
else:
499502
print("No new contributors found.")

0 commit comments

Comments
 (0)