Contributing

This page provides a guide for developers wishing to contribute to Sphinx-Needs.

Bugs, Features and PRs

For bug reports and well-described technical feature requests, please use our issue tracker:
https://github.com/useblocks/sphinx-needs/issues

For feature ideas and questions, please use our discussion board:
https://github.com/useblocks/sphinx-needs/discussions

If you have already created a PR, you can send it in. Our CI workflow will check (test and code styles) and a maintainer will perform a review, before we can merge it. Your PR should conform with the following rules:

  • A meaningful description or link, which describes the change

  • The changed code (for sure :) )

  • Test cases for the change (important!)

  • Updated documentation, if behavior gets changed or new options/directives are introduced.

  • Update of docs/changelog.rst.

  • If this is your first PR, feel free to add your name in the AUTHORS file.

Pull requests are written by people. A pull request that was generated automatically from an issue – opened by an account that has not read the code, run the tests or taken part in the discussion, typically within hours of the issue being filed – is closed without review, whatever its content. We cannot tell a good one from a bad one without the full review a change of our own would get, and its author knows nothing of the tools this repository serves or of where the change sits in our plans. Using an AI assistant for your own work is fine: you have read the change, you have tested it, and you answer for it. Say so in the pull request template.

Installing Dependencies

To develop Sphinx-Needs, use uv to install the project and its development dependencies into an isolated environment:

uv sync

Note

Run it from the repository root. This repository is a uv workspace: the test tooling is a dependency group of the workspace root, which is included in the root’s default dev group, so no group has to be named. Syncing from inside packages/sphinx-needs instead installs the package alone, without pytest.

The interpreter comes from the .python-version file at the repository root, so every contributor gets the same one; uv downloads it if the machine does not have it. If you use pyenv, run pyenv install 3.13 once, or its shims will report the version as missing inside this repository.

uv.lock is committed, so uv sync installs exactly the versions recorded in it, and every contributor and CI job gets the same environment. If you change the dependencies in pyproject.toml, the uv-lock hook below updates the lock for you (uv lock does the same by hand); commit the result with your change. Dependabot refreshes the locked versions once a month: minor and patch updates arrive batched in one pull request, major updates one pull request each.

To run the formatting and linting suite, prek is used:

uv run prek install  # to auto-run on every commit
uv run prek run --all-files  # to run manually

The hooks are declared in .pre-commit-config.yaml, which prek reads unchanged, so pre-commit itself still works if you prefer it.

Hook versions are bumped by the scheduled Prek update workflow, which opens a pull request with the new revisions.

Testing and documentation building are run as poe tasks, declared in pyproject.toml:

uv run poe  # to see all tasks

Words written after a task name are appended to the command it runs, so pytest and sphinx-build options can be passed straight through. A task that needs something other than the default environment — one sphinx version, a documentation theme — installs into its own .venvs/ directory, so tasks do not overwrite each other’s environment. uv run poe typecheck is one of those tasks: it installs the typing dependency group — the oldest supported Sphinx and Docutils, plus ty itself — into .venvs/typing and checks against it, which is what CI and the prek ty hook do too. Running ty by hand, or through an editor extension, uses .venvs/typing as well, because [tool.ty.environment] python names it; run the task once to create it.

Set UV_PYTHON to choose the interpreter a task runs on, for example UV_PYTHON=3.12 uv run --no-sync poe test-needs-sphinx8. uv downloads an interpreter it does not have, so no separate version manager is needed. Give the outer uv run the --no-sync flag in that form: without it, uv also rebuilds the default .venv on that interpreter (uv sync --python 3.13 puts it back).

Build docs

To build the Sphinx-Needs documentation stored under /packages/sphinx-needs/docs, run:

# Build HTML pages with the furo theme
uv run poe docs-needs

# ... and first remove all old build files
uv run poe docs-needs-clean

The other themes have a task each — docs-needs-alabaster, docs-needs-im, docs-needs-pds and docs-needs-rtd — and the link checker is its own task:

# Check links in the documentation
uv run poe docs-needs-linkcheck

Running Tests

Run the tests against the newest supported sphinx with:

uv run poe test-needs

The CI matrix tests three sphinx versions, and each is a task of its own — test-needs-sphinx7, test-needs-sphinx8, test-needs-sphinx9. Every one of them is exactly what CI runs, so a failing cell can be reproduced locally:

UV_PYTHON=3.12 uv run --no-sync poe test-needs-sphinx8 tests/test_basic_doc.py

Note some tests use syrupy to perform snapshot testing. These snapshots can be updated by running:

uv run poe test-needs --snapshot-update

Running the browser tests

The tests marked jstest drive a real browser through pytest-playwright; poe test-needs excludes them. The browser binary is not a Python package, so download it once per machine:

uv run poe install-browser

That is playwright install chromium, which lands in ~/.cache/ms-playwright (~/Library/Caches/ms-playwright on macOS), or in PLAYWRIGHT_BROWSERS_PATH if your environment sets one – some prepared container images do, and then a browser they baked in is only found if its revision is the one this playwright pins. Then:

uv run poe test-needs-js

To skip the download altogether and drive a Chrome that is already on the machine, pass pytest-playwright’s own flag: uv run poe test-needs-js --browser-channel chrome.

A browser test builds its project with the usual test_app fixture, opens the built page over file:// – nothing on the page fetches, so no server is involved – and asserts on it with Playwright’s expect:

# tests/test_sn_collapse_button.py

from pathlib import Path

import pytest
from playwright.sync_api import Page, expect


@pytest.mark.jstest
@pytest.mark.parametrize(
    "test_app",
    [{"buildername": "html", "srcdir": "doc_test/doc_basic"}],
    indirect=True,
)
def test_something(test_app, page: Page):
    test_app.build()
    page.goto(Path(test_app.outdir, "index.html").as_uri())
    expect(page.locator("table.need")).to_have_count(2)  # locators are sets

