parameters: (self, name, extra_path=None)
docstring: Load a Python module that should be useable from Jamfiles.
  
          There are generally two types of modules Jamfiles might want to
          use:
          - Core Boost.Build. Those are imported using plain names, e.g.
          'toolset', so this function checks if we have module named
          b2.package.module already.
          - Python modules in the same directory as Jamfile. We don't
          want to even temporary add Jamfile's directory to sys.path,
          since then we might get naming conflicts between standard
          Python modules and those.
docstring_summary: Load a Python module that should be useable from Jamfiles.
docstring_tokens: Load a Python module that should be useable from Jamfiles .
function: def load_module(self, name, extra_path=None):
          """Load a Python module that should be useable from Jamfiles.
  
          There are generally two types of modules Jamfiles might want to
          use:
          - Core Boost.Build. Those are imported using plain names, e.g.
          'toolset', so this function checks if we have module named
          b2.package.module already.
          - Python modules in the same directory as Jamfile. We don't
          want to even temporary add Jamfile's directory to sys.path,
          since then we might get naming conflicts between standard
          Python modules and those.
          """
          assert isinstance(name, basestring)
          assert is_iterable_typed(extra_path, basestring) or extra_path is None
          # See if we loaded module of this name already
          existing = self.loaded_tool_modules_.get(name)
          if existing:
              return existing
  
          # check the extra path as well as any paths outside
          # of the b2 package and import the  module if it exists
          b2_path = os.path.normpath(b2.__path__[0])
          # normalize the pathing in the BOOST_BUILD_PATH.
          # this allows for using startswith() to determine
          # if a path is a subdirectory of the b2 root_path
          paths = [os.path.normpath(p) for p in self.manager.boost_build_path()]
          # remove all paths that start with b2's root_path
          paths = [p for p in paths if not p.startswith(b2_path)]
          # add any extra paths
          paths.extend(extra_path)
  
          try:
              # find_module is used so that the pyc's can be used.
              # an ImportError is raised if not found
              f, location, description = imp.find_module(name, paths)
          except ImportError:
              # if the module is not found in the b2 package,
              # this error will be handled later
              pass
          else:
              # we've found the module, now let's try loading it.
              # it's possible that the module itself contains an ImportError
              # which is why we're loading it in this else clause so that the
              # proper error message is shown to the end user.
              # TODO: does this module name really need to be mangled like this?
              mname = name + "__for_jamfile"
              self.loaded_tool_module_path_[mname] = location
              module = imp.load_module(mname, f, location, description)
              self.loaded_tool_modules_[name] = module
              return module
  
          # the cache is created here due to possibly importing packages
          # that end up calling get_manager() which might fail
          if not self.__python_module_cache:
              self.__build_python_module_cache()
  
          underscore_name = name.replace('-', '_')
          # check to see if the module is within the b2 package
          # and already loaded
          mname = self.__python_module_cache.get(underscore_name)
          if mname in sys.modules:
              return sys.modules[mname]
          # otherwise, if the module name is within the cache,
          # the module exists within the BOOST_BUILD_PATH,
          # load it.
          elif mname:
              # in some cases, self.loaded_tool_module_path_ needs to
              # have the path to the file during the import
              # (project.initialize() for example),
              # so the path needs to be set *before* importing the module.
              path = os.path.join(b2.__path__[0], *mname.split('.')[1:])
              self.loaded_tool_module_path_[mname] = path
              # mname is guaranteed to be importable since it was
              # found within the cache
              __import__(mname)
              module = sys.modules[mname]
              self.loaded_tool_modules_[name] = module
              return module
  
          self.manager.errors()("Cannot find module '%s'" % name)
function_tokens: def load_module ( self , name , extra_path = None ) : assert isinstance ( name , basestring ) assert is_iterable_typed ( extra_path , basestring ) or extra_path is None # See if we loaded module of this name already existing = self . loaded_tool_modules_ . get ( name ) if existing : return existing # check the extra path as well as any paths outside # of the b2 package and import the  module if it exists b2_path = os . path . normpath ( b2 . __path__ [ 0 ] ) # normalize the pathing in the BOOST_BUILD_PATH. # this allows for using startswith() to determine # if a path is a subdirectory of the b2 root_path paths = [ os . path . normpath ( p ) for p in self . manager . boost_build_path ( ) ] # remove all paths that start with b2's root_path paths = [ p for p in paths if not p . startswith ( b2_path ) ] # add any extra paths paths . extend ( extra_path ) try : # find_module is used so that the pyc's can be used. # an ImportError is raised if not found f , location , description = imp . find_module ( name , paths ) except ImportError : # if the module is not found in the b2 package, # this error will be handled later pass else : # we've found the module, now let's try loading it. # it's possible that the module itself contains an ImportError # which is why we're loading it in this else clause so that the # proper error message is shown to the end user. # TODO: does this module name really need to be mangled like this? mname = name + "__for_jamfile" self . loaded_tool_module_path_ [ mname ] = location module = imp . load_module ( mname , f , location , description ) self . loaded_tool_modules_ [ name ] = module return module # the cache is created here due to possibly importing packages # that end up calling get_manager() which might fail if not self . __python_module_cache : self . __build_python_module_cache ( ) underscore_name = name . replace ( '-' , '_' ) # check to see if the module is within the b2 package # and already loaded mname = self . __python_module_cache . get ( underscore_name ) if mname in sys . modules : return sys . modules [ mname ] # otherwise, if the module name is within the cache, # the module exists within the BOOST_BUILD_PATH, # load it. elif mname : # in some cases, self.loaded_tool_module_path_ needs to # have the path to the file during the import # (project.initialize() for example), # so the path needs to be set *before* importing the module. path = os . path . join ( b2 . __path__ [ 0 ] , * mname . split ( '.' ) [ 1 : ] ) self . loaded_tool_module_path_ [ mname ] = path # mname is guaranteed to be importable since it was # found within the cache __import__ ( mname ) module = sys . modules [ mname ] self . loaded_tool_modules_ [ name ] = module return module self . manager . errors ( ) ( "Cannot find module '%s'" % name )