myst_parser.inventory#

Logic for dealing with sphinx style inventories (e.g. objects.inv).

These contain mappings of reference names to ids, scoped by domain and object type.

This is adapted from the Sphinx inventory.py module. We replicate it here, so that it can be used without Sphinx.

1.  Module Contents#

1.1.  Classes#

InventoryItemType

A single inventory item.

InventoryType

Inventory data.

InventoryFileReader

A file reader for an inventory file.

InvMatch

A match from an inventory.

1.2.  Functions#

from_sphinx

Convert from a Sphinx compliant format.

to_sphinx

Convert to a Sphinx compliant format.

load

Load inventory data from a stream.

match_with_wildcard

Match a whole name with a pattern, that can include * wildcards, to match 0 or more characters.

filter_inventories

Filter a set of inventories.

filter_sphinx_inventories

Filter a set of sphinx style inventories.

filter_string

Create a string representation of the filter, from the given arguments.

fetch_inventory

Fetch an inventory from a URL or local path.

inventory_cli

Command line interface for fetching and parsing an inventory.

1.3.  API#

class myst_parser.inventory.InventoryItemType[源代码]#

Bases: typing.TypedDict

A single inventory item.

Initialization

Initialize self. See help(type(self)) for accurate signature.

loc: str = None#

The location of the item (relative if base_url not None).

text: str | None = None#

Implicit text to show for the item.

class myst_parser.inventory.InventoryType[源代码]#

Bases: typing.TypedDict

Inventory data.

Initialization

Initialize self. See help(type(self)) for accurate signature.

name: str = None#

The name of the project.

version: str = None#

The version of the project.

base_url: str | None = None#

The base URL of the loc.

objects: dict[str, dict[str, dict[str, myst_parser.inventory.InventoryItemType]]] = None#

Mapping of domain -> object type -> name -> item.

myst_parser.inventory.from_sphinx(inv: sphinx.util.typing.Inventory) myst_parser.inventory.InventoryType[源代码]#

Convert from a Sphinx compliant format.

myst_parser.inventory.to_sphinx(inv: myst_parser.inventory.InventoryType) sphinx.util.typing.Inventory[源代码]#

Convert to a Sphinx compliant format.

myst_parser.inventory.load(stream: IO, base_url: str | None = None) myst_parser.inventory.InventoryType[源代码]#

Load inventory data from a stream.

class myst_parser.inventory.InventoryFileReader(stream: IO)[源代码]#

A file reader for an inventory file.

This reader supports mixture of texts and compressed texts.

Initialization

read_buffer() None[源代码]#
readline() str[源代码]#
readlines() collections.abc.Iterator[str][源代码]#
read_compressed_chunks() collections.abc.Iterator[bytes][源代码]#
read_compressed_lines() collections.abc.Iterator[str][源代码]#
myst_parser.inventory.match_with_wildcard(name: str, pattern: str | None) bool[源代码]#

Match a whole name with a pattern, that can include * wildcards, to match 0 or more characters.

To include a literal * in the pattern, use *.

class myst_parser.inventory.InvMatch[源代码]#

A match from an inventory.

inv: str = None#
domain: str = None#
otype: str = None#
name: str = None#
project: str = None#
version: str = None#
base_url: str | None = None#
loc: str = None#
text: str | None = None#
asdict() dict[str, str][源代码]#
myst_parser.inventory.filter_inventories(inventories: dict[str, myst_parser.inventory.InventoryType], *, invs: str | None = None, domains: str | None = None, otypes: str | None = None, targets: str | None = None) collections.abc.Iterator[myst_parser.inventory.InvMatch][源代码]#

Filter a set of inventories.

Filters are strings that can include * wildcards, to match 0 or more characters.

To include a literal * in the pattern, use *.

参数:
  • inventories -- Mapping of inventory name to inventory data

  • invs -- the inventory key filter

  • domains -- the domain name filter

  • otypes -- the object type filter

  • targets -- the target name filter

myst_parser.inventory.filter_sphinx_inventories(inventories: dict[str, sphinx.util.typing.Inventory], *, invs: str | None = None, domains: str | None = None, otypes: str | None = None, targets: str | None = None) collections.abc.Iterator[myst_parser.inventory.InvMatch][源代码]#

Filter a set of sphinx style inventories.

Filters are strings that can include * wildcards, to match 0 or more characters.

To include a literal * in the pattern, use *.

参数:
  • inventories -- Mapping of inventory name to inventory data

  • invs -- the inventory key filter

  • domains -- the domain name filter

  • otypes -- the object type filter

  • targets -- the target name filter

myst_parser.inventory.filter_string(invs: str | None, domains: str | None, otype: str | None, target: str | None, *, delimiter: str = ':') str[源代码]#

Create a string representation of the filter, from the given arguments.

myst_parser.inventory.fetch_inventory(uri: str, *, timeout: None | float = None, base_url: None | str = None) myst_parser.inventory.InventoryType[源代码]#

Fetch an inventory from a URL or local path.

myst_parser.inventory.inventory_cli(inputs: None | list[str] = None)[源代码]#

Command line interface for fetching and parsing an inventory.