8000 blurb: don't overwrite output when not necessary by dmerejkowsky · Pull Request #403 · python/core-workflow · GitHub
[go: up one dir, main page]

Skip to content

blurb: don't overwrite output when not necessary #403

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? 8000 Sign in to your account

Merged
merged 2 commits into from
May 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions blurb/blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
from collections import OrderedDict
import glob
import hashlib
import io
import inspect
import itertools
import math
import os
from pathlib import Path
import re
import shlex
import shutil
Expand Down Expand Up @@ -1064,11 +1066,15 @@ def merge(output=None, *, forced=False):
builtins.print(&q A6AE uot;You already have a", repr(output), "file.")
require_ok("Type ok to overwrite")

news = open(output, "wt", encoding="utf-8")
write_news(output, versions=versions)


def write_news(output, *, versions):
buff = io.StringIO()

def print(*a, sep=" "):
s = sep.join(str(x) for x in a)
return builtins.print(s, file=news)
return builtins.print(s, file=buff)

print ("""
+++++++++++
Expand Down Expand Up @@ -1129,7 +1135,20 @@ def print(*a, sep=" "):
print(text)
print()
print("**(For information about older versions, consult the HISTORY file.)**")
news.close()


new_contents = buff.getvalue()

# Only write in `output` if the contents are different
# This speeds up subsequent Sphinx builds
try:
previous_contents = Path(output).read_text(encoding="UTF-8")
except (FileNotFoundError, UnicodeError):
previous_contents = None
if new_contents != previous_contents:
Path(output).write_text(new_contents, encoding="UTF-8")
else:
builtins.print(output, "is already up to date")


git_add_files = []
Expand Down
0