Skip to content

Commit

Permalink
Merge branch 'speced:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr authored Sep 9, 2024
2 parents 9da91bb + 880b32e commit 07252a6
Show file tree
Hide file tree
Showing 2,639 changed files with 456,704 additions and 137,655 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: psf/black@24.2.0
- uses: psf/black@24.8.0
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyGithub==2.2.0
PyGithub==2.3.0
26 changes: 19 additions & 7 deletions bikeshed/Spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
constants,
datablocks,
dfns,
doctypes,
extensions,
fingerprinting,
h,
Expand Down Expand Up @@ -108,6 +109,7 @@ def initializeState(self) -> bool:
self.widl: widlparser.Parser = idl.getParser()

self.languages: dict[str, language.Language] = fetchLanguages(self.dataFile)
self.doctypes: doctypes.DoctypeManager = fetchDoctypes(self.dataFile)

self.extraJC = stylescript.JCManager()
self.extraJC.addColors()
Expand Down Expand Up @@ -141,21 +143,27 @@ def initMetadata(self, inputContent: InputSource.InputContent) -> None:
# in a markdown code span or an <xmp> to show off.
_, self.mdDocument = metadata.parse(lines=inputContent.lines)

# Combine the data so far...
# Combine the data so far, and compute the doctype
# (the other md sources need the doctype in order to be found)
self.md = metadata.join(self.mdBaseline, self.mdDocument, self.mdCommandLine)
rawDoctype = (self.md.rawOrg, self.md.rawGroup, self.md.rawStatus)
self.doctype = self.doctypes.getDoctype(self.md.rawOrg, self.md.rawGroup, self.md.rawStatus)

# Using that to determine the Group and Status, load the correct defaults.include boilerplate
self.mdDefaults = metadata.fromJson(
data=retrieve.retrieveBoilerplateFile(self, "defaults", error=True),
data=retrieve.retrieveBoilerplateFile(self, "defaults"),
source="defaults",
)
self.md = metadata.join(self.mdBaseline, self.mdDefaults, self.mdDocument, self.mdCommandLine)
if rawDoctype != (self.md.rawOrg, self.md.rawGroup, self.md.rawStatus):
# recompute doctype
self.doctype = self.doctypes.getDoctype(self.md.rawOrg, self.md.rawGroup, self.md.rawStatus)

# Using all of that, load up the text macros so I can sub them into the computed-metadata file.
self.md.fillTextMacros(self.macros, doc=self)
jsonEscapedMacros = {k: json.dumps(v)[1:-1] for k, v in self.macros.items()}

computedMdText = h.replaceMacrosTextly(
retrieve.retrieveBoilerplateFile(self, "computed-metadata", error=True),
retrieve.retrieveBoilerplateFile(self, "computed-metadata"),
macros=jsonEscapedMacros,
context="? of computed-metadata.include",
)
Expand All @@ -173,7 +181,7 @@ def initMetadata(self, inputContent: InputSource.InputContent) -> None:
# And compute macros again, in case the preceding steps changed them.
self.md.fillTextMacros(self.macros, doc=self)

self.md.validate()
self.md.validate(doc=self)
m.retroactivelyCheckErrorLevel()

def earlyParse(self, inputContent: InputSource.InputContent) -> list[l.Line]:
Expand Down Expand Up @@ -231,7 +239,7 @@ def assembleDocument(self) -> Spec:
features=markdownFeatures,
)

self.refs.setSpecData(self.md)
self.refs.setSpecData(self)

# Convert to a single string of html now, for convenience.
self.html = "".join(x.text for x in self.lines)
Expand Down Expand Up @@ -482,7 +490,7 @@ def printTargets(self) -> None:
def isOpaqueElement(self, el: t.ElementT) -> bool:
if el.tag in self.md.opaqueElements:
return True
if el.get("data-opaque") is not None or el.get("bs-opaque") is not None:
if el.get("data-opaque") is not None or el.get("bs-opaque") is not None: # noqa needless-bool
return True
return False

Expand Down Expand Up @@ -554,6 +562,10 @@ def fetchLanguages(dataFile: retrieve.DataFileRequester) -> dict[str, language.L
}


def fetchDoctypes(dataFile: retrieve.DataFileRequester) -> doctypes.DoctypeManager:
return doctypes.DoctypeManager.fromKdlStr(dataFile.fetch("boilerplate", "doctypes.kdl", str=True))


