Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Aug 11, 2023
1 parent a31b827 commit 61febc3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bikeshed/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def addIndexOfLocallyDefinedTerms(doc: t.SpecT, container: t.ElementT) -> None:
h.appendChild(container, indexHTML, allowEmpty=True)


def disambiguator(ref: r.RefWrapper, types: set[str] | None, specs: set[str] | None) -> str:
def disambiguator(ref: r.RefWrapper, types: set[str] | None, specs: list[str] | None) -> str:
disambInfo = []
if types is None or len(types) > 1:
disambInfo.append(ref.type)
Expand Down
2 changes: 1 addition & 1 deletion bikeshed/h/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def foldWhitespace(text: str) -> str:


def sortElements(el: t.Iterable[t.ElementT]) -> list[t.ElementT]:
return list(sorted(el, key=lambda x:(x.get("bs-line-number", ""), textContent(x))))
return sorted(el, key=lambda x: (x.get("bs-line-number", ""), textContent(x)))


def parseHTML(text: str) -> list[t.ElementT]:
Expand Down
20 changes: 13 additions & 7 deletions bikeshed/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from . import constants, t

if t.TYPE_CHECKING:
import io

messages: set[str | tuple[str, str]]
messages = set()

Expand Down Expand Up @@ -122,9 +125,9 @@ def failure(msg: str) -> None:


def resetSeenMessages() -> None:
global messages # noqa: PLW0603
global messages
messages = set()
global messageCounts # noqa: PLW0603
global messageCounts
messageCounts = Counter()


Expand Down Expand Up @@ -228,13 +231,15 @@ def errorAndExit() -> None:


@contextlib.contextmanager
def messagesToFile(pathOrFh: str | io.TextIOWrapper, mode: str|None = None) -> t.Generator[io.TextIOWrapper, None, None]:
from . import constants
def messagesToFile(
pathOrFh: str | io.TextIOWrapper,
mode: str | None = None,
) -> t.Generator[io.TextIOWrapper, None, None]:
if mode is None:
mode = "plain"

if isinstance(pathOrFh, str):
fh = open(pathOrFh, 'w', encoding='utf-8')
fh = open(pathOrFh, "w", encoding="utf-8")
else:
fh = pathOrFh
global messageFh
Expand All @@ -254,12 +259,13 @@ def messagesToFile(pathOrFh: str | io.TextIOWrapper, mode: str|None = None) -> t
@contextlib.contextmanager
def messagesSilent() -> t.Generator[io.TextIOWrapper, None, None]:
import os
fh = open(os.devnull, 'w', encoding='utf-8')

fh = open(os.devnull, "w", encoding="utf-8")
global messageFh
oldMessageFh = messageFh
try:
messageFh = fh
yield fh
finally:
messageFh = oldMessageFh
fh.close()
fh.close()
15 changes: 6 additions & 9 deletions bikeshed/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import dataclasses
import difflib
import glob
import io
import os
import re
import sys

from alive_progress import alive_it

Expand Down Expand Up @@ -117,18 +115,17 @@ def runAllTests(
m.p(m.printColor("Serialization failed.", color="red"))
fails.append(testName)
continue
with open(replaceExtension(path, ".html"), 'r', encoding="utf-8") as golden:
with open(replaceExtension(path, ".html"), "r", encoding="utf-8") as golden:
goldenOutput = golden.read()
with open(replaceExtension(path, ".console.txt"), 'r', encoding="utf-8") as golden:
with open(replaceExtension(path, ".console.txt"), "r", encoding="utf-8") as golden:
goldenConsole = golden.read()
if compare(testOutput, goldenOutput) and compare(testConsole, goldenConsole):
numPassed += 1
else:
sys.exit(0)
fails.append(testName)
except Exception as e:
m.say(testName)
m.say(e)
print(testName) # noqa: T201
print(e) # noqa: T201
if numPassed == total:
m.p(m.printColor("✔ All tests passed.", color="green"))
return True
Expand All @@ -152,7 +149,7 @@ def processTest(
addTestMetadata(doc)
doc.preprocess()
except Exception as e:
print(f"Error running test {path}:\n {e}")
print(f"Error running test {path}:\n {e}") # noqa: T201
raise e
assert doc is not None
return doc
Expand Down Expand Up @@ -207,4 +204,4 @@ def addTestMetadata(doc: t.SpecT) -> None:
def replaceExtension(path: str, newExt: str) -> str:
assert newExt[0] == "."
trunk = os.path.splitext(path)[0]
return f"{trunk}{newExt}"
return f"{trunk}{newExt}"
2 changes: 1 addition & 1 deletion bikeshed/unsortedJunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ def processIDL(doc: t.SpecT) -> None:
localDfns.update(idl.markupIDLBlock(pre, doc))

dfns = h.findAll("pre.idl:not([data-no-idl]) dfn, xmp.idl:not([data-no-idl]) dfn", doc) + list(localDfns)
dfns = sorted(dfns, key=lambda x:(x.get("bs-line-number") or "", h.textContent(x)))
dfns = sorted(dfns, key=lambda x: (x.get("bs-line-number") or "", h.textContent(x)))
classifyDfns(doc, dfns)
h.fixupIDs(doc, dfns)
doc.refs.addLocalDfns(doc, (dfn for dfn in dfns if dfn.get("id") is not None))
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ select = [
"bikeshed/__init__.py" = ["E402", "T201"]
"bikeshed/cli.py" = ["S102"]
"bikeshed/extensions.py" = ["S102"]
"bikeshed/messages.py" = ["T201"]
"bikeshed/messages.py" = ["T201", "SIM115", "PLW0603"]

[tool.ruff.flake8-implicit-str-concat]
allow-multiline = false

0 comments on commit 61febc3

Please sign in to comment.