From 31fa53e97645fc034bba1f0acc2bb29781a9820c Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Thu, 4 Apr 2024 13:45:09 -0400 Subject: [PATCH] feat: better warning messages --- lib/mccole/extensions/hooks.py | 6 ++++++ lib/mccole/extensions/inclusions.py | 13 ++++++++----- lib/mccole/extensions/termdefs.py | 3 +-- lib/mccole/extensions/util.py | 7 ++++++- lib/mccole/resources/mccole.css | 2 +- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/mccole/extensions/hooks.py b/lib/mccole/extensions/hooks.py index 3e1e789..fa89608 100644 --- a/lib/mccole/extensions/hooks.py +++ b/lib/mccole/extensions/hooks.py @@ -2,10 +2,16 @@ import ark +EXCLUSIONS = { + "__pycache__", +} + @ark.filters.register(ark.filters.Filter.LOAD_NODE_DIR) def keep_dir(value, path): """Do not process directories excluded by parent.""" + if path.name in EXCLUSIONS: + return False path = str(path).replace(ark.site.src(), "").lstrip("/") return not any(path.startswith(x) for x in ark.site.config["exclude"]) diff --git a/lib/mccole/extensions/inclusions.py b/lib/mccole/extensions/inclusions.py index f9a3290..e237e68 100644 --- a/lib/mccole/extensions/inclusions.py +++ b/lib/mccole/extensions/inclusions.py @@ -46,9 +46,9 @@ def inclusion(pargs, kwargs, node): if not kwargs: body = _whole(path) elif "pattern" in kwargs: - body = _match(path, kwargs["pattern"], indent) + body = _match(node, path, kwargs["pattern"], indent) elif "mark" in kwargs: - body = _extract(path, kwargs["mark"], indent) + body = _extract(node, path, kwargs["mark"], indent) else: util.fail(f"Badly-formed inclusion for '{path}' in {node} with '{kwargs}'") body = f"```{kind}\n{body}\n```\n" @@ -58,7 +58,7 @@ def inclusion(pargs, kwargs, node): util.fail(f"Unable to read inclusion '{path}' in {node}.") -def _extract(filepath, mark, indent): +def _extract(node, filepath, mark, indent): """Extract portion of file in comment markers.""" if isinstance(filepath, str): filepath = Path(filepath) @@ -74,12 +74,14 @@ def _extract(filepath, mark, indent): text = text.split(before)[1].split(after)[0] elif before_in or after_in: util.fail( - f"Mis-matched mark with '{mark}' in {filename} in {node.path}" + f"Mis-matched mark in {node.path}: '{mark}' in '{filepath}'" ) + else: + util.warn(f"No mark in {node.slug}: '{mark}' in '{filepath}'") return text -def _match(filepath, pattern, indent): +def _match(node, filepath, pattern, indent): """Match a pattern against the contents of a file.""" if isinstance(filepath, str): filepath = Path(filepath) @@ -87,6 +89,7 @@ def _match(filepath, pattern, indent): matchers = _translate_pattern(pattern) node = _match_rec(doc, matchers) if not node: + util.warn(f"Failed to match inclusion pattern in {node.path}: '{filepath}' and '{pattern}'") return None result = unparse(node) if indent: diff --git a/lib/mccole/extensions/termdefs.py b/lib/mccole/extensions/termdefs.py index aced907..c802c39 100644 --- a/lib/mccole/extensions/termdefs.py +++ b/lib/mccole/extensions/termdefs.py @@ -2,7 +2,6 @@ import ark import ibis -import sys from glossary import glossary_ref import util @@ -28,5 +27,5 @@ def _make_ref(node, glossary, lang, key): try: return glossary_ref([key, glossary[key][lang]["term"]], {}, node) except KeyError: - print(f"Unknown glossary key {key} in {node.slug}", file=sys.stderr) + util.warn(f"Unknown glossary key {key} in {node.slug}") return None diff --git a/lib/mccole/extensions/util.py b/lib/mccole/extensions/util.py index 59e0ffd..51e7bdd 100644 --- a/lib/mccole/extensions/util.py +++ b/lib/mccole/extensions/util.py @@ -48,7 +48,7 @@ def ensure_links(): def fail(msg): """Fail unilaterally.""" - print(msg, file=sys.stderr) + warn(msg) raise AssertionError(msg) @@ -96,3 +96,8 @@ def require_file(node, filename, kind): """Require that a file exists.""" filepath = Path(Path(node.filepath).parent, filename) require(filepath.exists(), f"Missing {kind} file {filename} from {node.path}") + + +def warn(msg): + """Print warning message.""" + print(msg, file=sys.stderr) diff --git a/lib/mccole/resources/mccole.css b/lib/mccole/resources/mccole.css index 7507dce..389eba9 100644 --- a/lib/mccole/resources/mccole.css +++ b/lib/mccole/resources/mccole.css @@ -34,7 +34,7 @@ /* Font sizings */ --size-body: large; - --size-code: 90%; + --size-code: 80%; --size-subtitle: x-large; /* Spacings */