def __build_python_module_cache(self):
        """Recursively walks through the b2/src subdirectories and
        creates an index of base module name to package name. The
        index is stored within self.__python_module_cache and allows
        for an O(1) module lookup.

        For example, given the base module name `toolset`,
        self.__python_module_cache['toolset'] will return
        'b2.build.toolset'

        pkgutil.walk_packages() will find any python package
        provided a directory contains an __init__.py. This has the
        added benefit of allowing libraries to be installed and
        automatically avaiable within the contrib directory.

        *Note*: pkgutil.walk_packages() will import any subpackage
        in order to access its __path__variable. Meaning:
        any initialization code will be run if the package hasn't
        already been imported.
        """
        cache = {}
        for importer, mname, ispkg in pkgutil.walk_packages(b2.__path__, prefix='b2.'):
            basename = mname.split('.')[-1]
            # since the jam code is only going to have "import toolset ;"
            # it doesn't matter if there are separately named "b2.build.toolset" and
            # "b2.contrib.toolset" as it is impossible to know which the user is
            # referring to.
            if basename in cache:
                self.manager.errors()('duplicate module name "{0}" '
                                      'found in boost-build path'.format(basename))
            cache[basename] = mname
        self.__python_module_cache = cache