Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @forman @clarasb
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ __pycache__
coverage.xml
htmlcov/
site/
.cache/
docs/rule-ref.md

# Jupyter
.ipynb_checkpoints
Expand All @@ -35,4 +37,4 @@ notebooks/*.zarr/
.idea/

# Downloaded assets
docs/assets/downloaded/
docs/assets/downloaded/
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

### Documentation

- Migrated from MkDocs/Material to Zensical with the classic theme and
`zensical.toml`. Preserved the existing Pixi documentation commands, self-hosted
fonts, API references, and automatic rule-reference regeneration during preview.
Moved documentation helpers into `docs/scripts/` and added dated migration notes
covering dependency versions and remaining compatibility limitations. (#81)
- Completed the configuration guide, replacing all "Coming soon" sections with
explanations and examples for file filters, opening options, rule settings,
presets, custom plugins, rules, and processors.
Expand Down
24 changes: 18 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,26 @@ pixi run docs-serve
```

The build writes `site/`. The preview command serves the site locally and
rebuilds when files change. Edit Markdown pages in `docs/`; update `mkdocs.yml`
rebuilds when files change. Edit Markdown pages in `docs/`; update `zensical.toml`
when adding navigation entries.

`docs/mkruleref.py` runs automatically through `mkdocs-gen-files`, generating
`rule-ref.md` from discovered plugin metadata. Do not create or edit that
generated page manually. Update rule descriptions and schemas in the source,
or change the generator for presentation changes. The API page uses
`mkdocstrings` to render source docstrings.
Both tasks use `docs/scripts/manage.py` to prepare self-hosted Roboto fonts and run
`docs/scripts/mkruleref.py`, generating the ignored `docs/rule-ref.md` from discovered
plugin metadata. The build then runs `zensical build --strict`; preview runs
`zensical serve`. Additional arguments are forwarded, for example
`pixi run docs-serve --dev-addr 127.0.0.1:8001`.

During preview, a watcher checks Python sources in `xrlint/`, the generator,
and `pyproject.toml` every half second. Changes regenerate the reference in a
fresh Python process, and Zensical reloads the page. If an edit temporarily breaks
generation, the last successful page remains available; fixing the source retries
generation. Stop preview with Ctrl+C.

Do not create or edit the generated rule page manually. Update rule descriptions
and schemas in the source, or change the generator for presentation changes.
The API page uses `mkdocstrings` to render source docstrings. Use these Pixi tasks
instead of invoking Zensical directly so preparation and regeneration take place.
See [migration notes](docs/zensical-migration.md) for compatibility limitations.

The plugins installed in the build environment determine the generated rule
reference. Use a project environment without unrelated third-party XRLint
Expand Down
2 changes: 1 addition & 1 deletion docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Follow the [documentation build and preview instructions](https://github.com/bcd
to set up MkDocs and run it locally.

The generated site is written to `site/`. The rule reference is generated by
`docs/mkruleref.py` during the build, using installed plugin metadata.
`docs/scripts/mkruleref.py` during the build, using installed plugin metadata.
The API reference is rendered from Python docstrings by `mkdocstrings`.

## License
Expand Down
10 changes: 6 additions & 4 deletions docs/hooks/download_fonts.py → docs/scripts/download_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
)


def on_config(config):
"""Download self-hosted Roboto assets before MkDocs builds the site."""
docs_dir = Path(config["docs_dir"])
def download_fonts():
"""Prepare self-hosted Roboto assets before building or previewing the site."""
docs_dir = Path(__file__).resolve().parent.parent
font_dir = docs_dir / "assets" / "downloaded" / "fonts"
font_dir.mkdir(parents=True, exist_ok=True)

Expand All @@ -41,4 +41,6 @@ def on_config(config):
f"{font_dir}."
) from exc

return config

if __name__ == "__main__":
download_fonts()
84 changes: 84 additions & 0 deletions docs/scripts/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""Build or preview the documentation, including its generated rule reference."""

import argparse
import subprocess
import sys
import time
from pathlib import Path

PROJECT_DIR = Path(__file__).resolve().parents[2]
GENERATOR = Path(__file__).resolve().with_name("mkruleref.py")


def rule_sources():
"""Snapshot sources, including additions and removals, without watching output."""
paths = [GENERATOR, PROJECT_DIR / "pyproject.toml"]
paths.extend((PROJECT_DIR / "xrlint").rglob("*.py"))
sources = {}
for path in paths:
try:
stat = path.stat()
except FileNotFoundError:
# Editors may replace or remove a file while we scan the tree.
continue
sources[path] = (stat.st_mtime_ns, stat.st_size)
return sources


def generate_rule_reference():
# A fresh interpreter reloads plugin metadata instead of reusing imported modules.
subprocess.run([sys.executable, str(GENERATOR)], cwd=PROJECT_DIR, check=True)


def serve(arguments):
previous = rule_sources()
generate_rule_reference()
process = subprocess.Popen(
[sys.executable, "-m", "zensical", "serve", *arguments], cwd=PROJECT_DIR
)
try:
while process.poll() is None:
time.sleep(0.5)
current = rule_sources()
if current != previous:
previous = current
try:
generate_rule_reference()
except subprocess.CalledProcessError:
print(
"Rule reference generation failed; fix the sources to retry.",
file=sys.stderr,
flush=True,
)
return process.returncode
except KeyboardInterrupt:
return 0
finally:
if process.poll() is None:
process.terminate()
try:
process.wait(timeout=5)
except subprocess.TimeoutExpired:
process.kill()
process.wait()


def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("command", choices=["build", "serve"])
options, arguments = parser.parse_known_args()
subprocess.run(
[sys.executable, str(GENERATOR.with_name("download_fonts.py"))],
cwd=PROJECT_DIR,
check=True,
)
if options.command == "serve":
return serve(arguments)
generate_rule_reference()
return subprocess.call(
[sys.executable, "-m", "zensical", "build", *arguments], cwd=PROJECT_DIR
)


if __name__ == "__main__":
sys.exit(main())
23 changes: 17 additions & 6 deletions docs/mkruleref.py → docs/scripts/mkruleref.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# MIT license (https://mit-license.org/).

import json
from io import StringIO
from pathlib import Path

from xrlint.config import plugins_from_entry_points
from xrlint.constants import CORE_PLUGIN_NAME
from xrlint.plugin import Plugin
from xrlint.rule import RuleConfig

# for icons, see
# https://squidfunk.github.io/mkdocs-material/reference/icons-emojis/
# https://zensical.org/docs/authoring/icons-emojis/

severity_icons = {
2: "material-lightning-bolt",
Expand All @@ -25,14 +27,14 @@
}


def write_rule_ref_page():
import mkdocs_gen_files

def write_rule_ref_page(path: Path | None = None):
if path is None:
path = Path(__file__).resolve().parent.parent / "rule-ref.md"
plugins = plugins_from_entry_points()

print(f"Generating rule reference for discovered plugins: {list(plugins.keys())}")

with mkdocs_gen_files.open("rule-ref.md", "w") as stream:
with StringIO() as stream:
stream.write("# Rule Reference\n\n")
stream.write(
"This page is generated from plugins discovered through the "
Expand Down Expand Up @@ -66,6 +68,14 @@ def write_rule_ref_page():
stream.write(f"- [Documentation]({plugin.meta.docs_url})\n\n")
write_plugin_rules(stream, plugin)

content = stream.getvalue()

# Avoid unnecessary preview rebuilds, and never expose a partially written page.
if not path.exists() or path.read_text(encoding="utf-8") != content:
temporary = path.with_suffix(".md.tmp")
temporary.write_text(content, encoding="utf-8")
temporary.replace(path)


def write_plugin_rules(stream, plugin: Plugin):
config_rules = get_plugin_rule_configs(plugin)
Expand Down Expand Up @@ -127,4 +137,5 @@ def get_plugin_rule_configs(plugin: Plugin) -> dict[str, dict[str, RuleConfig]]:
return config_rules


write_rule_ref_page()
if __name__ == "__main__":
write_rule_ref_page()
77 changes: 77 additions & 0 deletions docs/zensical-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Zensical migration notes

Migration and compatibility review date: **2026-11-20**.

The compatibility statements below refer to these project versions, taken from
the lockfiles before and after migration:

| Component | Before migration | After migration |
| --- | --- | --- |
| MkDocs | 1.6.1 | 1.6.1 (transitive API renderer dependency) |
| Material for MkDocs (`mkdocs-material`) | 9.8.2 | Removed |
| Zensical | Not used | 0.0.74 |
| Zensical UI | Not used | 0.0.41 |
| `mkdocs-gen-files` | 0.6.1 | Removed |
| `mkdocstrings` | 1.0.8 | 1.0.8 |
| `mkdocstrings-python` | 2.0.11 | 2.0.11 |
| `mkdocs-autorefs` | 1.4.5 | 1.4.5 (transitive API renderer dependency) |

The documentation uses `zensical.toml` and the classic theme. Build with
`pixi run docs-build` and preview with `pixi run docs-serve`.

Basic functionality is preserved: navigation, light/dark palettes, search,
icons, Markdown extensions, Python API documentation and cross-references,
the custom legal footer, self-hosted Roboto, and the generated rule catalogue.
Pixel-identical rendering and identical search rankings are not migration goals.

## Features implemented outside Zensical

| Previous integration | Replacement | Upstream limitation |
| --- | --- | --- |
| `mkdocs-gen-files` generated the rule catalogue during a build. | `docs/scripts/mkruleref.py` writes `docs/rule-ref.md` before building. The generated file is ignored by Git. | Zensical does not support `gen-files` or arbitrary MkDocs plugins. |
| A MkDocs `on_config` hook downloaded Roboto and its licence. | `docs/scripts/download_fonts.py` prepares the same self-hosted assets before build and preview, reusing downloaded files. | Zensical does not support MkDocs hooks. |
| MkDocs reran the rule generator when Python sources changed. | `docs/scripts/manage.py` polls local rule sources every 0.5 seconds and regenerates in a fresh interpreter. Zensical notices the generated Markdown and reloads the page. | There is no supported build hook for this custom generator. |

Sources: [plugin compatibility](https://zensical.org/docs/compatibility/mkdocs/plugins/)
and [migration guide](https://zensical.org/docs/compatibility/mkdocs/migration/).
Review these before replacing the wrapper with a future Zensical extension API.

## Remaining differences and improvements

- Direct `zensical build` or `zensical serve` commands bypass project preparation.
Use the Pixi tasks, especially on a clean checkout.
- Preview watches local `xrlint/**/*.py`, `docs/scripts/mkruleref.py`, and
`pyproject.toml` for rule-reference changes. Installed third-party plugins
outside this tree are discovered at generation time but are not watched.
Restart preview after installing plugins or changing external plugin sources.
- Font downloads still need network access on the first run. The downloaded
fonts and licence are reused for subsequent offline builds. This matches the
previous behavior; vendoring fonts could remove that first-run dependency.
- Search uses Zensical's native engine rather than MkDocs' Lunr engine. The site
retains full-text search, but ranking and query behavior can differ. See
[site search](https://zensical.org/docs/setup/search/).
- Template overrides run under MiniJinja rather than Python Jinja. The current
footer uses compatible constructs. Future overrides cannot call arbitrary
Python functions. See [customization](https://zensical.org/docs/customization/).
- Python API pages still use `mkdocstrings-python`. Its dependency chain retains
MkDocs and `mkdocs-autorefs`, even though Zensical builds and serves the site.
Removing those transitive dependencies depends on changes in the API renderer.

No current user-facing feature is intentionally removed. The custom generation
and font preparation are maintained here until suitable Zensical extension
support becomes available.

## Migration verification

Verified on 2026-11-20 with Zensical 0.0.74 and the versions listed above:

- The strict documentation build completes without issues.
- All configured navigation pages are generated. API headings and automatic
cross-references resolve; rule icons render as inline SVG.
- Light/dark controls, the legal footer, social links, CSS, self-hosted fonts,
and search assets are present in the generated site.
- In a running preview, temporarily editing a rule description updates both
the generated Markdown and the served rule-reference page. Restoring the
source updates both again, and stopping the wrapper cleans up the server.
- Focused tests cover rule content, avoiding unnecessary writes, detecting
source additions/changes/removals, and recovery after a generation error.
Loading
Loading