fancytools.pystructure package

Submodules

fancytools.pystructure.FallBack module

class fancytools.pystructure.FallBack.FallBack(ownModuleName, fallbackModule, print_warning=True)[source]

Bases: object

a class allowing to automatically using another module as fall back if the given module doesn’t have a needed attribute

to create the fall back compatibility just ad the following line to your module:

>>> FallBack(__name__, MyFallBackModule, print_warning=True)

fancytools.pystructure.GetCallablesInPackage module

class fancytools.pystructure.GetCallablesInPackage.GetCallablesInPackage(package, modules_in_structure=False, include_classes=True, include_functions=False, min_level=0, max_level=None, exclude_empty_pck=True)[source]

Bases: fancytools.fcollections.NestedOrderedDict.NestedOrderedDict

Return a NestedOrderedDict of all functions and classes within a given package. excluding ‘private’ modules beginning with ‘_’

Arguments Description
package package or string of path to package to get all callables from
Optional Default Description
modules_in_structure False include the modules of the callables in the output
include_classes True include classes in the output
include_functions True include functions in the output
min_level 0 minimum depth level in the package structure
max_level None maximum depth level in the package structure
exclude_empty_pck True exclude sub-packages without any callables from the output
static belongsToModule(obj, module)[source]

Returns True is an object belongs to a module.

buildHirarchy(horizontal_operation=None, vertical_operation=None)[source]

Walk through the nested dict structure and executes horizontal_operation(name, callable) resp. vertical_operation(name, callable) if defined.

static isNestedDict(instance)[source]

convenience function for

>>> isinstance(instance, NestedOrderedDict)

fancytools.pystructure.getMembers module

Different functions to return members within a given module or package.

fancytools.pystructure.getMembers.getAvClassNamesInModule(prooveModule)[source]

get the class names within a module

fancytools.pystructure.getMembers.getAvClassNamesInPackage(package)[source]

get the class names within a package

fancytools.pystructure.getMembers.getAvailableClassesInModule(prooveModule)[source]

return a list of all classes in the given module that dont begin with ‘_’

fancytools.pystructure.getMembers.getAvailableClassesInPackage(package)[source]

return a list of all classes in the given package whose modules dont begin with ‘_’

fancytools.pystructure.getMembers.getClassInModuleFromName(className, module)[source]

get a class from name within a module

fancytools.pystructure.getMembers.getClassInPackageFromName(className, pkg)[source]

get a class from name within a package

fancytools.pystructure.runAllInDir module

fancytools.pystructure.runAllInDir.runAllInDir(dir_path, exclude=[], add_args=(), ignoreErrors=True)[source]

execute all modules as __main__ within a given package path

fancytools.pystructure.stitchModules module

fancytools.pystructure.stitchModules.stitchModules(module, fallbackModule)[source]

complete missing attributes with those in fallbackModule

imagine you have 2 modules: a and b a is some kind of an individualised module of b - but will maybe not contain all attributes of b. in this case a should use the attributes from b

>>> import types
>>> a = types.ModuleType('a', 'The a.py module') # you will have of course a file for those
>>> b = types.ModuleType('b', 'The b.py module')
>>> b.var1 = 'standard 1'
>>> b.var2 = 'standard 2'
>>> a.var1 = 'individual 1'

what we now want is to all all missing attributes from b to a:

>>> stitchModules(a,b)
>>> print a.var1
individual 1
>>> print a.var2
standard 2