Skip to content

Commit

Permalink
Switch entirely off of the implicit-format() message signature, to fi…
Browse files Browse the repository at this point in the history
…nally stop the 'panic when an f-string gets some curly braces in it' errors.
  • Loading branch information
tabatkins committed Oct 13, 2021
1 parent 4011944 commit 368df1c
Show file tree
Hide file tree
Showing 45 changed files with 346 additions and 898 deletions.
19 changes: 6 additions & 13 deletions bikeshed/Spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ def initializeState(self):
if inputContent.date is not None:
self.mdBaseline.addParsedData("Date", inputContent.date)
except FileNotFoundError:
die(
"Couldn't find the input file at the specified location '{0}'.",
self.inputSource,
)
die(f"Couldn't find the input file at the specified location '{self.inputSource}'.")
return False
except OSError:
die("Couldn't open the input file '{0}'.", self.inputSource)
die(f"Couldn't open the input file '{self.inputSource}'.")
return False

return True
Expand Down Expand Up @@ -304,7 +301,7 @@ def serialize(self):
try:
rendered = h.Serializer(self.md.opaqueElements, self.md.blockElements).serialize(self.document)
except Exception as e:
die("{0}", e)
die(str(e))
return
rendered = finalHackyCleanup(rendered)
return rendered
Expand Down Expand Up @@ -334,11 +331,7 @@ def finish(self, outputFilename=None, newline=None):
with open(outputFilename, "w", encoding="utf-8", newline=newline) as f:
f.write(rendered)
except Exception as e:
die(
"Something prevented me from saving the output document to {0}:\n{1}",
outputFilename,
e,
)
die(f"Something prevented me from saving the output document to {outputFilename}:\n{e}")

def printResultMessage(self):
# If I reach this point, I've succeeded, but maybe with reservations.
Expand All @@ -351,7 +344,7 @@ def printResultMessage(self):
success("Successfully generated, but fatal errors were suppressed")
return
if links:
success("Successfully generated, with {0} linking errors", links)
success(f"Successfully generated, with {links} linking errors")
return
if warnings:
success("Successfully generated, with warnings")
Expand Down Expand Up @@ -416,7 +409,7 @@ def log_message(self, format, *args):
thread.join()
sys.exit(0)
except Exception as e:
die("Something went wrong while watching the file:\n{0}", e)
die(f"Something went wrong while watching the file:\n{e}")

def fixText(self, text, moreMacros={}):
# Do several textual replacements that need to happen *before* the document is parsed as h.
Expand Down
8 changes: 4 additions & 4 deletions bikeshed/biblio.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def processReferBiblioFile(lines, storage, order):
if match:
letter, value = match.groups()
else:
die("Biblio line in unexpected format:\n{0}", line)
die(f"Biblio line in unexpected format:\n{line}")
continue

if letter in singularReferCodes:
Expand All @@ -233,7 +233,7 @@ def processReferBiblioFile(lines, storage, order):
elif letter in unusedReferCodes:
pass
else:
die("Unknown line type ")
die(f"Unknown line type {letter}:\n{line}")
if biblio is not None:
storage[biblio["linkText"].lower()] = biblio
return storage
Expand Down Expand Up @@ -277,7 +277,7 @@ def processSpecrefBiblioFile(text, storage, order):
try:
datas = json.loads(text)
except Exception as e:
die("Couldn't read the local JSON file:\n{0}", str(e))
die(f"Couldn't read the local JSON file:\n{e}")
return storage

