Skip to content

Commit cf225d6

Browse files
committed
blurb: don't overwrite output when not necessary
This speeds up doc generation. With this change, blurb won't update the NEWS file unnecessarily, which means Sphinx will then use a cache instead of parsing it again.
1 parent 0dd9f16 commit cf225d6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

blurb/blurb.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
from collections import OrderedDict
5050
import glob
5151
import hashlib
52+
import io
5253
import inspect
5354
import itertools
5455
import math
5556
import os
57+
from pathlib import Path
5658
import re
5759
import shlex
5860
import shutil
@@ -1068,9 +1070,11 @@ def merge(output=None, *, forced=False):
10681070

10691071

10701072
def write_news(output, *, versions):
1073+
buff = io.StringIO()
1074+
10711075
def print(*a, sep=" "):
10721076
s = sep.join(str(x) for x in a)
1073-
return builtins.print(s, file=news)
1077+
return builtins.print(s, file=buff)
10741078

10751079
print ("""
10761080
+++++++++++
@@ -1131,7 +1135,20 @@ def print(*a, sep=" "):
11311135
print(text)
11321136
print()
11331137
print("**(For information about older versions, consult the HISTORY file.)**")
1134-
news.close()
1138+
1139+
1140+
new_contents = buff.getvalue()
1141+
1142+
# Only write in `output` if the contents are different
1143+
# This speeds up subsequent Sphinx builds
1144+
try:
1145+
previous_contents = Path(output).read_text(encoding="UTF-8")
1146+
except (FileNotFoundError, UnicodeError):
1147+
previous_contents = None
1148+
if new_contents != previous_contents:
1149+
Path(output).write_text(new_contents, encoding="UTF-8")
1150+
else:
1151+
builtins.print(output, "is already up to date")
11351152

11361153

11371154
git_add_files = []

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy