Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pathlib in fixup_whats_new_pr.py #12552

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 10 additions & 17 deletions tools/fixup_whats_new_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,29 @@
notes.
"""

import glob

from pathlib import Path

def main():
folder = 'docs/source/whatsnew/pr/'
assert folder.endswith('/')
files = glob.glob(folder+'*.rst')
folder = Path("docs/source/whatsnew/pr/")
files = list(folder.glob("*.rst"))
print(files)

for filename in files:
print('Adding pseudo-title to:', filename)
title = filename[:-4].split('/')[-1].replace('-', ' ').capitalize()
for filepath in files:
print("Adding pseudo-title to:", filepath.name)
title = filepath.name[:-4].split("/")[-1].replace("-", " ").capitalize()

with open(filename) as f:
data = f.read()
data = filepath.read_text()
try:
if data and data.splitlines()[1].startswith('='):
continue
except IndexError:
pass

with open(filename, 'w') as f:
f.write(title+'\n')
f.write('='* len(title)+'\n\n')
with filepath.open("w") as f:
f.write(title + "\n")
f.write("=" * len(title) + "\n\n")
f.write(data)

if __name__ == '__main__':
main()