Skip to main content

sphinxcontrib.paverutils

This module provides an alternative integration of Sphinx and Paver. It supports calling Sphinx from within Paver using multiple configurations, and does not assume you only want to build HTML output.

Basic Usage

To use this module, import it in your pavement.py file as from sphinxcontrib import paverutils, then define option Bundles for “html” and/or “pdf” output using the options described in the task help.

For example:

import paver
import paver.misctasks
from paver.path import path
from paver.easy import *
import paver.setuputils
paver.setuputils.install_distutils_tasks()
try:
    from sphinxcontrib import paverutils
except:
    import warnings
    warnings.warn('sphinxcontrib.paverutils was not found, you will not be able to produce documentation')

options(
    setup=Bunch(
        name = 'MyProject',
        version = '1.0',

        # ... more options here ...
        ),

    # Defaults for sphinxcontrib.paverutils
    sphinx = Bunch(
        docroot='.',
        sourcedir='docsource',
        builder='html',
    ),

    # One configuration to build HTML for the package
    html=Bunch(
        builddir='docs',
        confdir='sphinx/pkg',
    ),

    # Another configuration with different templates
    # to build HTML to upload to the website
    website=Bunch(
        builddir = 'web',
        confdir='sphinx/web',
    ),

    # We also want a PDF file for the website,
    # so the instructions are included in the web
    # configuration directory.
    pdf=Bunch(
        builddir='web',
        builder='latex',
        confdir='sphinx/web',
    ),

)

Tasks

After you have imported sphinxcontrib.paverutils in your pavement.py file, Paver will show two additional tasks. html takes the place of the task defined in paver.doctools and can be used to build HTML output. pdf uses the LaTeX builder and an external toolset such as TeXLive to create a PDF manual.

Configuration Parameters

docroot

the root under which Sphinx will be working.

default: docs

builddir

directory under the docroot where the resulting files are put.

default: build

sourcedir

directory under the docroot for the source files

default: "" (empty string)

doctrees

the location of the cached doctrees

default: $builddir/doctrees

confdir

the location of the sphinx conf.py

default: $sourcedir

outdir

the location of the generated output files

default: $builddir/$builder

builder

the name of the sphinx builder to use

default: html

template_args

dictionary of values to be passed as name-value pairs to the HTML builder

default: {}

Advanced Usage

You can also develop your own tasks by calling run_sphinx() directly:

@task
@needs(['cog'])
@cmdopts([
    ('in-file=', 'b', 'Blog input filename'),
    ('out-file=', 'B', 'Blog output filename'),
])
def blog(options):
    """Generate the blog post version of the HTML for the current module.
    """
    # Generate html from sphinx
    paverutils.run_sphinx(options, 'blog')

    blog_file = path(options.blog.outdir) / options.blog.out_file
    dry("Write blog post body to %s" % blog_file,
        gen_blog_post,
        outdir=options.blog.outdir,
        input_base=options.blog.in_file,
        blog_base=options.blog.out_file,
        )

    if 'EDITOR' in os.environ:
        sh('$EDITOR %s' % blog_file)
    return

Cog Extensions

In addition to the html and pdf tasks, the package includes the function run_script() to be used with cog to insert the output of a command line program in your documentation.

This example of reStructuredText source using run_script():

.. {{{cog
.. cog.out(run_script(cog.inFile, 'anydbm_whichdb.py'))
.. }}}
.. {{{end}}}

renders to:

.. {{{cog
.. cog.out(run_script(cog.inFile, 'anydbm_whichdb.py'))
.. }}}

::

    $ python anydbm_whichdb.py
    dbhash

.. {{{end}}}

The lines prefixed with .. are comments, and do not appear in the final HTML or PDF output.

Arguments:

input_file

The name of the file being processed by cog. Usually passed as cog.inFile.

script_name

The name of the Python script living in the same directory as input_file to be run. If not using an interpreter, this can be a complete command line. If using an alternate interpreter, it can be some other type of file.

interpreter=’python’

The external interpreter to use for the program. Specify ‘python’, ‘python3’, ‘jython’, etc.

include_prefix=True

Boolean controlling whether the :: prefix is included. When chaining multiple commands together, the first instance would typically use the default and subsequent calls would use False.

ignore_error=False

Boolean controlling whether errors are ignored. If not ignored, the error is printed to stdout and then the command is run again with errors ignored so that the output ends up in the cogged file.

trailing_newlines=True

Boolean controlling whether the trailing newlines are added to the output. If False, the output is passed to rstrip() then one newline is added. If True, newlines are added to the output until it ends in 2.

break_lines_at=0

Integer indicating the length where lines should be broken and continued on the next line. Defaults to 0, meaning no special handling should be done.

line_break_mode=’break’

Mode to control how the line breaks are inserted. Options are:

‘break’

Insert the newline.

‘wrap’

Use the textwrap module to wrap each line individually to the specified width.

‘fill’

Use the textwrap module to wrap each line individually, inserting an appropriate amount of whitespace to keep the left edge of the lines aligned.

‘continue’

Insert a backslash (\) and then a newline to break the line.

‘truncate’

Break the line at the indicated location and discard the remainder.

Users

PyMOTW

The Python Module of the Week package is built using Paver and Sphinx, including three forms of HTML and a PDF.

virtualenvwrapper

The documentation for virtualenvwrapper includes the packaged HTML and a website using alternate templates.

History

1.6

  • include tox.ini in source dist

  • adjust interpreter for python3

  • redefine cog to allow it to run on specific input file(s)

  • compatibility with paver 1.2, and add support force a full build

1.5

Misc.

1.4

  • Add different modes for breaking lines in the output of run_script().

  • Incorporate a fix from Maciek Starzyk for issue #6 so docroot can be set to something other than ..

1.3

Added simple line-splitting to run_script().

1.2

Modified run_script() so that if ignore_error is False any exception caused by the external application is re-raised. This “breaks” a build if there is a problem generating the cog output in an rst file, and makes it easier to spot problems with the cog instructions.

1.1

Updated to include run_script() function.

1.0

First public release based on the versions of these functions developed for PyMOTW.

Metadata

Release files for sphinxcontrib-paverutils 1.18.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinxcontrib-paverutils 1.18.1
File Size Uploaded Provenance Actions
sphinxcontrib_paverutils-1.18.1.tar.gz 9.5 kB With provenance Details for sphinxcontrib_paverutils-1.18.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sphinxcontrib-paverutils 1.18.1
File Interpreter ABI Platform Actions
sphinxcontrib_paverutils-1.18.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for sphinxcontrib_paverutils-1.18.1-py2.py3-none-any.whl

Total release size: 19.8 kB

Release files / sphinxcontrib_paverutils-1.18.1.tar.gz

Download URL sphinxcontrib_paverutils-1.18.1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8abaed9b77cf1e477c647193d2eb876947dc8313ee2b6439d6fc0ffcb0552953
BLAKE2b-256 checksum
How to use checksums
6d1b0c73648b511389b68cd2c561b0372b652f7377101c77022d75c8810299ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2025.

Transparency log

Release files / sphinxcontrib_paverutils-1.18.1-py2.py3-none-any.whl

Download URL sphinxcontrib_paverutils-1.18.1-py2.py3-none-any.whl
Size 10.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c0851ae12a1915f11a895186073b403ba0a0402a05bd89db69e7dc7206f96822
BLAKE2b-256 checksum
How to use checksums
c4f1f441ce823ce7d4442f0ad19d5498992538ea24c9899a73effd927ab04f0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2025.

Transparency log

Security for sphinxcontrib-paverutils 1.18.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sphinxcontrib_paverutils-1.18.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page