# JSON field name: BiblioEntry name
Expand Down Expand Up @@ -372,7 +372,7 @@ def loadBiblioDataFile(lines, storage):
}
line = next(lines) # Eat the -
else:
die("Unknown biblio prefix '{0}' on key '{1}'", prefix, fullKey)
die(f"Unknown biblio prefix '{prefix}' on key '{fullKey}'")
continue
storage[key].append(b)
except StopIteration:
Expand Down
26 changes: 8 additions & 18 deletions bikeshed/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,7 @@ def addExplicitIndexes(doc):
status = el.get("status")
if status and status not in config.specStatuses:
die(
"<index> has unknown value '{0}' for status. Must be {1}.",
status,
config.englishFromList(config.specStatuses),
f"<index> has unknown value '{status}' for status. Must be {config.englishFromList(config.specStatuses)}.",
el=el,
)
continue
Expand All @@ -371,7 +369,7 @@ def addExplicitIndexes(doc):
for t in types:
if t not in config.dfnTypes:
die(
"Unknown type value '{}' on {}".format(t, outerHTML(el)),
f"Unknown type value '{t}' on {outerHTML(el)}",
el=el,
)
types.remove(t)
Expand All @@ -383,7 +381,7 @@ def addExplicitIndexes(doc):
specs = {x.strip() for x in el.get("data-link-spec").split(",")}
for s in list(specs):
if s not in doc.refs.specs:
die("Unknown spec name '{}' on {}".format(s, outerHTML(el)), el=el)
die(f"Unknown spec name '{s}' on {outerHTML(el)}", el=el)
specs.remove(s)
else:
specs = None
Expand All @@ -401,7 +399,7 @@ def addExplicitIndexes(doc):
export = False
else:
die(
"Unknown export value '{}' (should be boolish) on {}".format(exportVal, outerHTML(el)),
f"Unknown export value '{exportVal}' (should be boolish) on {outerHTML(el)}",
el=el,
)
export = None
Expand Down Expand Up @@ -599,8 +597,7 @@ def extractKeyValFromRow(row, table):
result = re.match(r"(.*):", textContent(row[0]).strip())
if result is None:
die(
"Propdef row headers must be a word followed by a colon. Got:\n{0}",
textContent(row[0]).strip(),
f"Propdef row headers must be a word followed by a colon. Got:\n{textContent(row[0]).strip()}",
el=table,
)
return "", ""
Expand Down Expand Up @@ -802,20 +799,14 @@ def addTOCSection(doc):
if isinstance(container, int):
# Saw a low-level heading without first seeing a higher heading.
die(
"Saw an <h{0}> without seeing an <h{1}> first. Please order your headings properly.\n{2}",
level,
level - 1,
outerHTML(header),
f"Saw an <h{level}> without seeing an <h{level-1}> first. Please order your headings properly.\n{outerHTML(header)}",
el=header,
)
return
if level > previousLevel + 1:
# Jumping two levels is a no-no.
die(
"Heading level jumps more than one level, from h{0} to h{1}:\n {2}",
previousLevel,
level,
textContent(header).replace("\n", " "),
f"Heading level jumps more than one level, from h{previousLevel} to h{level}:\n{outerHTML(el)}",
el=header,
)
return
Expand Down Expand Up @@ -920,8 +911,7 @@ def printTranslation(tr):
missingInfo = True
if missingInfo:
warn(
"Bikeshed doesn't have all the translation info for '{0}'. Please add to bikeshed/spec-data/readonly/languages.json and submit a PR!",
lang,
f"Bikeshed doesn't have all the translation info for '{lang}'. Please add to bikeshed/spec-data/readonly/languages.json and submit a PR!"
)
if nativeName:
return E.span(
Expand Down
12 changes: 4 additions & 8 deletions bikeshed/caniuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def addCanIUsePanels(doc):

featId = featId.lower()
if not doc.canIUse.hasFeature(featId):
die("Unrecognized Can I Use feature ID: {0}", featId, el=dfn)
die(f"Unrecognized Can I Use feature ID: {featId}", el=dfn)
feature = doc.canIUse.getFeature(featId)

addClass(dfn, "caniuse-paneled")
Expand All @@ -45,11 +45,7 @@ def addCanIUsePanels(doc):
)
dfnId = dfn.get("id")
if not dfnId:
die(
"Elements with `caniuse` attribute need to have an ID as well. Got:\n{0}",
serializeTag(dfn),
el=dfn,
)
die(f"Elements with `caniuse` attribute need to have an ID as well. Got:\n{serializeTag(dfn)}", el=dfn)
continue
panel.set("data-dfn-id", dfnId)
appendChild(doc.body, panel)
Expand Down Expand Up @@ -207,9 +203,9 @@ def validateCanIUseURLs(doc, elements):

