close
Skip to content

Repository files navigation

gp-libs · Python Package License Code Coverage

Sphinx extensions and pytest plugins shared across git-pull's projects, developed by dogfooding them on cihai, vcs-python, and tmux-python.

doctest for reStructured and markdown

Two components:

  1. doctest_docutils module: Same specification as doctest, but can parse reStructuredText and markdown

  2. pytest_doctest_docutils: Pytest plugin, collects test items for pytest for reStructuredText and markdown files

    This means you can do:

    $ pytest docs

doctest module

This extends standard library doctest to support anything docutils can parse. It can parse reStructuredText (.rst) and markdown (.md).

See more: https://gp-libs.git-pull.com/modules/doctest_docutils/

Supported styles

It supports two barebones directives:

  • docutils' doctest_block

    >>> 2 + 2
    4
  • .. doctest:: directive

    reStructuredText:

    .. doctest::
    
       >>> 2 + 2
       4

    Markdown:

    ```{doctest}
    >>> 2 + 2
    4
    ```

Usage

The doctest_docutils module preserves standard library's usage conventions:

reStructuredText
$ python -m doctest_docutils README.rst -v

That's what doctest does by design.

Markdown

Markdown files run through myst-parser, which is installed with gp-libs.

$ python -m doctest_docutils README.md -v

pytest plugin

This plugin blocks pytest's standard doctest plugin.

This plugin integrates doctest_docutils with pytest so documentation examples run with the surrounding conftest.py setup.

$ pytest docs/

Like the above module, it supports docutils' own doctest_block and a basic .. doctest:: directive.

See more: https://gp-libs.git-pull.com/modules/pytest_doctest_docutils/

sphinx plugins

Plain-text issue linker (linkify-issues)

linkify_issues turns a plain-text issue reference, e.g. #99999, into a link to the project tracker at https://github.com/git-pull/gp-libs/issues/99999. The source text stays plain, so it still reads correctly wherever it is rendered unprocessed, including GitHub and GitLab.

Configuration

In your conf.py:

  1. Add 'linkify_issues' to extensions

    extensions = [
        # ...
        "linkify_issues",
    ]
  2. Configure your issue URL, issue_url_tpl:

    # linkify_issues
    issue_url_tpl = "https://github.com/git-pull/gp-libs/issues/{issue_id}"

    The config variable is formatted via str.format() where issue_id is 42 if the text is #42.

See more: https://gp-libs.git-pull.com/modules/linkify_issues/

Install

$ pip install --user gp-libs

Developmental releases

You can test the unpublished version of gp-libs before it's released.

  • pip:

    $ pip install --user --upgrade --pre gp-libs

Minimum requirements

To lift the development burden of supporting legacy APIs, as this package is lightly used, a minimum constraint is pinned in pyproject.toml:

  • docutils: 0.20+

myst-parser has no minimum version pinned. If you have a passing interest in supporting legacy versions, file an issue on the tracker.

More information

Docs Build Status

About

Incubator for pytest and sphinx helpers for git-pull python projects

Topics

Resources

Contributing

Stars

3 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages