Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6508f25

Browse filesBrowse files
committed
Issue #205: Fix "blurb release" assertion error.
Blurb now wordwraps paragraphs twice for text stability. Paragraphs can shift around between the first and second times they are wordwrapped; this is because textwrap.wrap may change a sentence from ending with two spaces to ending with one space. It's better to live with the behavior, so now blurb just reflows paragraphs twice so they become stable.
1 parent d79d505 commit 6508f25
Copy full SHA for 6508f25

File tree

Expand file treeCollapse file tree

1 file changed

+41
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+41
-5
lines changed

‎blurb/blurb.py

Copy file name to clipboardExpand all lines: blurb/blurb.py
+41-5Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,42 @@ def textwrap_body(body, *, subsequent_indent=''):
167167
paragraph = "\n".join(lines)
168168
paragraphs2.append(paragraph)
169169
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()
170206
paragraph = "\n".join(textwrap.wrap(paragraph.strip(), width=76, **kwargs)).rstrip()
171207
paragraphs2.append(paragraph)
172208
# don't reflow literal code blocks (I hope)
@@ -937,15 +973,15 @@ def release(version):
937973
git_add_files.append(output)
938974
flush_git_add_files()
939975

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-
945976
print("Removing {} 'next' files from git.".format(len(filenames)))
946977
git_rm_files.extend(filenames)
947978
flush_git_rm_files()
948979

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+
949985
print()
950986
print("Ready for commit.")
951987

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.