Register page.on("pageerror", ...) before page.goto if the test should also assert that the page raised nothing.

The tests are not in the source distribution

The sdist on PyPI carries the package and its documentation, and nothing else. The suite lives in this repository: it loads its fixtures from sphinx-needs-testkit, a workspace member classified Private :: Do Not Upload that is on no index, so a copy of tests/ inside a tarball could not be run from it anyway — shipping one would only look runnable.

Run it from a repository checkout instead — uv sync --frozen, then uv run poe test-needs, which installs the testkit out of the workspace for you. From a source snapshot with no uv (a GitHub tag tarball, or a distribution’s own copy of one) install the package and the testkit from the tree itself, then add the rest of the root’s test dependency group by name; that group lists the testkit as a bare requirement, so pip install --group test on its own would go looking for it on an index and fail. Either way the machine needs graphviz’s dot and a PlantUML renderer — the pinned jar is committed at vendor/plantuml/, so a repository snapshot already carries it — because the tests that need them assert rather than skip:

pip install ./packages/sphinx-needs ./packages/sphinx-needs-testkit
pytest packages/sphinx-needs/tests

Benchmarks

Every push to master runs the Benchmark workflow, which records three numbers: the build time of a small project and of Sphinx-Needs own documentation, and the peak memory of the latter’s build.

A build time is the fastest of several builds, each with a fresh environment, with no PlantUML diagram rendered: a diagram is a Java process of about two seconds, which used to be three quarters of the documentation’s build time and most of its variation between runners. The diagrams are still parsed and their sources generated.

The workflow fails when a number is more than 30% worse (10% for memory) than the median of its last ten results. CI runners come in several speeds, so a build time is only compared with results measured on the same CPU model.

Benchmark test cases are available under tests/benchmarks.

The results for each PR/commit get added to a chart, which is available under http://useblocks.com/sphinx-needs/bench/index.html.

The benchmark data is stored on the benchmarks branch, which is also used by github-pages as source.

Publishing a new release

This repository is a workspace, and every distribution under packages/ releases independently. One workflow, .github/workflows/release.yaml, serves all of them, and the tag says which: it must read <distribution>-v<version>, so sphinx-needs-v8.6.0. No other tag triggers it, and a tag that names no distribution in the workspace is refused before anything is built.

Before either step, ask what is pending:

uv run poe release-plan

That prints, for every distribution the workspace publishes, its last release tag, what PyPI has, the commits since that tag that touched the code it ships, and — where one package depends on another — which check would stop a release of the dependant, or the version the release workflow’s compatibility check would install from PyPI. Then a suggested order, with the commands. It is advice, not a gate: it exits 0 whatever it finds.

uv run python tools/src/sn_tools/import_check.py <dist> (for sphinx-needs, uv run poe import-check-needs) is the companion question for a package that depends on another one in this workspace. It builds that package’s wheel and installs it into a throwaway environment outside this project, so uv resolves the wheel’s own dependencies from PyPI and every sibling arrives as published, then imports every module of it — which answers “is a name missing?” in seconds, where the compatibility check takes minutes.

A release is two steps, a pull request and a tag.

The pull request bumps the version and stamps the changelog. From master, with a clean tree and from the repository root:

uv version --package sphinx-needs --bump patch --no-sync
uv lock

--no-sync matters: --frozen would leave uv.lock claiming the old version, and a bare uv version --bump re-resolves the whole lock from scratch. Then update the two numbers uv version does not touch — __version__ in packages/sphinx-needs/src/sphinx_needs/__init__.py, which is written into every generated needs.json, and the NEEDS_VERSION fallback in .github/workflows/docker.yaml, which becomes sphinx-needs-v<version> — and add the changelog entry in docs/changelog.rst (the _release:<version> label, the heading, :Released:, the :Full Changelog: compare link and a summary paragraph). uv run poe lint fails if the version and __version__ disagree.

Once that pull request is merged, push the tag from master:

git tag sphinx-needs-v8.6.0
git push origin sphinx-needs-v8.6.0

The workflow then validates the tag against the tree, builds the wheel and the source distribution, resolves the built wheel against PyPI alone, runs the test suite against the dependencies as they are published rather than as they are in this repository, uploads to PyPI with trusted publishing (OIDC — the workflow holds no API token), and creates the GitHub Release. For sphinx-needs it also pushes a second, bare 8.6.0 tag, which is the one Read the Docs and any git+…@8.6.0 requirement use.

To rehearse the pipeline without publishing anything, run the workflow by hand: gh workflow run release.yaml -f tag=sphinx-needs-v8.6.0. The publish job only runs for a real tag push, so a manual run stops after the build and the checks.

Maintainers

Daniel Woste <daniel@useblocks.com>

Chris Sewell <chrisj_sewell@hotmail.com>

Contributors

Marco Heinemann <marco@useblocks.com>

Trevor Lovett <trevor.lovett@gmail.com>

Magnus Lööf <magnus.loof@gmail.com>

Harri Kaimio

Anders Thuné

Daniel Eades <danieleades@hotmail.com>

Philip Partsch <philip.partsch@googlemail.com>

David Le Nir <david.lenir.e@thalesdigital.io>

Baran Barış Yıldızlı <arisbbyil@gmail.com>

Roberto Rötting <roberto.roetting@gmail.com>

Nirmal Sasidharan <nirmal.sasidharan@de.bosch.com>

Jacob Allen <jacob.allen@etas.com>

Jörg Kreuzberger <j.kreuzberger@procitec.de>

Duodu Randy <duodurandy19@gmail.com>

Christian Wappler <chri.wapp@gmail.com>

Simon Leiner <simon@leiner.me>