sphinx-pyproject 0.3.0


pip install sphinx-pyproject

  Latest version

Released: Aug 18, 2023


Meta
Author: Dominic Davis-Foster
Requires Python: >=3.6

Classifiers

Development Status
  • 4 - Beta

Framework
  • Sphinx

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3 :: Only
  • Python :: 3.6
  • Python :: 3.7
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Documentation
  • Documentation :: Sphinx
  • Software Development :: Documentation
  • Utilities

Typing
  • Typed

Move some of your Sphinx configuration into pyproject.toml

Docs

Documentation Build Status Docs Check Status

Tests

Linux Test Status Windows Test Status macOS Test Status Coverage

PyPI

PyPI - Package Version PyPI - Supported Python Versions PyPI - Supported Implementations PyPI - Wheel

Anaconda

Conda - Package Version Conda - Platform

Activity

GitHub last commit GitHub commits since tagged version Maintenance PyPI - Downloads

QA

CodeFactor Grade Flake8 Status mypy status

Other

License GitHub top language Requirements Status

Installation

sphinx-pyproject can be installed from PyPI or Anaconda.

To install with pip:

$ python -m pip install sphinx-pyproject

To install with conda:

  • First add the required channels

$ conda config --add channels https://conda.anaconda.org/conda-forge
$ conda config --add channels https://conda.anaconda.org/domdfcoding
  • Then install

$ conda install sphinx-pyproject

Usage

The SphinxConfig class will load the configuration from pyproject.toml. By passing globalns=globals() to the class constructor, the keys parsed from the pyproject.toml file will be added to the global namespace of the conf.py file.

For example:

# conf.py

from sphinx_pyproject import SphinxConfig

config = SphinxConfig("../pyproject.toml", globalns=globals())

author  # This name *looks* to be undefined, but it isn't.

The SphinxConfig class also provides a collections.abc.Mapping interface. If you are going to override or modify one of the configuration values after parsing it, the recommended approach is to explicitly assign the name:

extensions = config["extensions"]
extensions.append("sphinx.ext.autodoc")

This will prevent warnings from linters etc., but is not necessary for Sphinx to see the configuration.

Additionally the SphinxConfig class takes an optional parameter config_overrides that can be used to dynamically update values from pyproject.toml. This can be helpful for setting dynamic values like version.

# conf.py
from sphinx_pyproject import SphinxConfig

from myproject import __version__ as myproject_version

config = SphinxConfig("../pyproject.toml", globalns=globals(), config_overrides = {"version": myproject_version})

Configuration

sphinx-pyproject parses the configuration from the [project] and [tool.sphinx-pyproject] tables in pyproject.toml. The [project] table is defined in PEP 621. sphinx-pyproject only uses the following keys:

The remaining Sphinx configuration values can be provided in the [tool.sphinx-pyproject] table.

See this project’s pyproject.toml file for an example of this configuration.

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras: None
Dependencies:
dom-toml (>=0.3.0)
domdf-python-tools (>=2.7.0)