Beispiel #1
0
def load_parcel_from_entrypoint(rv,ep):
    """
    Load the parcel defined by entrypoint `ep` into repository view `rv`

    `ep` should be an entry point yielded by ``loadable_parcels()``, and `rv`
    should be a repository view.  The egg corresponding to the entry point,
    along with any dependencies, must already be on sys.path.

    If a parcel already exists in `rv` for the entrypoint, it is updated if
    its version doesn't match the version of the egg containing the
    entry point.  If no parcel exists, it is created.
    """
    module_name = ep.module_name
    egg_version = ep.dist.version

    if ep.attrs:
        # This is a fatal error so that nobody will ship
        # a parcel with attrs set to something!
        raise AssertionError(
            "%s: parcel entrypoints must specify a module only"
            % ep.dist
        )

    old_parcel = find_parcel_from_entrypoint(rv,ep)

    if old_parcel is None:
        new_parcel = schema.parcel_for_module(module_name, rv)
        old_version = egg_version
    else:
        new_parcel = old_parcel
        old_version = getattr(old_parcel,'version','')

    #new_parcel.egg_id = ep.dist.key    XXX schema change needed for this
    new_parcel.version = egg_version

    # XXX what if parcel came from a different egg?

    if old_version <> egg_version:
        schema.synchronize(rv, module_name)     # get any new Kinds
        module = sys.modules[module_name]       # get the actual module
        if hasattr(module,'installParcel') and not hasattr(module,'__parcel__'):
            module.installParcel(new_parcel, old_version)   # upgrade!

    return new_parcel
Beispiel #2
0
def load_parcel_from_entrypoint(rv, ep):
    """
    Load the parcel defined by entrypoint `ep` into repository view `rv`

    `ep` should be an entry point yielded by ``loadable_parcels()``, and `rv`
    should be a repository view.  The egg corresponding to the entry point,
    along with any dependencies, must already be on sys.path.

    If a parcel already exists in `rv` for the entrypoint, it is updated if
    its version doesn't match the version of the egg containing the
    entry point.  If no parcel exists, it is created.
    """
    module_name = ep.module_name
    egg_version = ep.dist.version

    if ep.attrs:
        # This is a fatal error so that nobody will ship
        # a parcel with attrs set to something!
        raise AssertionError(
            "%s: parcel entrypoints must specify a module only" % ep.dist)

    old_parcel = find_parcel_from_entrypoint(rv, ep)

    if old_parcel is None:
        new_parcel = schema.parcel_for_module(module_name, rv)
        old_version = egg_version
    else:
        new_parcel = old_parcel
        old_version = getattr(old_parcel, 'version', '')

    #new_parcel.egg_id = ep.dist.key    XXX schema change needed for this
    new_parcel.version = egg_version

    # XXX what if parcel came from a different egg?

    if old_version <> egg_version:
        schema.synchronize(rv, module_name)  # get any new Kinds
        module = sys.modules[module_name]  # get the actual module
        if hasattr(module,
                   'installParcel') and not hasattr(module, '__parcel__'):
            module.installParcel(new_parcel, old_version)  # upgrade!

    return new_parcel
Beispiel #3
0
    def __syncParcel(self, pkg):
        """
        Synchronize the specified parcel's Python schema with self.repo

        This will import the corresponding Python module and synchronize its
        schema with the repository.  If the imported module has a parent
        module that has not yet been synchronized, this method will load
        the parent parcel, thereby synchronizing the parent module first.
        """
        if pkg in self._imported:
            return  # skip already-processed parcels
        else:
            self._imported.add(pkg)

        if '.' in pkg:
            # load parent first - even though schema API does this too,
            # the parcel loader will get confused and not load the
            # parent parcel correctly, unless we process it here.  :(
            parent_pkg = pkg.rsplit('.', 1)[0]
            if parent_pkg not in self._imported:
                self.__syncParcel(parent_pkg)

        # Last, but not least, actually synchronize the package
        schema.synchronize(self.itsView, pkg)
Beispiel #4
0
    def __syncParcel(self, pkg):
        """
        Synchronize the specified parcel's Python schema with self.repo

        This will import the corresponding Python module and synchronize its
        schema with the repository.  If the imported module has a parent
        module that has not yet been synchronized, this method will load
        the parent parcel, thereby synchronizing the parent module first.
        """
        if pkg in self._imported:
            return  # skip already-processed parcels
        else:
            self._imported.add(pkg)

        if '.' in pkg:
            # load parent first - even though schema API does this too,
            # the parcel loader will get confused and not load the
            # parent parcel correctly, unless we process it here.  :(
            parent_pkg = pkg.rsplit('.',1)[0]
            if parent_pkg not in self._imported:
                self.__syncParcel(parent_pkg)

        # Last, but not least, actually synchronize the package
        schema.synchronize(self.itsView, pkg)