Skip to content

API

Pyrig plugin for generating a project's logo, banner, and badge configuration.

rig

Pyrig runtime integration for the badge plugin.

configs

Configuration managers that add project badges to generated files.

base

Shared base configuration classes for badge-enabled files.

badges

Badge-augmented Markdown configuration base class.

BadgesConfigFile

Bases: BadgesConfigFile

Add the generated project banner before the base class's badge groups.

badges_content
badges_content() -> str

Return the project banner followed by the generated badge groups.

Returns:

Type Description
str

Markdown containing the banner image and the base badge content.

Source code in src/pyrig_badge/rig/configs/base/badges.py
    def badges_content(self) -> str:
        """Return the project banner followed by the generated badge groups.

        Returns:
            Markdown containing the banner image and the base badge content.
        """
        return f"""{self.logo_content()}

{super().badges_content()}"""
image_path
image_path() -> Path

Return the configured banner file's path.

Returns:

Type Description
Path

Path to the project's banner asset.

Source code in src/pyrig_badge/rig/configs/base/badges.py
def image_path(self) -> Path:
    """Return the configured banner file's path.

    Returns:
        Path to the project's banner asset.
    """
    return BannerConfigFile.I.path()
logo_content
logo_content() -> str

Return a linked Markdown image for the project's banner.

Returns:

Type Description
str

Markdown linking the banner image to its own file, using the

str

project name as its alternative text.

Source code in src/pyrig_badge/rig/configs/base/badges.py
def logo_content(self) -> str:
    """Return a linked Markdown image for the project's banner.

    Returns:
        Markdown linking the banner image to its own file, using the
        project name as its alternative text.
    """
    image_path = self.image_path().as_posix()
    return f"[![{PackageManager.I.project_name()}]({image_path})]({image_path})"
svg

Base class for managing dictionary-backed SVG configuration files.

SVGConfigFile

Bases: XMLConfigFile

Manage SVG files using the XML configuration lifecycle.

extension
extension() -> str

Return the SVG file extension without a leading dot.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def extension(self) -> str:
    """Return the SVG file extension without a leading dot."""
    return "svg"
height
height() -> str

Return the stored SVG height, or "200" if absent.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def height(self) -> str:
    """Return the stored SVG height, or `"200"` if absent."""
    return self.safe_load_svg().get("@height", "200")
insert_svg
insert_svg(svg: type[SVGConfigFile]) -> dict[str, Any]

Return svg's content as a nested <svg> element.

The nested element mirrors the loaded root of svg, including its attributes and children, so this SVG is self-contained and changes to svg propagate on sync. Its width, height, and viewBox are svg's values, and its x and y place it at this SVG's viewBox origin plus half the remaining space, rounded down to integers; these five attributes override any same-named attributes of svg. The inserted dimensions must be integer strings and are used unchanged as this SVG's user-space dimensions, so svg is not scaled to fit.

Parameters:

Name Type Description Default
svg type[SVGConfigFile]

The SVGConfigFile subclass whose content is inserted. If its file does not exist, only the generated attributes are set.

required

Returns:

Type Description
dict[str, Any]

A dictionary representing a nested <svg> element containing

dict[str, Any]

svg's content, sized to its dimensions and positioned within

dict[str, Any]

this SVG's viewBox.

Raises:

Type Description
ValueError

