Package grassyknoll :: Package lib :: Module meta
[hide private]

Module meta

source code

meta-programming magic

Classes [hide private]
  Spatch
  Factory
easier construction of instance factories.
  FactoryMixin
a mixin providing factory, which produces Factorys
  AutoLogger
descriptor that returns a logger named after the class or subclass
  LocalState
a instance with support for thread-local attributes.
Functions [hide private]
a module
importString(source, filename, globals_=None, locals_=None)
construct a module from source code.
source code
a module
importFile(f, globals_=None, locals_=None)
construct a module from a file
source code
module
findModule(name)
find a module
source code
list of string
findPackageModules(path)
Returns: a list of all modules in path
source code
list of modules
importPackageModules(pkgname)
import and return a list of all modules in pkgname
source code
 
localProperty(func)
a read-only thread-local property.
source code
Function Details [hide private]

importString(source, filename, globals_=None, locals_=None)

source code 

construct a module from source code.

The module will not appear in sys.path
Parameters:
  • source (string) - source code of the module
  • filename (string) - a filename to use for the module's __file__
  • globals_ (dict) - globals to pass to eval(). Defaults to globals()
  • locals_ (dict) - locals to pass to eval(). Defaults to empty dict
Returns: a module

importFile(f, globals_=None, locals_=None)

source code 

construct a module from a file

The module will not appear in sys.path
Parameters:
  • f (string or file) - filename or open file
  • globals_ (dict) - globals to pass to eval(). Defaults to globals()
  • locals_ (dict) - locals to pass to eval(). Defaults to empty dict
Returns: a module

findModule(name)

source code 
find a module
Parameters:
  • name (string) - name of the module to find. Call with __name__ to find yourself.
Returns: module
Raises:
  • KeyError - if no module called name exists

findPackageModules(path)

source code 
Parameters:
  • path (string) - a filesystem path
Returns: list of string
a list of all modules in path

importPackageModules(pkgname)

source code 

import and return a list of all modules in pkgname

This only works with the usual Python package layout. More obscure/magic variants (such as __path__) won't work.
Parameters:
  • pkgname (string) - the name of a package. Use __name__ from __init__.py to get your own modules.
Returns: list of modules
all modules in pkgname

localProperty(func)

source code 

a read-only thread-local property.

Use this function as a decorator. When first accessed in each thread, it will create a thread-local attribute with the return value of the decoratored function.

XXX extend to support set/delete?