Skip to content
Merged
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
90 changes: 90 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Build the reference and publish it to GitHub Pages.
#
# The site at https://scattercode.github.io/sillybos/ is the README followed
# by the API and command line reference, generated by Sphinx from docs/ and
# the package's docstrings (docs/conf.py). Every push to main builds it and
# deploys it with the official Pages flow (upload-pages-artifact, then
# deploy-pages from a job of its own): no gh-pages branch, nothing committed.
# A pull request runs the build alone, with warnings as errors, so a
# docstring that renders badly fails the review rather than main.
#
# Publishing needs the repository's Pages source set to "GitHub Actions"
# (Settings > Pages > Build and deployment), once, by hand. Until it is, the
# deploy job fails and says so; the build job reports regardless.
#
# The version in the page title comes from hatch-vcs. A merge that cuts no
# release (docs, ci, chore) therefore publishes as X.Y.Z.devN until the
# release commit for the next one lands, which is the honest reading of
# main at that moment; docs/conf.py says why the .devN is kept.
name: Docs

on:
push:
branches: [main]
# No path filter on pull_request: a required check that is filtered out
# never starts, so never reports, and leaves the pull request blocked.
pull_request:
workflow_dispatch:

# Granted per job below, not here: only the deploy job needs more than read.
permissions: {}

