Skip to main content

Additions to Sybil, the documentation testing tool.

Project description

Build Status codecov PyPI

sybil-extras

Add ons for Sybil.

Installation

$ pip install sybil-extras

Usage

MultiEvaluator

"""Use MultiEvaluator to run multiple evaluators on the same parser."""

from sybil import Example, Sybil
from sybil.evaluators.python import PythonEvaluator
from sybil.parsers.rest.codeblock import CodeBlockParser
from sybil.typing import Evaluator

from sybil_extras.evaluators.multi import MultiEvaluator


def _evaluator_1(example: Example) -> None:
    """Check that the example is long enough."""
    minimum_length = 50
    assert len(example.parsed) >= minimum_length


evaluators: list[Evaluator] = [_evaluator_1, PythonEvaluator()]
multi_evaluator = MultiEvaluator(evaluators=evaluators)
parser = CodeBlockParser(language="python", evaluator=multi_evaluator)
sybil = Sybil(parsers=[parser])

pytest_collect_file = sybil.pytest()

ShellCommandEvaluator

"""Use ShellCommandEvaluator to run shell commands against the code block."""

import sys

from sybil import Sybil
from sybil.parsers.rest.codeblock import CodeBlockParser

from sybil_extras.evaluators.shell_evaluator import ShellCommandEvaluator

evaluator = ShellCommandEvaluator(
    args=[sys.executable, "-m", "mypy"],
    # The code block is written to a temporary file
    # with these suffixes.
    tempfile_suffixes=[".example", ".py"],
    # Pad the temporary file with newlines so that the
    # line numbers in the error messages match the
    # line numbers in the source document.
    pad_file=True,
    # Don't write any changes back to the source document.
    # This option is useful when running a linter or formatter
    # which modifies the code.
    write_to_file=False,
    # Use a pseudo-terminal for running commands.
    # This can be useful e.g. to get color output, but can also break
    # in some environments.
    use_pty=True,
)
parser = CodeBlockParser(language="python", evaluator=evaluator)
sybil = Sybil(parsers=[parser])

pytest_collect_file = sybil.pytest()

CustomDirectiveSkipParser

"""Use CustomDirectiveSkipParser to skip code blocks with a custom marker."""

from sybil import Sybil
from sybil.parsers.rest.codeblock import PythonCodeBlockParser

# Similar parsers are available at
# sybil_extras.parsers.markdown.custom_directive_skip and
# sybil_extras.parsers.myst.custom_directive_skip.
from sybil_extras.parsers.rest.custom_directive_skip import (
    CustomDirectiveSkipParser,
)

skip_parser = CustomDirectiveSkipParser(directive="custom-marker-skip")
code_block_parser = PythonCodeBlockParser()

sybil = Sybil(parsers=[skip_parser, code_block_parser])

pytest_collect_file = sybil.pytest()

This allows you to skip code blocks in the same way as described in the Sybil documentation for skipping examples in reStructuredText, Markdown , and MyST files, but with custom text, e.g. custom-marker-skip replacing the word skip.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sybil_extras-2024.12.26.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sybil_extras-2024.12.26-py2.py3-none-any.whl (12.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sybil_extras-2024.12.26.tar.gz.

File metadata

  • Download URL: sybil_extras-2024.12.26.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for sybil_extras-2024.12.26.tar.gz
Algorithm Hash digest
SHA256 2fe858c1dac043d27d1d8d830e7fb6266f18dd0dbd859b71b82effb865dbaa4e
MD5 427d2f7218a6394c52ae9d629cc33268
BLAKE2b-256 c46ff1dea018154311a3c898c5508d6c1b500287b28e6cec608cdf5c6b06a4e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for sybil_extras-2024.12.26.tar.gz:

Publisher: release.yml on adamtheturtle/sybil-extras

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sybil_extras-2024.12.26-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sybil_extras-2024.12.26-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5f31919dbfd7f5d4eb14ea92d1b92e06e9d665c1d7b3d67ebcea163c1478388f
MD5 cec76588976a41d6e7bc5451b2804d58
BLAKE2b-256 8517797ffd72a4bbbc562e4c8d9459bf198a469591033639c32ca2bc2a193189

See more details on using hashes here.

Provenance

The following attestation bundles were made for sybil_extras-2024.12.26-py2.py3-none-any.whl:

Publisher: release.yml on adamtheturtle/sybil-extras

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page