mewlo.mpacks.core.helpers.callables module

callables.py This module contains functions that can lookup and return a reference to a function in a module, where both are specified by module imports or dotted strings. These functions are used, for example, in mcontroller.py where a site specifies the controller function associated with a route.

mewlo.mpacks.core.helpers.callables.do_importmodule_bypath(filepath, flag_tryinitfiletoo=True)[source]

Internal helper function. Load a python module import by explicit path. return tuple (dynamicmodule, failure)

mewlo.mpacks.core.helpers.callables.does_directory_contain_initpackagefile(path)[source]
mewlo.mpacks.core.helpers.callables.find_callable(callableroot, callableobj)[source]

Given a dotted path, and an optional root package, find the callable.

This is really the only function in this module that the user should ever have to invoke; the rest of the functions are called by this one.

For more info on the approach, see http://stackoverflow.com/questions/6643324/how-is-calling-module-and-function-by-string-handled-in-python

Parameters:
  • callableroot – None | string to prefix to dotted path | imported package(module) to use as root of dotted lookup
  • callableobj – string representing a dotted path to look up; the last element is treated as function name, and everything before that is treated as module name to lookup
Returns:

funcreference

Todo:

support python egg format of “package.module:object”

ATTN: we currently use an exception here because we treat this like a fatal error. If instead we wanted callers to be able to resume fromt his, we might return EFailures instead

mewlo.mpacks.core.helpers.callables.find_function_from_module_and_dottedpath(mod, functionname)[source]

Internal helper funciton for finding a callable by string. Return the callable function attribute in the given module.

mewlo.mpacks.core.helpers.callables.find_module_from_dottedpath(callableroot, modulepath)[source]

Internal helper funciton for finding a callable by string or module itself. Given a dotted path to a module, look up and return the module.

mewlo.mpacks.core.helpers.callables.find_module_from_dottedpath_bystring(modulepath)[source]

Internal helper funciton for finding a callable by string. Given a dotted path to a module, look up and return the module.

mewlo.mpacks.core.helpers.callables.find_module_from_dottedpath_relativetopackage(parentmodule, modulepath)[source]

Helper funciton for finding a callable by string. Given a dotted path to a module relative to a parent, look up and return the module.

mewlo.mpacks.core.helpers.callables.guess_module_importname_or_adjust_pythonpath(dirpath, name)[source]

Generate the dotted name to pass to imp.load_module() or modify python path if needed. See the function do_importmodule_bypath() for a long discussion. :return: (imploadname, flag_did_addtopythonpath)

mewlo.mpacks.core.helpers.callables.importmodule_bypath(path)[source]

Import a python module by file path.

mewlo.mpacks.core.helpers.callables.is_module_directory_importreachable(startpath, subdirdottedpath)[source]
mewlo.mpacks.core.helpers.callables.split_dottedpath_modulepath_and_funcname(dottedname)[source]

Internal helper funciton for finding a callable by string. Split off the token after the last dot and return a tuple of (string-less-the-last-token, last-token)

Table Of Contents

Previous topic

mewlo.mpacks.core.helpers package

Next topic

mewlo.mpacks.core.helpers.cfgmodule module

This Page