# Two regimes in one expression. Deploying runs share one serialised group
# with no cancellation, so a deploy is never killed mid-flight. Pull-request
# builds deploy nothing and get a per-ref group with cancellation, so a
# review-fix push stops the superseded build instead of paying for it.
concurrency:
group: ${{ github.event_name == 'pull_request' && format('docs-{0}', github.ref) || 'pages' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
name: Build the docs
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
# hatch-vcs derives the version from `git describe --tags`, and
# the page title carries it. A shallow clone has no tags
# reachable and the site would call itself 0.1.dev1.
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-python@v7
with:
python-version: "3.12"

- name: Install the package with the docs extra
run: pip install -e '.[docs]'

# -W makes every warning a failure; --keep-going reports them all
# rather than stopping at the first.
- name: Build
run: sphinx-build -W --keep-going -b html docs docs/_build/html

# The artifact is what deploy-pages publishes. actions/configure-pages
# is left out on purpose: it only sets outputs for static site
# generators that need the site's base path, which Sphinx does not,
# and it would need Pages permissions on a job that otherwise reads.
- uses: actions/upload-pages-artifact@v5
if: github.event_name != 'pull_request'
with:
path: docs/_build/html

deploy:
name: Deploy to GitHub Pages
needs: build
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v5
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ htmlcov/
# Written at build time by hatch-vcs; the version lives in the git tag.
src/sillybos/_version.py

# Sphinx output (docs/)
/docs/_build/

# OS
.DS_Store
11 changes: 9 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ in `SECURITY.md`.
headings. Docs in the first person plural: this is a collaborative
project.
- The checks: `ruff check .`, `ruff format --check .`, `mypy`, `pytest --cov`
(floor in `pyproject.toml`), `uv lock --check`. The Ruff set includes the
`S` (bandit) rules; an ignore needs a reason beside it.
(floor in `pyproject.toml`), `uv lock --check`, and
`sphinx-build -W -b html docs docs/_build/html` with the `docs` extra.
The Ruff set includes the `S` (bandit) rules; an ignore needs a reason
beside it.
- The reference site (`docs/`, published to GitHub Pages on merge) is the
README, included between its two `docs:` comment markers, plus the API
and command line generated from the docstrings. Document the API in the
docstrings, Google style with reStructuredText cross-references; never
copy it into a page by hand.
- Conventional Commits, enforced by `.githooks/commit-msg` (shared from
`scattercode/release-pipelines`; do not edit the copy). `fix` → patch,
`feat` → minor, `!` → major. Releases are automatic on merge to `main`:
Expand Down
20 changes: 18 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ same as here, stated for an agent.

```bash
uv venv .venv && source .venv/bin/activate
uv pip install -e '.[dev]'
uv pip install -e '.[dev,docs]'
```

(`python -m venv` and `pip` work too.) The PDF tests need `pdfinfo` from
poppler (`brew install poppler`, `apt install poppler-utils`) and skip
without it. Then activate the git hooks, one of:
without it. The `docs` extra is Sphinx and its theme, for the reference
site; leave it out if you are not touching the docs. Then activate the git
hooks, one of:

```bash
lefthook install # if you have lefthook (brew install lefthook gitleaks zizmor)
Expand All @@ -55,6 +57,7 @@ ruff format --check .
mypy
pytest --cov
uv lock --check # the lockfile matches pyproject.toml
sphinx-build -W -b html docs docs/_build/html # the docs, with the docs extra
gitleaks git --no-banner --redact . # secrets in the history
uvx zizmor --min-severity medium .github/workflows
```
Expand All @@ -64,6 +67,19 @@ is declared explicitly in `pyproject.toml` and includes the `S` (bandit)
rules; an ignore needs a dated reason beside it. Coverage must stay at or
above the floor in `pyproject.toml`.

## The docs

The reference site at <https://scattercode.github.io/sillybos/> is built by
Sphinx from `docs/` and published by `docs.yml` on every push to `main`. It
is the README (included, not copied, between the two `docs:` comment
markers) followed by the API and the command line, generated from the
docstrings and the parser. There is nothing to write by hand when the API
changes: the docstrings are the reference, in Google style with
reStructuredText cross-references (`:class:`, `:func:`, `:data:`), and a
docstring that does not render is a build failure, since the build runs
with warnings as errors on every pull request. Build it locally with the
command above and open `docs/_build/html/index.html`.

## Dependencies and the lockfile

The package has no runtime dependencies, and that is deliberate. The
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# sillybos

**📖 [Documentation and API reference](https://scattercode.github.io/sillybos/)**

<!-- docs: include from here -->
<img src="https://raw.githubusercontent.com/scattercode/sillybos/main/docs/logo.png" alt="A rolled scroll with a small parchment tag hanging from it, reading: metadata, caps and format vetted" width="280" align="right">

**Decide before decoding.** A σίλλυβος (*sillybos*; Latin *sittybus*) was
Expand Down Expand Up @@ -207,6 +210,8 @@ Say this plainly, because a security library carries an implied promise.
the rest are refused by name until someone shows a scan in one. Each
format added is attack surface added.

<!-- docs: include to here -->

## Development

```bash
Expand Down
65 changes: 65 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# API reference

Everything the package exports, generated from the docstrings. The
[policy table](index.md#the-policy) says what each limit bounds and why.

```{eval-rst}
.. automodule:: sillybos
```

## The check

```{eval-rst}
.. autofunction:: sillybos.check

.. autofunction:: sillybos.require

.. autoclass:: sillybos.Verdict
:members:

.. autoclass:: sillybos.Facts

.. autoexception:: sillybos.Refused

.. autoexception:: sillybos.pdf.PdfInfoMissing
```

## The policy

```{eval-rst}
.. autoclass:: sillybos.Policy
:members:

.. autodata:: sillybos.DEFAULT
:no-value:

.. autodata:: sillybos.STRICT
:no-value:
```

## The names

What a policy's fields and a verdict's facts are spelt with. Each tuple is
every name the library knows, in the order the reasons list them; a policy
chooses from it.

```{eval-rst}
.. autodata:: sillybos.FORMATS

.. autodata:: sillybos.JPEG_FRAMES

.. autodata:: sillybos.PNG_COLOUR_TYPES

.. autodata:: sillybos.TIFF_COMPRESSIONS

.. autodata:: sillybos.TIFF_PHOTOMETRICS

.. autodata:: sillybos.TIFF_SUBSAMPLINGS
```

## With Pillow

```{eval-rst}
.. automodule:: sillybos.pillow
:members:
```
14 changes: 14 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Command line reference

Every flag of the `sillybos` command, generated from its parser. The
[README](index.md#the-command) shows what a run looks like.

```{eval-rst}
.. automodule:: sillybos.cli
```

```{argparse}
:module: sillybos.cli
:func: build_parser
:prog: sillybos
```
104 changes: 104 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""Sphinx configuration for the sillybos reference.

Published to GitHub Pages at https://scattercode.github.io/sillybos/ by
.github/workflows/docs.yml on every push to main. The site is the README
(what the library is, how to install and use it, the policy table, what it
does and does not do), included rather than copied, followed by the API and
command line reference generated from the code. The docstrings are the one
place the API is described; this file only arranges them.

Same arrangement as the Tetrak reference (scattercode/tetrak, docs/conf.py):
furo, autodoc with napoleon, MyST for the Markdown pages, sphinx-argparse for
the command.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from sphinx.pycode import ModuleAnalyzer

if TYPE_CHECKING:
from sphinx.application import Sphinx

project = "sillybos"
copyright = "2026, Stephen Masters, Yvette Mankerian"
author = "Stephen Masters, Yvette Mankerian"

try:
from sillybos._version import version as release
except ImportError: # a bare checkout, not yet built with hatch-vcs
release = "0.0.0"

# Sphinx's default page title is "{project} {release} documentation", and
# hatch-vcs derives `release` from git describe -- so on any commit that is
# not exactly a tag it carries PEP 440 build metadata: "2.0.1.dev2+g9f4085a".
# The segment after "+" is the commit hash, which is noise in a browser tab.
#
# Stripped for display only. The `.devN` part stays: it is the honest signal
# that a build came from an untagged commit, and hiding it would let the docs
# claim a version that was never released. A release build has neither part
# and reads simply "sillybos 2.0.0 documentation".
version = release.split("+", 1)[0]
html_title = f"{project} {version} documentation"

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"sphinxarg.ext",
"myst_parser",
]

autodoc_member_order = "bysource"
# Show a default as the source spells it. Every function takes
# ``policy: Policy = DEFAULT``, and the evaluated default is the whole
# Policy(...) repr, twenty fields long, in every signature.
autodoc_preserve_defaults = True
napoleon_google_docstring = True
napoleon_numpy_docstring = True

source_suffix = {".rst": "restructuredtext", ".md": "markdown"}
# The pages link to headings on other pages (`index.md#the-policy`). MyST
# only resolves those when it generates anchors for headings; three levels
# covers every heading the README has.
myst_heading_anchors = 3
root_doc = "index"
exclude_patterns = ["_build"]

html_theme = "furo"
html_logo = "logo.png"
html_theme_options = {
"source_repository": "https://github.com/scattercode/sillybos",
"source_branch": "main",
"source_directory": "docs/",
}

# The name tuples (FORMATS, JPEG_FRAMES, ...) and the presets DEFAULT and
# STRICT are defined in sillybos.policy, with their docstrings beside the
# assignments, and re-exported from the package. api.md documents them under
# the name a reader imports, sillybos.FORMATS, which is also what the
# cross-references in the docstrings use. autodoc, though, looks for an
# attribute's docstring only in the module named in the directive, finds
# nothing in sillybos/__init__.py, and falls back to the docstring of the
# value's type ("Built-in immutable sequence ..."). This reads it from where
# it is written instead.
_DATA_DEFINED_IN = {"sillybos": "sillybos.policy"}


def _data_docstring(
app: Sphinx, what: str, name: str, obj: object, options: Any, lines: list[str]
) -> None:
modname, _, attr = name.rpartition(".")
defined_in = _DATA_DEFINED_IN.get(modname)
if what != "data" or defined_in is None:
return
analyzer = ModuleAnalyzer.for_module(defined_in)
analyzer.analyze()
doc = analyzer.attr_docs.get(("", attr))
if doc is not None:
lines[:] = list(doc)


def setup(app: Sphinx) -> None:
app.connect("autodoc-process-docstring", _data_docstring)
21 changes: 21 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# sillybos

```{include} ../README.md
:start-after: <!-- docs: include from here -->
:end-before: <!-- docs: include to here -->
```

```{toctree}
:caption: Reference
:maxdepth: 2

api
cli
```

```{toctree}
:caption: Project
:maxdepth: 1

advisories/README
```
Loading
Loading