update-plugin-list.py


Overview

`update-plugin-list.py` is a utility script designed to automate the retrieval, processing, and generation of a comprehensive list of `pytest` plugins available on PyPI. It fetches plugin metadata from the PyPI JSON API, filters and organizes the data, and then outputs a reStructuredText (RST) formatted file (`plugin_list.rst`) that documents available plugins, their statuses, last release dates, and dependency requirements.

This script is typically run on a weekly basis (often via a GitHub Action) to keep the plugin list up-to-date for inclusion in the official pytest documentation.


Functionality Summary


Detailed Explanation of Components

Constants


Functions

escape_rst(text: str) -> str

Escapes special reStructuredText characters in a string to prevent unwanted formatting when rendered.


project_response_with_refresh(session: CachedSession, name: str, last_serial: int) -> OriginalResponse | CachedResponse

Fetches the PyPI JSON metadata for a project by name, using the cached session. If the cached response's "last serial" value differs from the provided `last_serial`, forces a refresh to get the latest data.


get_session() -> CachedSession

Creates and configures a `CachedSession` using `requests-cache` with an SQLite backend, storing cached HTTP responses in the user's cache directory (`~/.cache/pytest-plugin-list/http_cache.sqlite3`).


pytest_plugin_projects_from_pypi(session: CachedSession) -> dict[str, int]

Retrieves all PyPI projects from the simple API endpoint, filtered to those whose names start with `pytest-` or `pytest_` or are in `ADDITIONAL_PROJECTS`. Returns a dictionary mapping project names to their last serial number.


TypedDict

PluginInfo

A typed dictionary representing the key metadata fields tracked for each plugin.

Field

Type

Description

`name`

str

PyPI project name formatted as an RST link.

`summary`

str

Short description of the project.

`last_release`

str

Date of the most recent release (e.g., "Jan 01, 2024").

`status`

str

Development status extracted from classifiers.

`requires`

str

The required pytest version or requirement string.


Iterator / Generators

iter_plugins() -> Iterator[PluginInfo]

Main generator function that:

  1. Creates a cached HTTP session.

  2. Retrieves plugin projects and their last serials.

  3. Iterates over each project, fetching detailed JSON metadata.

  4. Skips 404 responses and inactive projects.

  5. Extracts relevant metadata (status, last release date, requirements).

  6. Yields PluginInfo dictionaries for each valid plugin.


Output Generation

plugin_definitions(plugins: Iterable[PluginInfo]) -> Iterator[str]

Generates a detailed RST block for each plugin formatted to fit better on vertical (PDF) pages.


Main Entrypoint

main() -> None

Coordinates the overall workflow:

  1. Calls iter_plugins to collect all plugin metadata.

  2. Determines output directory doc/en/reference.

  3. Writes plugin_list.rst with header, plugin count, and plugin data.

  4. Writes two formats:

    • A table (using tabulate) for non-LaTeX outputs.

    • Detailed definitions for LaTeX outputs.

  5. Ensures the wcwidth import is referenced for tabulate compatibility.


Implementation Details and Algorithms


Interactions with Other System Components


File Structure and Workflow Diagram

flowchart TD
    A[Start: main()] --> B[iter_plugins()]
    B --> C[get_session()]
    C --> D[pytest_plugin_projects_from_pypi()]
    D --> E[For each plugin project]
    E --> F[project_response_with_refresh()]
    F --> G{Is status 404?}
    G -- Yes --> E
    G -- No --> H{Is plugin inactive?}
    H -- Yes --> E
    H -- No --> I[Extract metadata: status, summary, requires, last_release]
    I --> J[Yield PluginInfo dict]
    J --> E
    E --> K[Collect all PluginInfo into list]
    K --> L[Generate RST output]
    L --> M[Write plugin_list.rst]
    M --> N[End]

    style B fill:#f9f,stroke:#333,stroke-width:2px
    style L fill:#bbf,stroke:#333,stroke-width:2px

Summary

`update-plugin-list.py` is a specialized utility that automates the discovery and documentation of pytest plugins on PyPI. It efficiently queries, caches, filters, and formats plugin metadata into a maintainable, human-readable RST file for official pytest documentation. Its use of caching, version parsing, and careful output formatting makes it a robust and maintainable tool for keeping the plugin list current.


Appendix: Example Usage

Run the script directly to update the plugin list:

python update-plugin-list.py

This will create or update `doc/en/reference/plugin_list.rst` with the latest plugin data.


End of Documentation for update-plugin-list.py