def install_bundle(self, name, path=None):
        # type: (str, str) -> Bundle
        """
        Installs the bundle with the given name

        *Note:* Before Pelix 0.5.0, this method returned the ID of the
        installed bundle, instead of the Bundle object.

        **WARNING:** The behavior of the loading process is subject to changes,
        as it does not allow to safely run multiple frameworks in the same
        Python interpreter, as they might share global module values.

        :param name: A bundle name
        :param path: Preferred path to load the module
        :return: The installed Bundle object
        :raise BundleException: Something happened
        """
        with self.__bundles_lock:
            # A bundle can't be installed twice
            for bundle in self.__bundles.values():
                if bundle.get_symbolic_name() == name:
                    _logger.debug("Already installed bundle: %s", name)
                    return bundle

            # Load the module
            try:
                if path:
                    # Use the given path in priority
                    sys.path.insert(0, path)

                try:
                    # The module has already been loaded
                    module_ = sys.modules[name]
                except KeyError:
                    # Load the module
                    #  __import__(name) -> package level
                    # import_module -> module level
                    module_ = importlib.import_module(name)
            except (ImportError, IOError) as ex:
                # Error importing the module
                raise BundleException(
                    "Error installing bundle {0}: {1}".format(name, ex)
                )
            finally:
                if path:
                    # Clean up the path. The loaded module(s) might
                    # have changed the path content, so do not use an
                    # index
                    sys.path.remove(path)

            # Add the module to sys.modules, just to be sure
            sys.modules[name] = module_

            # Compute the bundle ID
            bundle_id = self.__next_bundle_id

            # Prepare the bundle object and its context
            bundle = Bundle(self, bundle_id, name, module_)

            # Store the bundle
            self.__bundles[bundle_id] = bundle

            # Update the bundle ID counter
            self.__next_bundle_id += 1

        # Fire the bundle installed event
        event = BundleEvent(BundleEvent.INSTALLED, bundle)
        self._dispatcher.fire_bundle_event(event)
        return bundle
def install_bundle ( self , name , path = None ) : with self . __bundles_lock : for bundle in self . __bundles . values ( ) : if bundle . get_symbolic_name ( ) == name : _logger . debug ( "Already installed bundle: %s" , name ) return bundle try : if path : sys . path . insert ( 0 , path ) try : module_ = sys . modules [ name ] except KeyError : module_ = importlib . import_module ( name ) except ( ImportError , IOError ) as ex : raise BundleException ( "Error installing bundle {0}: {1}" . format ( name , ex ) ) finally : if path : sys . path . remove ( path ) sys . modules [ name ] = module_ bundle_id = self . __next_bundle_id bundle = Bundle ( self , bundle_id , name , module_ ) self . __bundles [ bundle_id ] = bundle self . __next_bundle_id += 1 event = BundleEvent ( BundleEvent . INSTALLED , bundle ) self . _dispatcher . fire_bundle_event ( event ) return bundle
Installs the bundle with the given name

        *Note:* Before Pelix 0.5.0, this method returned the ID of the
        installed bundle, instead of the Bundle object.

        **WARNING:** The behavior of the loading process is subject to changes,
        as it does not allow to safely run multiple frameworks in the same
        Python interpreter, as they might share global module values.

        :param name: A bundle name
        :param path: Preferred path to load the module
        :return: The installed Bundle object
        :raise BundleException: Something happened