dist_meta.entry_points

Parser and emitter for entry_points.txt.

Note

The functions in this module will only parse well-formed entry_points.txt files, and may return unexpected values if passed malformed input.

Functions:

lazy_load(filename)

Parse the entry points from the given file lazily.

lazy_loads(rawtext)

Parse the entry points from the given text lazily.

load(filename)

Parse the entry points from the given file.

loads(rawtext)

Parse the entry points from the given text.

dump(entry_points, filename)

Construct an entry_points.txt file for the given grouped entry points, and write it to filename.

dumps(entry_points)

Construct an entry_points.txt file for the given grouped entry points.

get_entry_points(group[, path])

Returns an iterator over entrypoints.EntryPoint objects in the given group.

get_all_entry_points([path])

Returns a mapping of entry point groups to entry points for all installed distributions.

Classes:

EntryPoint(name, value[, group, distro])

Represents a single entry point.

lazy_load(filename)[source]

Parse the entry points from the given file lazily.

Parameters

filename (Union[str, Path, PathLike])

Return type

Iterator[Tuple[str, Iterator[Tuple[str, str]]]]

Returns

An iterator over (group, entry_point) tuples, where entry_point is an iterator over (name, object) tuples.

lazy_loads(rawtext)[source]

Parse the entry points from the given text lazily.

Parameters

rawtext (str)

Return type

Iterator[Tuple[str, Iterator[Tuple[str, str]]]]

Returns

An iterator over (group, entry_point) tuples, where entry_point is an iterator over (name, object) tuples.

load(filename)[source]

Parse the entry points from the given file.

Parameters

filename (Union[str, Path, PathLike])

Return type

Dict[str, Dict[str, str]]

Returns

A mapping of entry point groups to entry points.

Entry points in each group are contained in a dictionary mapping entry point names to objects.

dist_meta.entry_points.EntryPoint objects can be constructed as follows:

for name, epstr in distro.get_entry_points().get("console_scripts", {}).items():
    EntryPoint(name, epstr)

loads(rawtext)[source]

Parse the entry points from the given text.

Parameters

rawtext (str)

Return type

Dict[str, Dict[str, str]]

Returns

A mapping of entry point groups to entry points.

Entry points in each group are contained in a dictionary mapping entry point names to objects.

dist_meta.entry_points.EntryPoint objects can be constructed as follows:

for name, epstr in distro.get_entry_points().get("console_scripts", {}).items():
    EntryPoint(name, epstr)

dump(entry_points, filename)[source]

Construct an entry_points.txt file for the given grouped entry points, and write it to filename.

Parameters
Return type

int

dumps(entry_points)[source]

Construct an entry_points.txt file for the given grouped entry points.

Parameters

entry_points (Union[Dict[str, Dict[str, str]], Dict[str, Sequence[EntryPoint]]]) –

A mapping of entry point groups to entry points.

Entry points in each group are contained in a dictionary mapping entry point names to objects, or in a list of EntryPoint objects.

Return type

str

get_entry_points(group, path=None)[source]

Returns an iterator over entrypoints.EntryPoint objects in the given group.

Parameters
Return type

Iterator[EntryPoint]

get_all_entry_points(path=None)[source]

Returns a mapping of entry point groups to entry points for all installed distributions.

Parameters

path (Optional[Iterable[Union[str, Path, PathLike]]]) – The directories entries to search for distributions in. Default sys.path.

Return type

Dict[str, List[EntryPoint]]

namedtuple EntryPoint(name, value, group=None, distro=None)[source]

Bases: NamedTuple

Represents a single entry point.

Fields
  1.  name (str) – The name of the entry point.

  2.  value (str) – The value of the entry point, in the form module.submodule:attribute.

  3.  group (Optional[str]) – The group the entry point belongs to.

  4.  distro (Optional[Distribution]) – The distribution the entry point belongs to.

load()[source]

Load the object referred to by this entry point.

If only a module is indicated by the value, return that module. Otherwise, return the named object.

Return type

object

property extras

Returns the list of extras associated with the entry point.

Return type

List[str]

property module

The module component of self.value.

Return type

str

property attr

The object/attribute component of self.value.

Return type

str

classmethod from_mapping(mapping, *, group=None, distro=None)[source]

Returns a list of EntryPoint objects constructed from values in mapping.

Parameters
  • mapping (Mapping[str, str]) – A mapping of entry point names to values, where values are in the form module.submodule:attribute.

  • group (Optional[str]) – The group the entry points belong to. Default None.

  • distro (Optional[Distribution]) – The distribution the entry points belong to. Default None.

Return type

List[EntryPoint]

__repr__()

Return a nicely formatted representation string