@@ -167,6 +167,42 @@ def textwrap_body(body, *, subsequent_indent=''):
167
167
paragraph = "\n " .join (lines )
168
168
paragraphs2 .append (paragraph )
169
169
else :
170
+ # Why do we reflow the text twice? Because it can actually change
171
+ # between the first and second reflows, and we want the text to
172
+ # be stable. The problem is that textwrap.wrap is deliberately
173
+ # dumb about how many spaces follow a period in prose.
174
+ #
175
+ # We're reflowing at 76 columns, but let's pretend it's 30 for
176
+ # illustration purposes. If we give textwrap.wrap the following
177
+ # text--ignore the line of 30 dashes, that's just to help you
178
+ # with visualization:
179
+ #
180
+ # ------------------------------
181
+ # xxxx xxxx xxxx xxxx xxxx. xxxx
182
+ #
183
+ # The first textwrap.wrap will return this:
184
+ # "xxxx xxxx xxxx xxxx xxxx.\nxxxx"
185
+ #
186
+ # If we reflow it again, textwrap will rejoin the lines, but
187
+ # only with one space after the period! So this time it'll
188
+ # all fit on one line, behold:
189
+ # ------------------------------
190
+ # xxxx xxxx xxxx xxxx xxxx. xxxx
191
+ # and so it now returns:
192
+ # "xxxx xxxx xxxx xxxx xxxx. xxxx"
193
+ #
194
+ # textwrap.wrap supports trying to add two spaces after a peroid:
195
+ # https://docs.python.org/3/library/textwrap.html#textwrap.TextWrapper.fix_sentence_endings
196
+ # But it doesn't work all that well, because it's not smart enough
197
+ # to do a really good job.
198
+ #
199
+ # Since blurbs are eventually turned into ReST and rendered anyway,
200
+ # and since the Zen says "In the face of ambiguity, refuse the
201
+ # temptation to guess", I don't sweat it. I run textwrap.wrap
202
+ # twice, so it's stable, and this means occasionally it'll
203
+ # convert two spaces to one space, no big deal.
204
+
205
+ paragraph = "\n " .join (textwrap .wrap (paragraph .strip (), width = 76 , ** kwargs )).rstrip ()
170
206
paragraph = "\n " .join (textwrap .wrap (paragraph .strip (), width = 76 , ** kwargs )).rstrip ()
171
207
paragraphs2 .append (paragraph )
172
208
# don't reflow literal code blocks (I hope)
@@ -937,15 +973,15 @@ def release(version):
937
973
git_add_files .append (output )
938
974
flush_git_add_files ()
939
975
940
- # sanity check: ensuring that saving/reloading the merged blurb file works.
941
- blurbs2 = Blurbs ()
942
- blurbs2 .load (output )
943
- assert blurbs2 == blurbs , "Reloading {} isn't reproducable?!" .format (output )
944
-
945
976
print ("Removing {} 'next' files from git." .format (len (filenames )))
946
977
git_rm_files .extend (filenames )
947
978
flush_git_rm_files ()
948
979
980
+ # sanity check: ensuring that saving/reloading the merged blurb file works.
981
+ blurbs2 = Blurbs ()
982
+ blurbs2 .load (output )
983
+ assert blurbs2 == blurbs , "Reloading {} isn't reproducible?!" .format (output )
984
+
949
985
print ()
950
986
print ("Ready for commit." )
951
987
0 commit comments