autodoc2.db#

A database interface for storing and querying the analysis items.

Module Contents#

Classes#

Database

A simple interface for storing and querying the analysis items, from a single package.

InMemoryDb

A simple in-memory database for storing and querying the analysis items.

Data#

API#

exception autodoc2.db.UniqueError[source]#

Bases: KeyError

An error raised when a unique constraint is violated.

Initialization

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

class autodoc2.db.Database[source]#

Bases: typing.Protocol

A simple interface for storing and querying the analysis items, from a single package.

This allows for potential extensibility in the future, e.g. using a persistent sqlite database.

add(item: autodoc2.utils.ItemData) None[source]#

Add an item to the database.

remove(full_name: str, descendants: bool) None[source]#

Remove an item from the database, by full_name.

If descendants is True, remove all descendants of this item.

__contains__(full_name: str) bool[source]#

Check if an item is in the database, by full_name.

get_item(full_name: str) autodoc2.utils.ItemData | None[source]#

Get an item from the database, by full_name.

get_items_like(full_name: str) Iterable[autodoc2.utils.ItemData][source]#

Get an item from the database, matching the wildcards * and ?.

* matches any number of characters, and ? matches any single character.

get_type(full_name: str) None | str[source]#

Get the type of an item from the database, by full_name.

get_by_type(type_: str) Iterable[autodoc2.utils.ItemData][source]#

Get all items from the database, by type.

get_overloads(full_name: str) Iterable[autodoc2.utils.ItemData][source]#

Get all function overloads for this name.

get_children(full_name: str, types: None | set[str] = None, *, sort_name: bool = False) Iterable[autodoc2.utils.ItemData][source]#

Get all items that are direct children of this name, i.e. {full_name}.{name}.

Parameters:
  • full_name – The full name of the item.

  • types – If given, only return items of these types.

  • sort_name – If True, sort the names alphabetically.

get_children_names(full_name: str, types: None | set[str] = None, *, sort_name: bool = False) Iterable[str][source]#

Get all names of direct children of this name, i.e. {full_name}.{name}.

Parameters:
  • full_name – The full name of the item.

  • types – If given, only return items of these types.

  • sort_name – If True, sort the names alphabetically.

get_ancestors(full_name: str, include_self: bool) Iterable[autodoc2.utils.ItemData | None][source]#

Get all ancestors of this name, e.g. a.b, a for a.b.c.

The order is guaranteed from closest to furthest ancestor.

Parameters:
  • full_name – The full name of the item.

  • include_self – If True, include the item itself.

autodoc2.db._LIKE_REGEX#

β€˜compile(…)’

class autodoc2.db.InMemoryDb[source]#

Bases: autodoc2.db.Database

A simple in-memory database for storing and querying the analysis items.

Initialization

Create the database.

add(item: autodoc2.utils.ItemData) None[source]#
remove(full_name: str, descendants: bool) None[source]#
__contains__(full_name: str) bool[source]#
get_item(full_name: str) autodoc2.utils.ItemData | None[source]#
get_items_like(full_name: str) Iterable[autodoc2.utils.ItemData][source]#
get_type(full_name: str) None | str[source]#
get_by_type(type_: str) Iterable[autodoc2.utils.ItemData][source]#
get_overloads(full_name: str) Iterable[autodoc2.utils.ItemData][source]#
get_children(full_name: str, types: None | set[str] = None, *, sort_name: bool = False) Iterable[autodoc2.utils.ItemData][source]#
get_children_names(full_name: str, types: None | set[str] = None, *, sort_name: bool = False) Iterable[str][source]#
get_ancestors(full_name: str, include_self: bool) Iterable[autodoc2.utils.ItemData | None][source]#
write(stream: TextIO) None[source]#

Write the database to a file.

classmethod read(stream: TextIO) autodoc2.db.InMemoryDb[source]#

Read the database from a file.