If the inserted dimensions are not integer strings or the viewBox is not four whitespace-separated integer values.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def insert_svg(self, svg: "type[SVGConfigFile]") -> dict[str, Any]:
    """Return `svg`'s content as a nested `<svg>` element.

    The nested element mirrors the loaded root of `svg`, including its
    attributes and children, so this SVG is self-contained and changes to
    `svg` propagate on sync. Its `width`, `height`, and `viewBox` are
    `svg`'s values, and its `x` and `y` place it at this SVG's viewBox
    origin plus half the remaining space, rounded down to integers; these
    five attributes override any same-named attributes of `svg`. The
    inserted dimensions must be integer strings and are used unchanged as
    this SVG's user-space dimensions, so `svg` is not scaled to fit.

    Args:
        svg: The `SVGConfigFile` subclass whose content is inserted. If its
            file does not exist, only the generated attributes are set.

    Returns:
        A dictionary representing a nested `<svg>` element containing
        `svg`'s content, sized to its dimensions and positioned within
        this SVG's viewBox.

    Raises:
        ValueError: If the inserted dimensions are not integer strings or
            the viewBox is not four whitespace-separated integer values.
    """
    x = int(self.view_box_x()) + (
        (int(self.view_box_width()) - int(svg.I.width())) // 2
    )
    y = int(self.view_box_y()) + (
        (int(self.view_box_height()) - int(svg.I.height())) // 2
    )
    return {
        "svg": {
            **svg.I.safe_load_svg(),
            "@x": str(x),
            "@y": str(y),
            "@width": svg.I.width(),
            "@height": svg.I.height(),
            "@viewBox": svg.I.view_box(),
        },
    }
safe_load_svg
safe_load_svg() -> dict[str, Any]

Return the loaded SVG root, or an empty dict if the file/root is absent.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def safe_load_svg(self) -> dict[str, Any]:
    """Return the loaded SVG root, or an empty dict if the file/root is absent."""
    return self.safe_load().get("svg", {})
svg_configs abstractmethod
svg_configs() -> dict[str, Any]

Return the SVG-specific configuration dictionary.

The _configs method adds the root <svg> element, namespace, dimensions, and viewBox. Returned attributes override those defaults.

Returns:

Type Description
dict[str, Any]

A dictionary representing the SVG configuration.

Source code in src/pyrig_badge/rig/configs/base/svg.py
@abstractmethod
def svg_configs(self) -> dict[str, Any]:
    """Return the SVG-specific configuration dictionary.

    The `_configs` method adds the root `<svg>` element, namespace,
    dimensions, and viewBox. Returned attributes override those defaults.

    Returns:
        A dictionary representing the SVG configuration.
    """
view_box
view_box() -> str

Return the stored viewBox, or "0 0 200 200" if absent.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def view_box(self) -> str:
    """Return the stored viewBox, or `"0 0 200 200"` if absent."""
    return self.safe_load_svg().get("@viewBox", "0 0 200 200")
view_box_attributes
view_box_attributes() -> tuple[str, str, str, str]

Split the viewBox into its four whitespace-separated values.

Returns:

Type Description
tuple[str, str, str, str]

Minimum x, minimum y, width, and height, in that order, as strings.

Raises:

Type Description
ValueError

If the viewBox does not contain exactly four whitespace-separated values.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def view_box_attributes(self) -> tuple[str, str, str, str]:
    """Split the viewBox into its four whitespace-separated values.

    Returns:
        Minimum x, minimum y, width, and height, in that order, as strings.

    Raises:
        ValueError: If the viewBox does not contain exactly four
            whitespace-separated values.
    """
    x, y, width, height = self.view_box().split()
    return x, y, width, height
view_box_height
view_box_height() -> str

Return the height of the viewBox.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def view_box_height(self) -> str:
    """Return the height of the viewBox."""
    _, _, _, height = self.view_box_attributes()
    return height
view_box_width
view_box_width() -> str

Return the width of the viewBox.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def view_box_width(self) -> str:
    """Return the width of the viewBox."""
    _, _, width, _ = self.view_box_attributes()
    return width
view_box_x
view_box_x() -> str

Return the minimum x-coordinate of the viewBox.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def view_box_x(self) -> str:
    """Return the minimum x-coordinate of the viewBox."""
    x, _, _, _ = self.view_box_attributes()
    return x
view_box_y
view_box_y() -> str

Return the minimum y-coordinate of the viewBox.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def view_box_y(self) -> str:
    """Return the minimum y-coordinate of the viewBox."""
    _, y, _, _ = self.view_box_attributes()
    return y
width
width() -> str