def addDomintroStyles(doc: Spec) -> None:
# Adds common WHATWG styles for domintro blocks.

Expand Down
6 changes: 3 additions & 3 deletions bikeshed/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def getFillContainer(tag: str, doc: t.SpecT, default: bool = False) -> t.Element

# Otherwise, append to the end of the document,
# unless you're in the byos group
if doc.md.group == "byos":
if doc.doctype.group.name == "BYOS":
return None
if default:
return doc.body
Expand Down Expand Up @@ -240,7 +240,7 @@ def removeUnwantedBoilerplate(doc: t.SpecT) -> None:


def w3cStylesheetInUse(doc: t.SpecT) -> bool:
return doc.md.prepTR or doc.md.status in config.snapshotStatuses
return doc.md.prepTR or doc.doctype.group.name == "W3C"


def addBikeshedBoilerplate(doc: t.SpecT) -> None:
Expand Down Expand Up @@ -933,7 +933,7 @@ def printPreviousVersion(v: dict[str, str]) -> t.ElementT | None:
md.setdefault("This version", []).append(h.E.a({"href": mac["version"], "class": "u-url"}, mac["version"]))
if doc.md.TR:
md.setdefault("Latest published version", []).append(h.E.a({"href": doc.md.TR}, doc.md.TR))
if doc.md.ED and doc.md.status in config.snapshotStatuses:
if doc.md.ED and "TR" in doc.doctype.status.requires:
md.setdefault("Editor's Draft", []).append(h.E.a({"href": doc.md.ED}, doc.md.ED))
if doc.md.previousVersions:
md["Previous Versions"] = [printPreviousVersion(ver) for ver in doc.md.previousVersions]
Expand Down
8 changes: 4 additions & 4 deletions bikeshed/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,12 @@ def handleProfile(options: argparse.Namespace) -> None:
root = f'--root="{options.root}"' if options.root else ""
leaf = f'--leaf="{options.leaf}"' if options.leaf else ""
if options.svgFile:
os.system(
f"time python -m cProfile -o stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} stat.prof | dot -Tsvg -o {options.svgFile} && rm stat.prof", # noqa: S605
os.system( # noqa s605
f"time python -m cProfile -o stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} stat.prof | dot -Tsvg -o {options.svgFile} && rm stat.prof",
)
else:
os.system(
f"time python -m cProfile -o /tmp/stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} /tmp/stat.prof | xdot &", # noqa: S605
os.system( # noqa s605
f"time python -m cProfile -o /tmp/stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} /tmp/stat.prof | xdot &",
)


Expand Down
4 changes: 2 additions & 2 deletions bikeshed/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dataclasses
import re

from . import config, h, t
from . import h, t
from . import messages as m

# Any element can have an include-if or exclude-if attribute,
Expand Down Expand Up @@ -61,7 +61,7 @@ def processConditionals(doc: t.SpecT, container: t.ElementT | None = None) -> No
def evalConditions(doc: t.SpecT, el: t.ElementT, conditionString: str) -> t.Generator[bool, None, None]:
for cond in parseConditions(conditionString, el):
if cond.type == "status":
yield config.looselyMatch(cond.value, doc.md.status)
yield doc.doctype.status.looselyMatch(cond.value)
elif cond.type == "text macro":
for k in doc.macros:
if k.upper() == cond.value:
Expand Down
20 changes: 0 additions & 20 deletions bikeshed/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,3 @@
simplifyText,
splitForValues,
)
from .status import (
canonicalizeStatus,
datedStatuses,
deadlineStatuses,
implementationStatuses,
looselyMatch,
megaGroups,
noEDStatuses,
shortToLongStatus,
snapshotStatuses,
splitStatus,
unlevelledStatuses,
w3cCgs,
w3cCommunityStatuses,
w3cIgs,
w3cIGStatuses,
w3cProcessDocumentStatuses,
w3cTAGStatuses,
w3cWGStatuses,
)
1 change: 1 addition & 0 deletions bikeshed/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
def englishFromList(items: t.Iterable[str], conjunction: str = "or") -> str:
# Format a list of strings into an English list.
items = list(items)
assert len(items) > 0
if len(items) == 1:
return items[0]
if len(items) == 2:
Expand Down
Loading

0 comments on commit 07252a6

Please sign in to comment.