aglyph — Dependency Injection for Python

Release:3.0.0.post1

This module defines a custom error type and several utility functions used by Aglyph.

Note

Aglyph uses the standard logging module, but by default registers a logging.NullHandler to suppress messages.

To enable Aglyph logging, configure a logger and handler for the “aglyph” log channel (see logging.config).

Note

New in version 3.0.0.

Aglyph framework functions and methods are fully traced using Autologging. However, all tracing is deactivated by default.

To activate tracing:

  1. Configure a logger and handler for the “aglyph” log channel and set the logging level to autologging.TRACE.
  2. Run Aglyph with the AGLYPH_TRACED environment variable set to a non-empty value.
exception aglyph.AglyphError(message, cause=None)[source]

Bases: exceptions.Exception

Raised when Aglyph operations fail with a condition that is not sufficiently described by a built-in exception.

aglyph.format_dotted_name(obj)[source]

Return the importable dotted-name string for obj.

Parameters:obj – an importable class, function, or module
Returns:a dotted name representing obj
Return type:str
Raises:AglyphError – if obj does not have a resolvable (importable) dotted name

The dotted name returned by this function is a “dotted_name.NAME” or “dotted_name” string for obj that represents a valid absolute import statement according to the following productions:

absolute_import_stmt ::=  "from" dotted_name "import" NAME
                          | "import" dotted_name
dotted_name          ::=  NAME ('.' NAME)*

Note

This function is the inverse of resolve_dotted_name().

Warning

This function will attempt to use the __qualname__ attribute, which is only available in Python 3.3+. When __qualname__ is not available, __name__ is used instead.

See also

PEP 3155, aglyph._compat.name_of()

aglyph.resolve_dotted_name(dotted_name)[source]

Return the class, function, or module identified by dotted_name.

Parameters:dotted_name (str) – a string representing an importable class, function, or module
Returns:a class, function, or module

dotted_name must be a “dotted_name.NAME” or “dotted_name” string that represents a valid absolute import statement according to the following productions:

absolute_import_stmt ::=  "from" dotted_name "import" NAME
                          | "import" dotted_name
dotted_name          ::=  NAME ('.' NAME)*

Note

This function is the inverse of format_dotted_name().