Return the stored SVG width, or "200" if absent.

Source code in src/pyrig_badge/rig/configs/base/svg.py
def width(self) -> str:
    """Return the stored SVG width, or `"200"` if absent."""
    return self.safe_load_svg().get("@width", "200")
xml

Base class for managing dictionary-backed XML configuration files.

XMLConfigFile

Bases: DictConfigFile

Manage XML using element names, @ attributes, and #text content.

Repeated elements are represented as lists. Subclasses must implement parent_path(), stem(), and _configs(), returning one root element. Values should use the strings and structures returned by xmltodict.parse. This dictionary representation does not preserve mixed-content ordering.

extension
extension() -> str

Return the XML file extension without a leading dot.

Source code in src/pyrig_badge/rig/configs/base/xml.py
def extension(self) -> str:
    """Return the XML file extension without a leading dot."""
    return "xml"

docs

Configuration managers for documentation assets and pages.

badge

Configuration manager for the Shields.io badge JSON asset.

BadgeConfigFile

Bases: JSONDictConfigFile

Generate project badge data and embed the configured logo SVG.

dependencies
dependencies() -> Iterable[type[ConfigFile[Any]]]

Return the logo asset required to construct this badge.

Returns:

Type Description
Iterable[type[ConfigFile[Any]]]

The logo configuration file, appended to inherited dependencies.

Source code in src/pyrig_badge/rig/configs/docs/badge.py
def dependencies(self) -> Iterable[type[ConfigFile[Any]]]:
    """Return the logo asset required to construct this badge.

    Returns:
        The logo configuration file, appended to inherited dependencies.
    """
    return (*super().dependencies(), LogoConfigFile)
parent_path
parent_path() -> Path

Return the directory containing the logo and badge assets.

Returns:

Type Description
Path

Parent directory used by the logo configuration file.

Source code in src/pyrig_badge/rig/configs/docs/badge.py
def parent_path(self) -> Path:
    """Return the directory containing the logo and badge assets.

    Returns:
        Parent directory used by the logo configuration file.
    """
    return LogoConfigFile.I.parent_path()
stem
stem() -> str

Return the filename stem "badge".

Source code in src/pyrig_badge/rig/configs/docs/badge.py
def stem(self) -> str:
    """Return the filename stem `"badge"`."""
    return "badge"
banner

Configuration manager for the generated documentation banner.

BannerConfigFile

Bases: SVGConfigFile

Manage the banner SVG, centering the logo within a viewBox that fits it.

dependencies
dependencies() -> Iterable[type[ConfigFile[Any]]]

Return the logo config file as a dependency.

Returns:

Type Description
Iterable[type[ConfigFile[Any]]]

A tuple of config file classes that must be validated first.

Source code in src/pyrig_badge/rig/configs/docs/banner.py
def dependencies(self) -> Iterable[type[ConfigFile[Any]]]:
    """Return the logo config file as a dependency.

    Returns:
        A tuple of config file classes that must be validated first.
    """
    return (*super().dependencies(), LogoConfigFile)
parent_path
parent_path() -> Path

Return the documentation assets directory.

Returns:

Type Description
Path

The same directory used by the project logo.

Source code in src/pyrig_badge/rig/configs/docs/banner.py
def parent_path(self) -> Path:
    """Return the documentation assets directory.

    Returns:
        The same directory used by the project logo.
    """
    return LogoConfigFile.I.parent_path()
stem
stem() -> str

Return the banner filename stem.

Source code in src/pyrig_badge/rig/configs/docs/banner.py
def stem(self) -> str:
    """Return the banner filename stem."""
    return "banner"
svg_configs
svg_configs() -> dict[str, Any]

Return the logo's SVG content inserted within the banner's viewBox.

Centering offsets are rounded down to integers by insert_svg.

Returns:

Type Description
dict[str, Any]

A dictionary representing a nested <svg> element that mirrors

dict[str, Any]

the logo's content.