unusedFeatures = urlFeatures - docFeatures
if unusedFeatures:
featureList = "\n".join(" * {0} - https://caniuse.com/#feat={0}".format(x) for x in sorted(unusedFeatures))
warn(
"The following Can I Use features are associated with your URLs, but don't show up in your spec:\n{0}",
"\n".join(" * {0} - https://caniuse.com/#feat={0}".format(x) for x in sorted(unusedFeatures)),
f"The following Can I Use features are associated with your URLs, but don't show up in your spec:\n{featureList}"
)


Expand Down
13 changes: 4 additions & 9 deletions bikeshed/config/retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ def boilerplatePath(*segs):
for f in (statusFile, genericFile):
if doc.inputSource.cheaplyExists(f):
warn(
(
"Found {0} next to the specification without a matching\n"
+ "Local Boilerplate: {1} yes\n"
+ "in the metadata. This include won't be found when building via a URL."
).format(f, name)
f"Found {f} next to the specification without a matching\n"
+ f"Local Boilerplate: {name} yes\n"
+ "in the metadata. This include won't be found when building via a URL."
)
# We should remove this after giving specs time to react to the warning:
sources.append(doc.inputSource.relative(f))
Expand All @@ -138,9 +136,6 @@ def boilerplatePath(*segs):
else:
if error:
die(
"Couldn't find an appropriate include file for the {0} inclusion, given group='{1}' and status='{2}'.",
name,
group,
status,
f"Couldn't find an appropriate include file for the {name} inclusion, given group='{group}' and status='{status}'."
)
return ""
22 changes: 6 additions & 16 deletions bikeshed/config/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def canonicalizeStatus(rawStatus, group):

def validateW3Cstatus(group, status, rawStatus):
if status == "DREAM":
warn("You used Status: DREAM for a W3C document." + " Consider UD instead.")
warn("You used Status: DREAM for a W3C document. Consider UD instead.")
return

if "w3c/" + status in shortToLongStatus:
Expand All @@ -304,25 +304,17 @@ def validateW3Cstatus(group, status, rawStatus):
def formatStatusSet(statuses):
return ", ".join(sorted({status.split("/")[-1] for status in statuses}))

msg = "You used Status: {0}, but {1} limited to these statuses: {2}."

if group in w3cIgs and status not in w3cIGStatuses:
warn(
msg,
rawStatus,
"W3C Interest Groups are",
formatStatusSet(w3cIGStatuses),
f"You used Status: {rawStatus}, but W3C Interest Groups are limited to these statuses: {formatStatusSet(w3cIGStatuses)}."
)

if group == "tag" and status not in w3cTAGStatuses:
warn(msg, rawStatus, "the TAG is", formatStatusSet(w3cTAGStatuses))

if group in w3cCgs and status not in w3cCommunityStatuses:
warn(
msg,
rawStatus,
"W3C Community and Business Groups are",
formatStatusSet(w3cCommunityStatuses),
f"You used Status: {rawStatus}, but W3C Community and Business Groups are limited to these statuses: {formatStatusSet(w3cCommunityStatuses)}."
)

def megaGroupsForStatus(status):
Expand Down Expand Up @@ -380,9 +372,7 @@ def megaGroupsForStatus(status):
)
else:
if len(possibleMgs) == 1:
msg += " That status can only be used with the org '{0}', like `Status: {0}/{1}`".format(
possibleMgs[0], status
)
msg += f" That status can only be used with the org '{possibleMgs[0]}', like `Status: {possibleMgs[0]}/{status}`"
else:
msg += " That status can only be used with the orgs {}.".format(
englishFromList(f"'{x}'" for x in possibleMgs)
Expand All @@ -393,7 +383,7 @@ def megaGroupsForStatus(status):
msg = f"Unknown Status metadata '{canonStatus}'. Check the docs for valid Status values."
else:
msg = f"Status '{status}' can't be used with the org '{megaGroup}'. Check the docs for valid Status values."
die("{0}", msg)
die(msg)
return canonStatus

# Otherwise, they provided a bare status.
Expand Down Expand Up @@ -425,7 +415,7 @@ def megaGroupsForStatus(status):
msg += ", and you don't have a Group metadata. Please declare your Group, or check the docs for statuses that can be used by anyone."
else:
msg = f"Unknown Status metadata '{canonStatus}'. Check the docs for valid Status values."
die("{0}", msg)
die(msg)
return canonStatus


Expand Down
Loading

0 comments on commit 368df1c

Please sign in to comment.