From 689cb3da01cd22a4932bc47dece8fb3f2285354d Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:31:53 -0500 Subject: [PATCH 001/161] Add experimental Quarto 2 support --- great_docs/_build/freeze.py | 2 +- great_docs/_build/quarto.py | 115 +++++++++++++++++++++++++++++++++--- great_docs/_build/render.py | 4 ++ great_docs/_build/watch.py | 5 +- 4 files changed, 115 insertions(+), 11 deletions(-) diff --git a/great_docs/_build/freeze.py b/great_docs/_build/freeze.py index 94aad3b94..4ab772d35 100644 --- a/great_docs/_build/freeze.py +++ b/great_docs/_build/freeze.py @@ -112,7 +112,7 @@ def render_page(config: Config, build_dir: Path, page: Path) -> subprocess.Compl Quarto's exit status and captured output. """ return subprocess.run( - ["quarto", "render", str(page.relative_to(build_dir))], + [quarto.executable(), "render", str(page.relative_to(build_dir))], cwd=build_dir, env=quarto.environment(config), capture_output=True, diff --git a/great_docs/_build/quarto.py b/great_docs/_build/quarto.py index 9c99d83a0..e17553ec6 100644 --- a/great_docs/_build/quarto.py +++ b/great_docs/_build/quarto.py @@ -4,6 +4,10 @@ Every command that runs Quarto first calls `ensure_installed`. A render runs in the Quarto project's directory with the environment from `environment`, and reports the pages Quarto starts, its warnings and how long each page took. + +Setting `GREAT_DOCS_QUARTO` to `q2`, or to the path of a `q2` binary, renders and previews +with Quarto 2 instead (experimental). Quarto 2 reports no per-page progress, so a render +reports its pages when it ends. """ from __future__ import annotations @@ -28,6 +32,7 @@ from ..config import Config __all__ = [ + "EXECUTABLE_ENV", "MIN_VERSION", "Progress", "QuartoNotFoundError", @@ -35,17 +40,26 @@ "RenderResult", "ensure_installed", "environment", + "executable", "installed_version", + "is_q2", "is_transient_error", "page_timings", "parse_progress", "render", ] +EXECUTABLE_ENV = "GREAT_DOCS_QUARTO" +"""The environment variable that names the Quarto command, `quarto` when unset""" + # The bundled extensions set the stage at which their filters run, which # Quarto's extension schema accepts from this release MIN_VERSION = (1, 9, 18) +# Quarto 2 has its own version numbers. No release is known to render a great-docs +# site completely; this is the first one tried. +Q2_MIN_VERSION = (0, 45, 0) + # Quarto can fail while copying output in large projects when one process renames # a file as another removes it. A retry can succeed after the filesystem race ends. _TRANSIENT_ERRORS = ("No such file or directory", "renameSync", "os error 2") @@ -53,6 +67,14 @@ _PROGRESS = re.compile(r"\[\s*(\d+)/(\d+)\]\s+(.+)") _ANSI = re.compile(r"\033\[[0-9;]*m") +# Quarto 2 prints `q2 (quarto 2) 0.45.0`; with `-v` it logs each output once rendering +# ends, and closes with `Rendered 3 of 4 files to ...` +_Q2_VERSION = re.compile(r"\(quarto 2\)\s*(\d+(?:\.\d+)*)", re.IGNORECASE) +_Q2_OUTPUT = re.compile(r"\bINFO\b.*\bOutput: (.+)$") +_Q2_RENDERED = re.compile(r"^Rendered (\d+) of (\d+) files") +# Warnings read `Warning [Q-11-7]: ...`, or `Warning: ...` without a code +_Q2_WARNING = re.compile(r"^Warning:?\s*(?:\[(Q-[\d-]+)\])?:?\s*(.*)$") + class QuartoNotFoundError(BuildError): """A missing Quarto CLI""" @@ -62,18 +84,44 @@ class QuartoVersionError(BuildError): """An installed Quarto CLI older than great-docs supports""" +def executable() -> str: + """ + Return the Quarto command that renders and previews sites + + Returns + ------- + : + The value of `GREAT_DOCS_QUARTO`, or `quarto` when it is unset or empty. + """ + return os.environ.get(EXECUTABLE_ENV, "").strip() or "quarto" + + +def is_q2() -> bool: + """ + Whether great-docs renders with Quarto 2 + + Returns + ------- + : + Whether the Quarto command is a `q2` binary, by its file name. + """ + name = os.path.basename(executable()).lower() + return name == "q2" or name.startswith(("q2.", "q2-")) + + def installed_version() -> tuple[int, ...] | None: """ - Read the version of the Quarto CLI on the `PATH` + Read the version of the Quarto CLI that great-docs runs Returns ------- : The version components, or `None` if Quarto fails to report a recognisable version. + Quarto 2 reports its own version numbers, which start at 0. """ try: proc = subprocess.run( - ["quarto", "--version"], + [executable(), "--version"], capture_output=True, timeout=30, check=True, @@ -81,7 +129,7 @@ def installed_version() -> tuple[int, ...] | None: ) except (OSError, subprocess.SubprocessError): return None - match = re.match(r"\s*(\d+(?:\.\d+)*)", proc.stdout) + match = _Q2_VERSION.search(proc.stdout) or re.match(r"\s*(\d+(?:\.\d+)*)", proc.stdout) return tuple(int(part) for part in match.group(1).split(".")) if match else None @@ -96,9 +144,15 @@ def ensure_installed() -> None: QuartoNotFoundError If Quarto is not on the `PATH`. QuartoVersionError - If Quarto is older than `MIN_VERSION`. + If Quarto is older than `MIN_VERSION`, or Quarto 2 older than `Q2_MIN_VERSION`. """ - if shutil.which("quarto") is None: + if shutil.which(executable()) is None: + if is_q2(): + raise QuartoNotFoundError( + f"Quarto 2 was not found: {EXECUTABLE_ENV} is {executable()!r}, which is not " + "an executable on the PATH. Set it to the path of a q2 binary, or unset it " + "to render with Quarto 1." + ) raise QuartoNotFoundError( "Quarto was not found on your system. Quarto is a system-level " "dependency of great-docs and is not bundled with the Python package.\n\n" @@ -107,11 +161,12 @@ def ensure_installed() -> None: "Or fetch the binary programmatically by using your OS package (brew, yum, winget)." ) version = installed_version() - if version is not None and version < MIN_VERSION: + minimum, product = (Q2_MIN_VERSION, "Quarto 2") if is_q2() else (MIN_VERSION, "Quarto") + if version is not None and version < minimum: found = ".".join(map(str, version)) - required = ".".join(map(str, MIN_VERSION)) + required = ".".join(map(str, minimum)) raise QuartoVersionError( - f"great-docs requires Quarto {required} or later, but found Quarto {found}. " + f"great-docs requires {product} {required} or later, but found {product} {found}. " "Upgrade Quarto from https://quarto.org/docs/get-started/" ) @@ -154,6 +209,12 @@ def environment(config: Config) -> dict[str, str]: env["PYTHONPATH"] = os.pathsep.join([*package_dirs, existing] if existing else package_dirs) _ = env.setdefault("PYTHONUTF8", "1") + + # Quarto 2 ignores `QUARTO_PYTHON` and runs whichever `jupyter` and `python3` the + # `PATH` finds first, so put the chosen Python's scripts directory first + if is_q2(): + scripts = os.path.dirname(env["QUARTO_PYTHON"]) + env["PATH"] = os.pathsep.join([scripts, env.get("PATH", "")]) return env @@ -267,6 +328,10 @@ def render( Report page starts and warnings through callbacks, and discard other output. Keep standard error in the result. Callbacks run on two threads, one per output stream. + Quarto 2 names its pages only once it has rendered them all, so `on_page` then runs for + every page at the end and the result has no page timings. Its warnings reach + `on_warning` once per warning code, with a count. + Parameters ---------- project @@ -288,8 +353,12 @@ def render( OSError If Quarto cannot be started. """ + q2 = is_q2() + command = [executable(), "render"] + if q2: + command += ["-v", "--color", "never"] process = subprocess.Popen( - ["quarto", "render"], + command, cwd=project, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -299,8 +368,35 @@ def render( ) stamps: list[tuple[str, float]] = [] stderr: list[str] = [] + q2_outputs: list[str] = [] + q2_warnings: dict[str, list[str]] = {} + + def report_q2_warnings() -> None: + if on_warning is not None: + for warnings in q2_warnings.values(): + more = f" (and {len(warnings) - 1} more like it)" if len(warnings) > 1 else "" + on_warning(f"WARN {warnings[0]}{more}") + q2_warnings.clear() + + def handle_q2(line: str) -> None: + plain = _ANSI.sub("", line).strip() + output = _Q2_OUTPUT.search(plain) + if output is not None: + q2_outputs.append(os.path.relpath(output.group(1).strip(), project)) + elif warning := _Q2_WARNING.match(plain): + code, message = warning.group(1) or "", warning.group(2).strip() + q2_warnings.setdefault(code, []).append(f"[{code}] {message}" if code else message) + elif _Q2_RENDERED.match(plain): + # Report warnings first: a caller may stop taking them after the last page + report_q2_warnings() + for current, page in enumerate(q2_outputs, 1): + if on_page is not None: + on_page(Progress(current, len(q2_outputs), page)) def handle(line: str) -> None: + if q2: + handle_q2(line) + return progress = parse_progress(line) if progress is not None: stamps.append((progress.page, time.monotonic())) @@ -324,4 +420,5 @@ def read_stderr() -> None: handle(line) _ = process.wait() reader.join(timeout=5) + report_q2_warnings() return RenderResult(process.returncode, "".join(stderr), page_timings(stamps, time.monotonic())) diff --git a/great_docs/_build/render.py b/great_docs/_build/render.py index 2fd957842..2cfa11b21 100644 --- a/great_docs/_build/render.py +++ b/great_docs/_build/render.py @@ -106,6 +106,10 @@ def site( env = quarto.environment(config) result: quarto.RenderResult | parallel_render.RenderResult | None = None render_stats: dict[str, object] | None = None + if jobs > 1 and quarto.is_q2(): + # Quarto 2 renders pages in parallel itself, and has no `inspect` to plan a split + log.detail("Rendering in one process: Quarto 2 renders pages in parallel itself") + jobs = 1 if jobs > 1: # Experimental: split the pages among several Quarto processes bar = log.progress("Rendering pages", 1) diff --git a/great_docs/_build/watch.py b/great_docs/_build/watch.py index 092aed5d7..1cec22de2 100644 --- a/great_docs/_build/watch.py +++ b/great_docs/_build/watch.py @@ -23,6 +23,7 @@ import watchfiles from .._project.layout import Layout +from . import quarto from .steps import BuildError if TYPE_CHECKING: @@ -127,7 +128,9 @@ def serve( staging = stage(layout) published = _digests(layout.build_dir) stopped = threading.Event() - preview = subprocess.Popen(["quarto", "preview", "--no-browser"], cwd=layout.build_dir, env=env) + preview = subprocess.Popen( + [quarto.executable(), "preview", "--no-browser"], cwd=layout.build_dir, env=env + ) def wait_for_preview() -> None: _ = preview.wait() From a8fb3916ecfc9442190b19eb495692e1bae9fd45 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:32:07 -0500 Subject: [PATCH 002/161] Escape markup in parameter names --- great_docs/_apiref/_render/doc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/great_docs/_apiref/_render/doc.py b/great_docs/_apiref/_render/doc.py index 0ef8f8429..07ec1ac24 100644 --- a/great_docs/_apiref/_render/doc.py +++ b/great_docs/_apiref/_render/doc.py @@ -46,6 +46,7 @@ render_formatted_expr, repr_obj, ) +from .._signature import escape_signature_markup from ._section_dispatch import SECTION_METHOD from .base import RenderBase @@ -356,7 +357,8 @@ def render_variable_definition( items: list[InlineContentItem] = [] if name: - items.append(Span(name, Attr(classes=["doc-parameter-name"]))) + # Escape `**kwargs` and `global_`: Quarto 2 reads them as unclosed emphasis + items.append(Span(escape_signature_markup(name), Attr(classes=["doc-parameter-name"]))) if annotation: if isinstance(annotation, gf.Expr): From 6146decd5b2dfa9de7ca9d4ea4b2f681a29d786a Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:32:21 -0500 Subject: [PATCH 003/161] Use resolved Quarto executable for rendering --- great_docs/_checks/examples.py | 2 +- great_docs/_term_player/editor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/great_docs/_checks/examples.py b/great_docs/_checks/examples.py index b38015630..673cbc643 100644 --- a/great_docs/_checks/examples.py +++ b/great_docs/_checks/examples.py @@ -480,7 +480,7 @@ def _render_page_with_quarto( try: proc = subprocess.run( [ - "quarto", + quarto.executable(), "render", str(tmp_qmd), "--to", diff --git a/great_docs/_term_player/editor.py b/great_docs/_term_player/editor.py index c955aaada..e5a4399e8 100644 --- a/great_docs/_term_player/editor.py +++ b/great_docs/_term_player/editor.py @@ -523,7 +523,7 @@ def _generate_preview_html(editor_data: dict, script_data: dict) -> str: # Run Quarto render result = subprocess.run( - ["quarto", "render", "preview.qmd", "--quiet"], + [quarto.executable(), "render", "preview.qmd", "--quiet"], cwd=str(tmp_dir), capture_output=True, **TEXT_MODE_KWARGS, From 6070b7b6ca8148be9caf8b7e0fc19fb0670dc595 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:32:34 -0500 Subject: [PATCH 004/161] Adapt render globs for Quarto 2 --- great_docs/_website/quarto_yml.py | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/great_docs/_website/quarto_yml.py b/great_docs/_website/quarto_yml.py index be61121aa..3600c1d2d 100644 --- a/great_docs/_website/quarto_yml.py +++ b/great_docs/_website/quarto_yml.py @@ -13,6 +13,7 @@ from yaml12 import parse_yaml, write_yaml +from .._build import quarto from .._build.ownership import QUARTO_YML_HEADER from . import inline_data from .navigation import navbar as nav_navbar @@ -90,11 +91,46 @@ def write(build_dir: Path, quarto_config: dict[str, Any]) -> None: ordered = {key: value for key, value in quarto_config.items() if key != "api-reference"} if "api-reference" in quarto_config: ordered["api-reference"] = quarto_config["api-reference"] + if quarto.is_q2(): + ordered = _q2_render_globs(ordered) with open(path(build_dir), "w", encoding="utf-8") as f: _ = f.write(QUARTO_YML_HEADER) write_yaml(ordered, f) +def _q2_render_globs(quarto_config: dict[str, Any]) -> dict[str, Any]: + """ + Rewrite `RENDER_GLOBS` in the render list for Quarto 2 + + Quarto 2's `*` matches in the project directory only, so each glob becomes a recursive + one. Quarto 2 renders `.qmd`, `.md` and `.ipynb` files only, and warns about globs that + match nothing, so drop the others. + + Parameters + ---------- + quarto_config + The configuration, which is not changed. + + Returns + ------- + : + The configuration, copied where the render list changes. + """ + project: Any = quarto_config.get("project") + if not isinstance(project, dict): + return quarto_config + project = cast("dict[str, Any]", project) + render = project.get("render") + if not isinstance(render, list): + return quarto_config + globs = [ + f"**/{entry}" if entry in ("*.qmd", "*.md", "*.ipynb") else entry + for entry in cast("list[Any]", render) + if entry not in RENDER_GLOBS or entry in ("*.qmd", "*.md", "*.ipynb") + ] + return {**quarto_config, "project": {**project, "render": globs}} + + def write_initial(build_dir: Path) -> dict[str, Any]: """ Write the initial website configuration From 3f8965012639ee3e46087438f860906ede0a6d5a Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:32:54 -0500 Subject: [PATCH 005/161] Make Lua extensions compatible with Quarto 2 --- .../_extensions/color-swatch/color-swatch.lua | 73 +++++++++++-------- .../assets/_extensions/details/details.lua | 55 ++++++++++---- .../_extensions/evolution/evolution.lua | 64 ++++++++++------ great_docs/assets/_extensions/icon/icon.lua | 59 ++++++++++----- .../markdown-pages/markdown-pages.lua | 9 ++- .../_extensions/tbl-explorer/tbl-explorer.lua | 62 ++++++++++------ .../_extensions/tbl-preview/tbl-preview.lua | 64 ++++++++++------ 7 files changed, 254 insertions(+), 132 deletions(-) diff --git a/great_docs/assets/_extensions/color-swatch/color-swatch.lua b/great_docs/assets/_extensions/color-swatch/color-swatch.lua index ac7a170c0..43cddf4ea 100644 --- a/great_docs/assets/_extensions/color-swatch/color-swatch.lua +++ b/great_docs/assets/_extensions/color-swatch/color-swatch.lua @@ -20,11 +20,48 @@ local function kwarg_str(kwargs, key) return s or "" end +--- Return the directory holding this script, ending in a slash. +--- +--- Quarto 2 omits Lua's `debug` library, so resolve a path against the +--- extension's directory instead. +local function script_dir() + if debug then + return debug.getinfo(1, "S").source:match("@?(.*/)") or "./" + end + return (quarto.utils.resolve_path("x"):gsub("x$", "")) +end + +--- Run a helper command without a shell. +--- +--- Use `pandoc.system.command` where Pandoc has it: under Quarto 2, `io.popen` +--- can deadlock when shortcodes run on parallel threads. +---@param cmd_args string[] The command and its arguments. +---@return boolean Whether the command exited successfully. +---@return string Its standard output followed by its standard error. +local function run_helper(cmd_args) + if pandoc.system.command then + local ok, status, out, err = pcall( + pandoc.system.command, cmd_args[1], { table.unpack(cmd_args, 2) }, "" + ) + if not ok then return false, tostring(status) end + return status == false, (out or "") .. (err or "") + end + local parts = {} + for _, arg in ipairs(cmd_args) do + local escaped = arg:gsub("'", "'\\''") + table.insert(parts, "'" .. escaped .. "'") + end + local handle = io.popen(table.concat(parts, " ") .. " 2>&1") + if not handle then return false, "" end + local result = handle:read("*a") + return handle:close() == true, result +end + return { ["color-swatch"] = function(args, kwargs, blocks) -- Locate the helper script (lives alongside this .lua file) - local script_dir = debug.getinfo(1, "S").source:match("@?(.*/)") or "./" - local helper = script_dir .. "_color_swatch_shortcode.py" + local here = script_dir() + local helper = here .. "_color_swatch_shortcode.py" -- Build CLI arguments local cmd_args = { "python3", helper } @@ -62,7 +99,7 @@ return { -- Resolve --file relative to the Quarto project root local file_val = kwarg_str(kwargs, "file") if file_val ~= "" and file_val:sub(1, 1) ~= "/" then - local project_root = script_dir .. "../../" + local project_root = here .. "../../" -- Replace the already-inserted value for i, arg in ipairs(cmd_args) do if arg == "--file" and cmd_args[i + 1] == file_val then @@ -75,35 +112,7 @@ return { -- Note: Quarto shortcodes do not support paired (body) content. -- The third parameter is `meta` (document metadata), not `blocks`. -- Custom colors are supplied via the `file` parameter instead. - local body = "" - - -- Build shell command: pipe body via echo into the helper - local parts = {} - for _, arg in ipairs(cmd_args) do - local escaped = arg:gsub("'", "'\\''") - table.insert(parts, "'" .. escaped .. "'") - end - local cmd_str = table.concat(parts, " ") - - local cmd - if body ~= "" then - -- Pipe the YAML body via a here-document to avoid shell escaping issues - local body_escaped = body:gsub("'", "'\\''") - cmd = "printf '%s' '" .. body_escaped .. "' | " .. cmd_str .. " 2>&1" - else - cmd = cmd_str .. " 2>&1" - end - - local handle = io.popen(cmd) - if not handle then - return pandoc.RawBlock( - "html", - "" - ) - end - - local result = handle:read("*a") - local success = handle:close() + local success, result = run_helper(cmd_args) if not success or result == "" then local msg = result ~= "" and result or "unknown error" diff --git a/great_docs/assets/_extensions/details/details.lua b/great_docs/assets/_extensions/details/details.lua index a6a4e1fab..9e9bf8642 100644 --- a/great_docs/assets/_extensions/details/details.lua +++ b/great_docs/assets/_extensions/details/details.lua @@ -68,26 +68,53 @@ local TYPE_ICONS = { danger = "ban", } +--- Return the directory holding this script, ending in a slash. +--- +--- Quarto 2 omits Lua's `debug` library, so read the filter's path from +--- `PANDOC_SCRIPT_FILE` instead. +local function script_dir() + if debug then + return debug.getinfo(1, "S").source:match("@?(.*/)") or "./" + end + return (PANDOC_SCRIPT_FILE or ""):match("(.*/)") or "./" +end + +--- Run a helper command without a shell and return its standard output. +--- +--- Use `pandoc.system.command` where Pandoc has it: under Quarto 2, `io.popen` +--- can deadlock when filters run on parallel threads. +---@param cmd_args string[] The command and its arguments. +---@return string The output, or an empty string if the command failed. +local function run_helper(cmd_args) + if pandoc.system.command then + local ok, status, out = pcall( + pandoc.system.command, cmd_args[1], { table.unpack(cmd_args, 2) }, "" + ) + if not ok or status ~= false then return "" end + return out or "" + end + local parts = {} + for _, arg in ipairs(cmd_args) do + local escaped = arg:gsub("'", "'\\''") + table.insert(parts, "'" .. escaped .. "'") + end + local handle = io.popen(table.concat(parts, " ") .. " 2>/dev/null") + if not handle then return "" end + local result = handle:read("*a") + if handle:close() ~= true then return "" end + return result +end + --- Render a Lucide icon SVG by calling the icon helper script. --- Returns the SVG HTML string, or empty string on failure. local function render_icon(icon_name) if icon_name == "" then return "" end -- Locate the icon helper script in the sibling extension directory - local script_dir = debug.getinfo(1, "S").source:match("@?(.*/)") or "./" - local helper = script_dir .. "../icon/_icon_shortcode.py" - - local cmd = "python3 '" .. - helper .. "' '" .. icon_name:gsub("'", "'\\''") .. - "' --size 16 --class gd-details-icon 2>/dev/null" - local handle = io.popen(cmd) - if not handle then return "" end - - local result = handle:read("*a") - local success = handle:close() - - if not success or result == "" then return "" end - return result + local helper = script_dir() .. "../icon/_icon_shortcode.py" + return run_helper({ + "python3", helper, icon_name, "--size", "16", "--class", "gd-details-icon" + }) end function Div(div) diff --git a/great_docs/assets/_extensions/evolution/evolution.lua b/great_docs/assets/_extensions/evolution/evolution.lua index 25537402c..1039b1943 100644 --- a/great_docs/assets/_extensions/evolution/evolution.lua +++ b/great_docs/assets/_extensions/evolution/evolution.lua @@ -20,6 +20,43 @@ local function kwarg_str(kwargs, key) return s or "" end +--- Return the directory holding this script, ending in a slash. +--- +--- Quarto 2 omits Lua's `debug` library, so resolve a path against the +--- extension's directory instead. +local function script_dir() + if debug then + return debug.getinfo(1, "S").source:match("@?(.*/)") or "./" + end + return (quarto.utils.resolve_path("x"):gsub("x$", "")) +end + +--- Run a helper command without a shell. +--- +--- Use `pandoc.system.command` where Pandoc has it: under Quarto 2, `io.popen` +--- can deadlock when shortcodes run on parallel threads. +---@param cmd_args string[] The command and its arguments. +---@return boolean Whether the command exited successfully. +---@return string Its standard output followed by its standard error. +local function run_helper(cmd_args) + if pandoc.system.command then + local ok, status, out, err = pcall( + pandoc.system.command, cmd_args[1], { table.unpack(cmd_args, 2) }, "" + ) + if not ok then return false, tostring(status) end + return status == false, (out or "") .. (err or "") + end + local parts = {} + for _, arg in ipairs(cmd_args) do + local escaped = arg:gsub("'", "'\\''") + table.insert(parts, "'" .. escaped .. "'") + end + local handle = io.popen(table.concat(parts, " ") .. " 2>&1") + if not handle then return false, "" end + local result = handle:read("*a") + return handle:close() == true, result +end + return { ["evolution"] = function(args, kwargs) -- Symbol can be a positional arg or a named kwarg @@ -36,8 +73,8 @@ return { end -- Locate the helper script (lives alongside this .lua file) - local script_dir = debug.getinfo(1, "S").source:match("@?(.*/)") or "./" - local helper = script_dir .. "_evolution_shortcode.py" + local here = script_dir() + local helper = here .. "_evolution_shortcode.py" -- Build CLI arguments for the helper script local cmd_args = { "python", helper, symbol } @@ -59,34 +96,17 @@ return { -- the Quarto project root (the directory containing _extensions/). local json_val = kwarg_str(kwargs, "json") if json_val ~= "" then - -- Resolve relative paths: script_dir is /_extensions/evolution/ + -- Resolve relative paths: `here` is /_extensions/evolution/ -- so project root is two levels up. if json_val:sub(1, 1) ~= "/" then - local project_root = script_dir .. "../../" + local project_root = here .. "../../" json_val = project_root .. json_val end table.insert(cmd_args, "--json_file") table.insert(cmd_args, json_val) end - -- Build shell command (quote each argument) - local parts = {} - for _, arg in ipairs(cmd_args) do - local escaped = arg:gsub("'", "'\\''") - table.insert(parts, "'" .. escaped .. "'") - end - local cmd = table.concat(parts, " ") .. " 2>&1" - - local handle = io.popen(cmd) - if not handle then - return pandoc.RawBlock( - "html", - "" - ) - end - - local result = handle:read("*a") - local success = handle:close() + local success, result = run_helper(cmd_args) if not success or result == "" then local msg = result ~= "" and result or "unknown error" diff --git a/great_docs/assets/_extensions/icon/icon.lua b/great_docs/assets/_extensions/icon/icon.lua index 552273fa8..52b6d9cba 100644 --- a/great_docs/assets/_extensions/icon/icon.lua +++ b/great_docs/assets/_extensions/icon/icon.lua @@ -19,6 +19,43 @@ local function kwarg_str(kwargs, key) return s or "" end +--- Return the directory holding this script, ending in a slash. +--- +--- Quarto 2 omits Lua's `debug` library, so resolve a path against the +--- extension's directory instead. +local function script_dir() + if debug then + return debug.getinfo(1, "S").source:match("@?(.*/)") or "./" + end + return (quarto.utils.resolve_path("x"):gsub("x$", "")) +end + +--- Run a helper command without a shell. +--- +--- Use `pandoc.system.command` where Pandoc has it: under Quarto 2, `io.popen` +--- can deadlock when shortcodes run on parallel threads. +---@param cmd_args string[] The command and its arguments. +---@return boolean Whether the command exited successfully. +---@return string Its standard output followed by its standard error. +local function run_helper(cmd_args) + if pandoc.system.command then + local ok, status, out, err = pcall( + pandoc.system.command, cmd_args[1], { table.unpack(cmd_args, 2) }, "" + ) + if not ok then return false, tostring(status) end + return status == false, (out or "") .. (err or "") + end + local parts = {} + for _, arg in ipairs(cmd_args) do + local escaped = arg:gsub("'", "'\\''") + table.insert(parts, "'" .. escaped .. "'") + end + local handle = io.popen(table.concat(parts, " ") .. " 2>&1") + if not handle then return false, "" end + local result = handle:read("*a") + return handle:close() == true, result +end + return { ["icon"] = function(args, kwargs) -- Icon name can be a positional arg or a named kwarg @@ -35,8 +72,7 @@ return { end -- Locate the helper script (lives alongside this .lua file) - local script_dir = debug.getinfo(1, "S").source:match("@?(.*/)") or "./" - local helper = script_dir .. "_icon_shortcode.py" + local helper = script_dir() .. "_icon_shortcode.py" -- Build CLI arguments for the helper script -- Use python3 for macOS compatibility (python may not exist) @@ -52,24 +88,7 @@ return { end end - -- Build shell command (quote each argument) - local parts = {} - for _, arg in ipairs(cmd_args) do - local escaped = arg:gsub("'", "'\\''") - table.insert(parts, "'" .. escaped .. "'") - end - local cmd = table.concat(parts, " ") .. " 2>&1" - - local handle = io.popen(cmd) - if not handle then - return pandoc.RawInline( - "html", - "" - ) - end - - local result = handle:read("*a") - local success = handle:close() + local success, result = run_helper(cmd_args) if not success or result == "" then local msg = result ~= "" and result or "unknown error" diff --git a/great_docs/assets/_extensions/markdown-pages/markdown-pages.lua b/great_docs/assets/_extensions/markdown-pages/markdown-pages.lua index 8ee75ecf8..5171f02c1 100644 --- a/great_docs/assets/_extensions/markdown-pages/markdown-pages.lua +++ b/great_docs/assets/_extensions/markdown-pages/markdown-pages.lua @@ -325,7 +325,11 @@ local function write_companion(doc) blocks:insert(title:walk(flatten)) end blocks:extend(doc.blocks) - local md = pandoc.write(pandoc.Pandoc(blocks), "gfm-raw_html", { wrap_text = "none" }) + -- Quarto 2 has no GitHub-Flavored Markdown writer; use its Markdown one + local companion_doc = pandoc.Pandoc(blocks) + local options = { wrap_text = "none" } + local ok, md = pcall(pandoc.write, companion_doc, "gfm-raw_html", options) + if not ok then md = pandoc.write(companion_doc, "markdown", options) end for from, to in pairs(ASCII) do md = md:gsub(from, to) end -- A full render cleans the output directory, and Quarto creates each @@ -353,6 +357,9 @@ local write = { end, } +-- Quarto 2 (versions 0.x) has no custom node handlers and warns about them +if quarto.version[1] == 0 then convert = {} end + return { { Pandoc = function(doc) snapshot = doc:clone() end }, convert, diff --git a/great_docs/assets/_extensions/tbl-explorer/tbl-explorer.lua b/great_docs/assets/_extensions/tbl-explorer/tbl-explorer.lua index e09e8f2a1..aa8ec27fd 100644 --- a/great_docs/assets/_extensions/tbl-explorer/tbl-explorer.lua +++ b/great_docs/assets/_extensions/tbl-explorer/tbl-explorer.lua @@ -17,6 +17,43 @@ local function kwarg_str(kwargs, key) return s or "" end +--- Return the directory holding this script, ending in a slash. +--- +--- Quarto 2 omits Lua's `debug` library, so resolve a path against the +--- extension's directory instead. +local function script_dir() + if debug then + return debug.getinfo(1, "S").source:match("@?(.*/)") or "./" + end + return (quarto.utils.resolve_path("x"):gsub("x$", "")) +end + +--- Run a helper command without a shell. +--- +--- Use `pandoc.system.command` where Pandoc has it: under Quarto 2, `io.popen` +--- can deadlock when shortcodes run on parallel threads. +---@param cmd_args string[] The command and its arguments. +---@return boolean Whether the command exited successfully. +---@return string Its standard output followed by its standard error. +local function run_helper(cmd_args) + if pandoc.system.command then + local ok, status, out, err = pcall( + pandoc.system.command, cmd_args[1], { table.unpack(cmd_args, 2) }, "" + ) + if not ok then return false, tostring(status) end + return status == false, (out or "") .. (err or "") + end + local parts = {} + for _, arg in ipairs(cmd_args) do + local escaped = arg:gsub("'", "'\\''") + table.insert(parts, "'" .. escaped .. "'") + end + local handle = io.popen(table.concat(parts, " ") .. " 2>&1") + if not handle then return false, "" end + local result = handle:read("*a") + return handle:close() == true, result +end + return { ["tbl-explorer"] = function(args, kwargs) -- File path can be a positional arg or named kwarg @@ -33,12 +70,12 @@ return { end -- Locate the helper script (lives alongside this .lua file) - local script_dir = debug.getinfo(1, "S").source:match("@?(.*/)") or "./" - local helper = script_dir .. "_tbl_explorer_shortcode.py" + local here = script_dir() + local helper = here .. "_tbl_explorer_shortcode.py" -- Resolve relative file paths against the Quarto project root if file:sub(1, 1) ~= "/" then - local project_root = script_dir .. "../../" + local project_root = here .. "../../" file = project_root .. file end @@ -62,24 +99,7 @@ return { end end - -- Build shell command (quote each argument) - local parts = {} - for _, arg in ipairs(cmd_args) do - local escaped = arg:gsub("'", "'\\''") - table.insert(parts, "'" .. escaped .. "'") - end - local cmd = table.concat(parts, " ") .. " 2>&1" - - local handle = io.popen(cmd) - if not handle then - return pandoc.RawBlock( - "html", - "" - ) - end - - local result = handle:read("*a") - local success = handle:close() + local success, result = run_helper(cmd_args) if not success or result == "" then return pandoc.RawBlock( diff --git a/great_docs/assets/_extensions/tbl-preview/tbl-preview.lua b/great_docs/assets/_extensions/tbl-preview/tbl-preview.lua index 2d7c2b0ea..00e0625b1 100644 --- a/great_docs/assets/_extensions/tbl-preview/tbl-preview.lua +++ b/great_docs/assets/_extensions/tbl-preview/tbl-preview.lua @@ -19,6 +19,43 @@ local function kwarg_str(kwargs, key) return s or "" end +--- Return the directory holding this script, ending in a slash. +--- +--- Quarto 2 omits Lua's `debug` library, so resolve a path against the +--- extension's directory instead. +local function script_dir() + if debug then + return debug.getinfo(1, "S").source:match("@?(.*/)") or "./" + end + return (quarto.utils.resolve_path("x"):gsub("x$", "")) +end + +--- Run a helper command without a shell. +--- +--- Use `pandoc.system.command` where Pandoc has it: under Quarto 2, `io.popen` +--- can deadlock when shortcodes run on parallel threads. +---@param cmd_args string[] The command and its arguments. +---@return boolean Whether the command exited successfully. +---@return string Its standard output followed by its standard error. +local function run_helper(cmd_args) + if pandoc.system.command then + local ok, status, out, err = pcall( + pandoc.system.command, cmd_args[1], { table.unpack(cmd_args, 2) }, "" + ) + if not ok then return false, tostring(status) end + return status == false, (out or "") .. (err or "") + end + local parts = {} + for _, arg in ipairs(cmd_args) do + local escaped = arg:gsub("'", "'\\''") + table.insert(parts, "'" .. escaped .. "'") + end + local handle = io.popen(table.concat(parts, " ") .. " 2>&1") + if not handle then return false, "" end + local result = handle:read("*a") + return handle:close() == true, result +end + return { ["tbl-preview"] = function(args, kwargs) -- File path can be a positional arg or named kwarg @@ -35,13 +72,13 @@ return { end -- Locate the helper script (lives alongside this .lua file) - local script_dir = debug.getinfo(1, "S").source:match("@?(.*/)") or "./" - local helper = script_dir .. "_tbl_preview_shortcode.py" + local here = script_dir() + local helper = here .. "_tbl_preview_shortcode.py" -- Resolve relative file paths against the Quarto project root - -- (script_dir is /_extensions/tbl-preview/) + -- (`here` is /_extensions/tbl-preview/) if file:sub(1, 1) ~= "/" then - local project_root = script_dir .. "../../" + local project_root = here .. "../../" file = project_root .. file end @@ -64,24 +101,7 @@ return { end end - -- Build shell command (quote each argument) - local parts = {} - for _, arg in ipairs(cmd_args) do - local escaped = arg:gsub("'", "'\\''") - table.insert(parts, "'" .. escaped .. "'") - end - local cmd = table.concat(parts, " ") .. " 2>&1" - - local handle = io.popen(cmd) - if not handle then - return pandoc.RawBlock( - "html", - "" - ) - end - - local result = handle:read("*a") - local success = handle:close() + local success, result = run_helper(cmd_args) if not success or result == "" then local msg = result ~= "" and result or "unknown error" From 1fe0ac65b35b3eea5eb40ceefde0c30d3f368de7 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:33:09 -0500 Subject: [PATCH 006/161] Allow configuring the rendered output directory --- test-packages/render_all.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test-packages/render_all.py b/test-packages/render_all.py index 1ba8d386b..b25d767b0 100644 --- a/test-packages/render_all.py +++ b/test-packages/render_all.py @@ -16,6 +16,9 @@ 4. Injects a top navigation bar into every HTML file 5. Creates a GDG index page at _rendered/_hub/index.html 6. Starts a local HTTP server on port 3333 + +Set `GDG_RENDERED_DIR` to build into another directory than `_rendered`, such as +a separate one for sites rendered with Quarto 2 (`make q2-hub-build`). """ from __future__ import annotations @@ -69,7 +72,7 @@ # ── Constants ──────────────────────────────────────────────────────────────── -RENDERED_DIR = _THIS_DIR / "_rendered" +RENDERED_DIR = Path(os.environ.get("GDG_RENDERED_DIR") or _THIS_DIR / "_rendered").resolve() HUB_DIR = RENDERED_DIR / "_hub" LOGS_DIR = RENDERED_DIR / "_logs" STATE_FILE = RENDERED_DIR / "_build_state.json" From 328c89fe4fbc42023331788d6ce48f9da6230041 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:33:39 -0500 Subject: [PATCH 007/161] Align Gauntlet fixtures with build configuration --- tests/gauntlet_sites.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/gauntlet_sites.py b/tests/gauntlet_sites.py index a040bb10d..6e8de43d1 100644 --- a/tests/gauntlet_sites.py +++ b/tests/gauntlet_sites.py @@ -36,7 +36,10 @@ ) _TEST_PACKAGES_DIR = Path(__file__).resolve().parent.parent / "test-packages" -RENDERED_DIR = _TEST_PACKAGES_DIR / "_rendered" +# `GDG_RENDERED_DIR` selects another Gauntlet build, as `render_all.py` does +RENDERED_DIR = Path( + os.environ.get("GDG_RENDERED_DIR") or _TEST_PACKAGES_DIR / "_rendered" +).resolve() # Treat these failures as unavailable rendered fixtures; dependent tests skip # absent sites. Fatal API reference configuration errors raise `BuildError`. @@ -319,9 +322,11 @@ def quarto_available() -> bool: Returns ------- - Whether the `quarto` executable is available. + Whether the Quarto executable that great-docs renders with is available. """ - return shutil.which("quarto") is not None + from great_docs._build import quarto + + return shutil.which(quarto.executable()) is not None def build_site(rendered_dir: Path, name: str) -> Path: @@ -369,7 +374,7 @@ def build_site(rendered_dir: Path, name: str) -> Path: pipeline.prepare_for_freeze(docs._config, docs.layout, log, remote=docs._remote) result = subprocess.run( - ["quarto", "render"], + [quarto.executable(), "render"], cwd=docs.layout.build_dir, env=quarto.environment(docs._config), capture_output=True, From 19415af3b2db3bfde7c34f46d67a01f4ff0126e6 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:33:58 -0500 Subject: [PATCH 008/161] Use configured Quarto executable in render test --- tests/test_description_render.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_description_render.py b/tests/test_description_render.py index 0ba0baf3a..19a8c5290 100644 --- a/tests/test_description_render.py +++ b/tests/test_description_render.py @@ -9,11 +9,14 @@ import pytest +from great_docs._build.quarto import executable as quarto_executable from great_docs._content.metadata import metadata_value from great_docs._website.page_metadata import add_to_page, write_to_pages from great_docs.config import Config -pytestmark = pytest.mark.skipif(shutil.which("quarto") is None, reason="Quarto is not installed") +pytestmark = pytest.mark.skipif( + shutil.which(quarto_executable()) is None, reason="Quarto is not installed" +) _META_DESCRIPTION = re.compile(r']*)" ?/?>') @@ -51,7 +54,7 @@ def test_descriptions_reach_the_page_intact(tmp_path: Path): (project / f"{name}.qmd").write_text(content, encoding="utf-8") write_to_pages(project, quarto_config, Config(tmp_path), "Site default") - subprocess.run(["quarto", "render"], cwd=project, check=True, capture_output=True) + subprocess.run([quarto_executable(), "render"], cwd=project, check=True, capture_output=True) def descriptions(name: str) -> list[str]: page = (project / "_site" / f"{name}.html").read_text(encoding="utf-8") From b77fc6c4d5a903bac878f2256711244058bd78e9 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:34:07 -0500 Subject: [PATCH 009/161] Allow selecting rendered Gauntlet test directory --- tests/test_gdg_rendered.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_gdg_rendered.py b/tests/test_gdg_rendered.py index b3765281e..96da1c462 100644 --- a/tests/test_gdg_rendered.py +++ b/tests/test_gdg_rendered.py @@ -23,6 +23,7 @@ from __future__ import annotations +import os import posixpath import re import sys @@ -36,7 +37,10 @@ # ── Setup ──────────────────────────────────────────────────────────────────── _TEST_PACKAGES_DIR = Path(__file__).resolve().parent.parent / "test-packages" -_RENDERED_DIR = _TEST_PACKAGES_DIR / "_rendered" +# `GDG_RENDERED_DIR` selects another Gauntlet build, as `render_all.py` does +_RENDERED_DIR = Path( + os.environ.get("GDG_RENDERED_DIR") or _TEST_PACKAGES_DIR / "_rendered" +).resolve() if str(_TEST_PACKAGES_DIR) not in sys.path: sys.path.insert(0, str(_TEST_PACKAGES_DIR)) From 1156974b7ca3b59bb5d4957282a57a2ff79659d1 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:34:17 -0500 Subject: [PATCH 010/161] Use configured Quarto executable in filter tests --- tests/test_markdown_pages_filter.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_markdown_pages_filter.py b/tests/test_markdown_pages_filter.py index 9e56ab668..0df9d47bb 100644 --- a/tests/test_markdown_pages_filter.py +++ b/tests/test_markdown_pages_filter.py @@ -9,11 +9,15 @@ import pytest +from great_docs._build.quarto import executable as quarto_executable + _EXTENSION = ( Path(__file__).parent.parent / "great_docs" / "assets" / "_extensions" / "markdown-pages" ) -pytestmark = pytest.mark.skipif(shutil.which("quarto") is None, reason="Quarto is not installed") +pytestmark = pytest.mark.skipif( + shutil.which(quarto_executable()) is None, reason="Quarto is not installed" +) _QUARTO_YML = """\ project: @@ -125,7 +129,7 @@ def _render_site(root: Path, *, with_filter: bool) -> Path: page = root / name page.parent.mkdir(parents=True, exist_ok=True) page.write_text(text, encoding="utf-8") - subprocess.run(["quarto", "render"], cwd=root, check=True, capture_output=True) + subprocess.run([quarto_executable(), "render"], cwd=root, check=True, capture_output=True) return root / "_site" From 2f41187d7a80ef96b1ba8421f1df4c18d2a56637 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:34:27 -0500 Subject: [PATCH 011/161] Use resolved Quarto executable in metadata tests --- tests/test_metadata_partial_render.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_metadata_partial_render.py b/tests/test_metadata_partial_render.py index 3827404d5..fc6e3509c 100644 --- a/tests/test_metadata_partial_render.py +++ b/tests/test_metadata_partial_render.py @@ -9,11 +9,14 @@ import pytest import great_docs +from great_docs._build.quarto import executable as quarto_executable from great_docs._website import head, page_dates BUNDLED = Path(great_docs.__file__).parent / "assets" / "metadata.html" -pytestmark = pytest.mark.skipif(shutil.which("quarto") is None, reason="Quarto is not installed") +pytestmark = pytest.mark.skipif( + shutil.which(quarto_executable()) is None, reason="Quarto is not installed" +) def test_partial_and_direction_reach_the_page(tmp_path: Path): @@ -36,7 +39,7 @@ def test_partial_and_direction_reach_the_page(tmp_path: Path): ) (project / "index.qmd").write_text("---\ntitle: T\n---\n\nText\n", encoding="utf-8") - subprocess.run(["quarto", "render"], cwd=project, check=True, capture_output=True) + subprocess.run([quarto_executable(), "render"], cwd=project, check=True, capture_output=True) page = (project / "_site" / "index.html").read_text(encoding="utf-8") assert page.count('') == 1 @@ -73,7 +76,7 @@ def test_page_dates_reach_the_page(tmp_path: Path) -> None: ) (project / "reference" / "f.qmd").write_text("---\ntitle: F\n---\n\nText\n", encoding="utf-8") - subprocess.run(["quarto", "render"], cwd=project, check=True, capture_output=True) + subprocess.run([quarto_executable(), "render"], cwd=project, check=True, capture_output=True) page = (project / "_site" / "index.html").read_text(encoding="utf-8") generated = (project / "_site" / "reference" / "f.html").read_text(encoding="utf-8") @@ -102,7 +105,7 @@ def test_robots_front_matter_reaches_the_page(tmp_path: Path): '---\ntitle: D\nrobots: "noindex, nofollow"\n---\n\nText\n', encoding="utf-8" ) - subprocess.run(["quarto", "render"], cwd=project, check=True, capture_output=True) + subprocess.run([quarto_executable(), "render"], cwd=project, check=True, capture_output=True) draft = (project / "_site" / "draft.html").read_text(encoding="utf-8") index = (project / "_site" / "index.html").read_text(encoding="utf-8") From 0aca468df5abd934b6ac89e2050e0c6397998d3a Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:34:44 -0500 Subject: [PATCH 012/161] Use configured Quarto executable in filter tests --- tests/test_page_url_filter.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_page_url_filter.py b/tests/test_page_url_filter.py index 97e22c3b9..001c1cfa9 100644 --- a/tests/test_page_url_filter.py +++ b/tests/test_page_url_filter.py @@ -9,9 +9,13 @@ import pytest +from great_docs._build.quarto import executable as quarto_executable + _EXTENSION = Path(__file__).parent.parent / "great_docs" / "assets" / "_extensions" / "page-url" -pytestmark = pytest.mark.skipif(shutil.which("quarto") is None, reason="Quarto is not installed") +pytestmark = pytest.mark.skipif( + shutil.which(quarto_executable()) is None, reason="Quarto is not installed" +) def _render_site( @@ -36,7 +40,7 @@ def _render_site( for page in ("index.qmd", "guide/index.qmd", "guide/page.qmd"): (project / page).write_text("---\ntitle: T\n---\n\nText\n", encoding="utf-8") - subprocess.run(["quarto", "render"], cwd=project, check=True, capture_output=True) + subprocess.run([quarto_executable(), "render"], cwd=project, check=True, capture_output=True) return project / "_site" From faa9221457ca65c0c524f4dd88d2d9ded5c4e6e0 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:34:54 -0500 Subject: [PATCH 013/161] Use resolved Quarto executable in render tests --- tests/test_parallel_render.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_parallel_render.py b/tests/test_parallel_render.py index 07983a76d..64aef47a2 100644 --- a/tests/test_parallel_render.py +++ b/tests/test_parallel_render.py @@ -19,6 +19,7 @@ import pytest from great_docs._build import parallel_render as pr +from great_docs._build.quarto import executable as quarto_executable # ── Choosing the number of processes ───────────────────────────────────────── @@ -539,7 +540,9 @@ def test_worker_copy_writes_its_configuration_from_the_mapping(tmp_path: Path): # ── Rendering with Quarto ──────────────────────────────────────────────────── -_needs_quarto = pytest.mark.skipif(shutil.which("quarto") is None, reason="Quarto not installed") +_needs_quarto = pytest.mark.skipif( + shutil.which(quarto_executable()) is None, reason="Quarto not installed" +) _QUARTO_YML = """\ project: @@ -604,7 +607,7 @@ def _urls(sitemap: Path) -> list[str]: def sites(tmp_path_factory: pytest.TempPathFactory) -> tuple[Path, Path, pr.RenderResult]: plain = _write_project(tmp_path_factory.mktemp("plain") / "proj") split = _write_project(tmp_path_factory.mktemp("split") / "proj") - subprocess.run(["quarto", "render"], cwd=plain, check=True, capture_output=True) + subprocess.run([quarto_executable(), "render"], cwd=plain, check=True, capture_output=True) pages: list[str] = [] config = pr.parse_yaml(_QUARTO_YML) result = pr.render(split, config, dict(os.environ), 3, on_page=pages.append, min_pages=1) From 45e0d82a5bf58401ffded6fa2ebd596d829f6b95 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:35:04 -0500 Subject: [PATCH 014/161] Expand Quarto 2 compatibility tests --- tests/test_quarto_check.py | 109 +++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tests/test_quarto_check.py b/tests/test_quarto_check.py index 0f3e204d9..c52a8e498 100644 --- a/tests/test_quarto_check.py +++ b/tests/test_quarto_check.py @@ -1,6 +1,10 @@ from __future__ import annotations +import os +import subprocess +import sys import tempfile +from pathlib import Path import pytest @@ -79,3 +83,108 @@ def test_build_reports_and_raises_quarto_not_found_when_quarto_missing( docs.build() assert capsys.readouterr().err == f"Error: {excinfo.value}\n" + + +def test_executable_defaults_to_quarto(monkeypatch: pytest.MonkeyPatch): + monkeypatch.delenv(quarto.EXECUTABLE_ENV, raising=False) + assert quarto.executable() == "quarto" + assert not quarto.is_q2() + + +@pytest.mark.parametrize( + ("value", "q2"), + [ + ("q2", True), + ("/opt/q2/target/release/q2", True), + ("/opt/bin/q2.exe", True), + ("quarto", False), + ("/usr/local/bin/quarto", False), + (" ", False), + ], +) +def test_is_q2_reads_the_executable_name(monkeypatch: pytest.MonkeyPatch, value: str, q2: bool): + monkeypatch.setenv(quarto.EXECUTABLE_ENV, value) + assert quarto.is_q2() is q2 + + +@pytest.mark.parametrize( + ("stdout", "version"), + [ + ("1.9.37\n", (1, 9, 37)), + ("q2 (quarto 2) 0.45.0\n", (0, 45, 0)), + ("Q2 (quarto 2) 0.46.1\n", (0, 46, 1)), + ("unknown\n", None), + ], +) +def test_installed_version_reads_quarto_and_quarto_2( + monkeypatch: pytest.MonkeyPatch, stdout: str, version: tuple[int, ...] | None +): + monkeypatch.setattr( + "great_docs._build.quarto.subprocess.run", + lambda *args, **kwargs: subprocess.CompletedProcess(args, 0, stdout, ""), + ) + assert quarto.installed_version() == version + + +def test_ensure_installed_applies_the_quarto_2_minimum(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv(quarto.EXECUTABLE_ENV, "q2") + monkeypatch.setattr("great_docs._build.quarto.shutil.which", lambda name: "/bin/q2") + monkeypatch.setattr("great_docs._build.quarto.installed_version", lambda: (0, 45, 0)) + assert quarto.ensure_installed() is None + + monkeypatch.setattr("great_docs._build.quarto.installed_version", lambda: (0, 44, 2)) + with pytest.raises(QuartoVersionError, match=r"Quarto 2 0\.45\.0 or later"): + quarto.ensure_installed() + + +def test_ensure_installed_names_a_missing_quarto_2(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setenv(quarto.EXECUTABLE_ENV, "/nowhere/q2") + monkeypatch.setattr("great_docs._build.quarto.shutil.which", lambda name: None) + + with pytest.raises(QuartoNotFoundError, match="GREAT_DOCS_QUARTO is '/nowhere/q2'"): + quarto.ensure_installed() + + +def test_environment_puts_the_python_scripts_first_for_quarto_2( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +): + monkeypatch.setenv(quarto.EXECUTABLE_ENV, "q2") + docs = GreatDocs(project_path=str(tmp_path)) + env = quarto.environment(docs._config) + + scripts = os.path.dirname(env["QUARTO_PYTHON"]) + assert env["PATH"].split(os.pathsep)[0] == scripts + + +@pytest.mark.skipif(sys.platform == "win32", reason="the fake Quarto 2 is a shell script") +def test_render_reports_quarto_2_pages_and_warnings_when_it_ends( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +): + fake = tmp_path / "bin" / "q2" + fake.parent.mkdir() + out = tmp_path / "_site" + fake.write_text( + "#!/bin/sh\n" + f'echo "Rendering project: {tmp_path} (type: website)" >&2\n' + 'echo "Warning [Q-2-9]: naked HTML in a.qmd" >&2\n' + 'echo "Warning [Q-2-9]: naked HTML in b.qmd" >&2\n' + 'echo "Warning: no code here" >&2\n' + f'echo "2026-01-01T00:00:00Z INFO q2::commands::render: Output: {out}/a.html" >&2\n' + f'echo "2026-01-01T00:00:00Z INFO q2::commands::render: Output: {out}/b.html" >&2\n' + f'echo "Rendered 2 of 2 files to {out} — 3 warnings" >&2\n', + encoding="utf-8", + ) + fake.chmod(0o755) + monkeypatch.setenv(quarto.EXECUTABLE_ENV, str(fake)) + events: list[object] = [] + + result = quarto.render(tmp_path, on_page=events.append, on_warning=events.append) + + assert result.returncode == 0 + assert result.page_timings == [] + assert events == [ + "WARN [Q-2-9] naked HTML in a.qmd (and 1 more like it)", + "WARN no code here", + quarto.Progress(1, 2, os.path.join("_site", "a.html")), + quarto.Progress(2, 2, os.path.join("_site", "b.html")), + ] From 8c9a79d6af5af29e8a68dc59f66a13c677b1be61 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:35:14 -0500 Subject: [PATCH 015/161] Test recursive render globs for Quarto 2 --- tests/test_quarto_yml.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_quarto_yml.py b/tests/test_quarto_yml.py index 5f2d07db2..1f4093c11 100644 --- a/tests/test_quarto_yml.py +++ b/tests/test_quarto_yml.py @@ -485,3 +485,20 @@ def test_apply_places_the_user_guide_as_the_user_guide_step_does( def test_navbar_link_rejects_a_placement_its_kind_ignores(fields: dict[str, Any]): with pytest.raises(ValueError, match="placement"): NavbarLink("Demos", "demos/index.qmd", **fields) + + +def test_write_makes_the_render_globs_recursive_for_quarto_2( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +): + monkeypatch.setenv("GREAT_DOCS_QUARTO", "q2") + quarto_config = {"project": {"type": "website", "render": [*quarto_yml.RENDER_GLOBS, "!a.md"]}} + + quarto_yml.write(tmp_path, quarto_config) + + assert quarto_yml.read(tmp_path)["project"]["render"] == [ + "**/*.qmd", + "**/*.md", + "**/*.ipynb", + "!a.md", + ] + assert quarto_config["project"]["render"][0] == "*.qmd" From 9fa6249cd48b2be498a30ed7db0b5e07c35e3691 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 13 Nov 2026 12:35:23 -0500 Subject: [PATCH 016/161] Use configured Quarto in sidebar rendering tests --- tests/test_shared_sidebar.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_shared_sidebar.py b/tests/test_shared_sidebar.py index 4641f6140..8b8fa706a 100644 --- a/tests/test_shared_sidebar.py +++ b/tests/test_shared_sidebar.py @@ -25,6 +25,7 @@ from great_docs._build import passes from great_docs._build.log import BuildLog +from great_docs._build.quarto import executable as quarto_executable from great_docs._website.navigation import shared_sidebar if TYPE_CHECKING: @@ -519,13 +520,17 @@ def test_for_page_without_its_own_link_only_rebases(): # ── Rendering with Quarto ──────────────────────────────────────────────────── -_needs_quarto = pytest.mark.skipif(shutil.which("quarto") is None, reason="Quarto not installed") +_needs_quarto = pytest.mark.skipif( + shutil.which(quarto_executable()) is None, reason="Quarto not installed" +) _SIDEBAR_NAV = re.compile(r'