Skip to main content

Read & write entry_points.txt files

Project description

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status https://codecov.io/gh/jwodder/entry-points-txt/branch/master/graph/badge.svg https://img.shields.io/pypi/pyversions/entry-points-txt.svg MIT License

GitHub | PyPI | Issues | Changelog

entry-points-txt provides functions for reading & writing entry_points.txt files according to the spec. That is the one thing it does, and it endeavors to do it well.

Installation

entry-points-txt requires Python 3.6 or higher. Just use pip for Python 3 (You have pip, right?) to install entry-points-txt:

python3 -m pip install entry-points-txt

API

EntryPoint

class EntryPoint(NamedTuple)

A representation of an entry point as a namedtuple. Instances have the following attributes and methods:

group: str

The name of the entry point group (e.g., "console_scripts")

name: str

The name of the entry point

module: str

The module portion of the attribute reference (the part before the colon)

attr: Optional[str]

The attribute/object portion of the attribute reference (the part after the colon), or None if not specified

extras: Tuple[str, ...]

Extras required for the entry point

load() -> Any

Returns the object referred to by the entry point

to_line() -> str

Returns the representation of the entry point as a line in entry_points.txt, i.e., a line of the form name = module:attr [extras]

EntryPointSet

EntryPointSet = Dict[str, Dict[str, EntryPoint]]

An alias for the return type of load() & loads() and the argument type of dump() & dumps(). Entry points are organized into a dict that maps group names to sub-dicts that map entry point names to EntryPoint instances.

load()

entry_points_txt.load(fp: IO[str]) -> EntryPointSet

Parse a file-like object as an entry_points.txt-format file and return the results.

For example, the following input:

[console_scripts]
foo = package.__main__:main
bar = package.cli:klass.attr

[thingy.extension]
quux = package.thingy [xtr]

would be parsed as:

{
    "console_scripts": {
        "foo": EntryPoint(group="console_scripts", name="foo", module="package.__main__", attr="main", extras=()),
        "bar": EntryPoint(group="console_scripts", name="bar", module="package.cli", attr="klass.attr", extras=()),
    },
    "thingy.extension": {
        "quux": EntryPoint(group="thingy.extension", name="quux", module="package.thingy", attr=None, extras=("xtr",)),
    },
}

loads()

entry_points_txt.loads(s: str) -> EntryPointSet

Like load(), but reads from a string instead of a filehandle

dump()

entry_points_txt.dump(eps: EntryPointSet, fp: IO[str]) -> None

Write a collection of entry points to a file-like object in entry_points.txt format. A ValueError is raised and nothing is written if the group or name key under which an EntryPoint is located does not match its group or name attribute.

dumps()

entry_points_txt.dumps(eps: EntryPointSet) -> str

Like dump(), but returns a string instead of writing to a filehandle

dump_list()

entry_points_txt.dump_list(eps: Iterable[EntryPoint], fp: IO[str]) -> None

Write an iterable of entry points to a file-like object in entry_points.txt format. If two or more entry points have the same group & name, only the last one will be output.

dumps_list()

entry_points_txt.dumps_list(eps: Iterable[EntryPoint]) -> str

Like dump_list(), but returns a string instead of writing to a filehandle

ParseError

class ParseError(ValueError)

Exception raised by load() or loads() when given invalid input

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

entry-points-txt-0.2.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

entry_points_txt-0.2.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file entry-points-txt-0.2.0.tar.gz.

File metadata

  • Download URL: entry-points-txt-0.2.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for entry-points-txt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b3e4e976b8c18f479ecad42594cac8d75e42293e8ba9e3f4892d927b02099e6a
MD5 3692a63d48405c2abd0d9539c6b845cd
BLAKE2b-256 9ef266329d6a74e456039ae09be85dc96f2994edb86613ed5bc63f605cef7864

See more details on using hashes here.

File details

Details for the file entry_points_txt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: entry_points_txt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for entry_points_txt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f17191ff7c7dcfe8753f22c5432705e7cbcca7de4b6ceb48ce298d1421c40bb7
MD5 f7e6b5ae34e2862b40fa79b64bb05309
BLAKE2b-256 6a110ef395fadaa92fc92ac12826e5dc5eb87278e66e6f0b2f2513d9352bcd13

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page