Source code in src/pyrig_badge/rig/configs/docs/banner.py
def svg_configs(self) -> dict[str, Any]:
    """Return the logo's SVG content inserted within the banner's viewBox.

    Centering offsets are rounded down to integers by `insert_svg`.

    Returns:
        A dictionary representing a nested `<svg>` element that mirrors
        the logo's content.
    """
    return self.insert_svg(LogoConfigFile)
view_box
view_box() -> str

Return the stored viewBox, enlarged to fit the logo if needed.

The inserted logo is sized in the banner's user units, so the viewBox width and height are raised to at least the logo's width and height to prevent cropping. The minimum coordinates are kept, and the banner's width and height are unchanged because the viewBox scales to them.

Returns:

Type Description
str

The viewBox as four whitespace-separated integers.

Raises:

Type Description
ValueError

If the stored viewBox does not contain exactly four whitespace-separated values, or its size or the logo's dimensions are not integers.

Source code in src/pyrig_badge/rig/configs/docs/banner.py
def view_box(self) -> str:
    """Return the stored viewBox, enlarged to fit the logo if needed.

    The inserted logo is sized in the banner's user units, so the viewBox
    width and height are raised to at least the logo's width and height
    to prevent cropping. The minimum coordinates are kept, and the
    banner's `width` and `height` are unchanged because the viewBox
    scales to them.

    Returns:
        The viewBox as four whitespace-separated integers.

    Raises:
        ValueError: If the stored viewBox does not contain exactly four
            whitespace-separated values, or its size or the logo's
            dimensions are not integers.
    """
    x, y, width, height = super().view_box().split()
    width = max(int(width), int(LogoConfigFile.I.width()))
    height = max(int(height), int(LogoConfigFile.I.height()))
    return f"{x} {y} {width} {height}"
index

Configuration file manager for the documentation landing page.

IndexConfigFile

Bases: BadgesConfigFile, IndexConfigFile

Generate the documentation landing page with its banner and badges.

image_path
image_path() -> Path

Return the banner path relative to the documentation source directory.

Returns:

Type Description
Path

Documentation-relative path to the configured banner asset.

Source code in src/pyrig_badge/rig/configs/docs/index.py
def image_path(self) -> Path:
    """Return the banner path relative to the documentation source directory.

    Returns:
        Documentation-relative path to the configured banner asset.
    """
    return super().image_path().relative_to(DocsBuilder.I.docs_dir())

Configuration manager for the generated documentation logo.

LogoConfigFile

Bases: SVGConfigFile

Manage the project logo SVG under the documentation assets directory.

parent_path
parent_path() -> Path

Return the documentation assets directory.

Returns:

Type Description
Path

The documentation source directory joined with "assets".

Source code in src/pyrig_badge/rig/configs/docs/logo.py
def parent_path(self) -> Path:
    """Return the documentation assets directory.

    Returns:
        The documentation source directory joined with `"assets"`.
    """
    return DocsBuilder.I.docs_dir() / "assets"
stem
stem() -> str

Return the logo filename stem.

Source code in src/pyrig_badge/rig/configs/docs/logo.py
def stem(self) -> str:
    """Return the logo filename stem."""
    return "logo"
svg_configs
svg_configs() -> dict[str, Any]

Return no additional SVG elements or attributes.

Returns:

Type Description
dict[str, Any]

An empty dictionary; the base SVG config supplies the required

dict[str, Any]

root element, namespace, dimensions, and viewBox, and Pyrig merges

dict[str, Any]

existing SVG content.

Source code in src/pyrig_badge/rig/configs/docs/logo.py
def svg_configs(self) -> dict[str, Any]:
    """Return no additional SVG elements or attributes.

    Returns:
        An empty dictionary; the base SVG config supplies the required
        root element, namespace, dimensions, and viewBox, and Pyrig merges
        existing SVG content.
    """
    return {}

readme

Configuration management for the project's README.md file.

ReadmeConfigFile

Bases: BadgesConfigFile, ReadmeConfigFile

Generate the project README with the configured banner and badges.