aglyph — Dependency Injection for Python

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

Aglyph is fully logged using the standard logging module, but by default uses a no-op logging handler to suppress log messages. If you want to enable Aglyph logging, define a logger for the “aglyph” log channel in your application, prior to importing any Aglyph modules.

See logging.config for more information about configuring the logging module.

exception aglyph.AglyphError[source]

Bases: exceptions.Exception

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

aglyph.has_importable_dotted_name(obj)[source]

Return True if obj is an importable class or unbound function.

aglyph.format_dotted_name(factory)[source]

Return the dotted-name string for factory.

factory should be an importable class or unbound function.

The returned dotted-name is a “relative_module.identifier” string for factory that represents a valid import statement according to the following production:

import_stmt ::=  "from" relative_module "import" identifier

This function is the inverse of resolve_dotted_name().

Raises TypeError:
 if factory is not a class or unbound function
aglyph.identify_by_spec(spec)[source]

Return an identifier string for spec.

If spec is a string, it is returned. Otherwise, spec must be an importable class or unbound function, and its dotted-name is returned (see format_dotted_name()).

aglyph.resolve_dotted_name(dotted_name)[source]

Return the class or function identified by dotted_name.

dotted_name must be a “relative_module.identifier” string such that the following production represents a valid import statement with respect to the application’s sys.path:

import_stmt ::=  "from" relative_module "import" identifier

This method is the inverse of format_dotted_name().

Raises:
  • ImportError – if importing dotted_name fails
  • ValueError – if dotted_name cannot be parsed into “relative_module” and “identifier” parts

Previous topic

Aglyph API reference

Next topic

aglyph.assembler — The Aglyph component assembler

This Page