Python pkg_resources.EGG_DIST Examples

The following are 5 code examples of pkg_resources.EGG_DIST(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pkg_resources , or try the search function .
Example #1
Source File: pip_faster.py    From venv-update with MIT License 5 votes vote down vote up
def fresh_working_set():
    """return a pkg_resources "working set", representing the *currently* installed packages"""
    class WorkingSetPlusEditableInstalls(pkg_resources.WorkingSet):

        def __init__(self, *args, **kwargs):
            self._normalized_name_mapping = {}
            super(WorkingSetPlusEditableInstalls, self).__init__(*args, **kwargs)

        def add_entry(self, entry):
            """Same as the original .add_entry, but sets only=False, so that egg-links are honored."""
            logger.debug('working-set entry: %r', entry)
            self.entry_keys.setdefault(entry, [])
            self.entries.append(entry)
            for dist in pkg_resources.find_distributions(entry, False):

                # eggs override anything that's installed normally
                # fun fact: pkg_resources.working_set's results depend on the
                # ordering of os.listdir since the order of os.listdir is
                # entirely arbitrary (an implemenation detail of file system),
                # without calling site.main(), an .egg-link file may or may not
                # be honored, depending on the filesystem
                replace = (dist.precedence == pkg_resources.EGG_DIST)
                self._normalized_name_mapping[normalize_name(dist.key)] = dist.key
                self.add(dist, entry, False, replace=replace)

        def find_normalized(self, req):
            req = _package_req_to_pkg_resources_req(str(req))
            req.key = self._normalized_name_mapping.get(normalize_name(req.key), req.key)
            return self.find(req)

    return WorkingSetPlusEditableInstalls() 
Example #2
Source File: ah_bootstrap.py    From grizli with MIT License 4 votes vote down vote up
def run(self):
        strategies = ['local_directory', 'local_file', 'index']
        dist = None

        # First, remove any previously imported versions of astropy_helpers;
        # this is necessary for nested installs where one package's installer
        # is installing another package via setuptools.sandbox.run_setup, as in
        # the case of setup_requires
        for key in list(sys.modules):
            try:
                if key == PACKAGE_NAME or key.startswith(PACKAGE_NAME + '.'):
                    del sys.modules[key]
            except AttributeError:
                # Sometimes mysterious non-string things can turn up in
                # sys.modules
                continue

        # Check to see if the path is a submodule
        self.is_submodule = self._check_submodule()

        for strategy in strategies:
            method = getattr(self, 'get_{0}_dist'.format(strategy))
            dist = method()
            if dist is not None:
                break
        else:
            raise _AHBootstrapSystemExit(
                "No source found for the {0!r} package; {0} must be "
                "available and importable as a prerequisite to building "
                "or installing this package.".format(PACKAGE_NAME))

        # This is a bit hacky, but if astropy_helpers was loaded from a
        # directory/submodule its Distribution object gets a "precedence" of
        # "DEVELOP_DIST".  However, in other cases it gets a precedence of
        # "EGG_DIST".  However, when activing the distribution it will only be
        # placed early on sys.path if it is treated as an EGG_DIST, so always
        # do that
        dist = dist.clone(precedence=pkg_resources.EGG_DIST)

        # Otherwise we found a version of astropy-helpers, so we're done
        # Just active the found distribution on sys.path--if we did a
        # download this usually happens automatically but it doesn't hurt to
        # do it again
        # Note: Adding the dist to the global working set also activates it
        # (makes it importable on sys.path) by default.

        try:
            pkg_resources.working_set.add(dist, replace=True)
        except TypeError:
            # Some (much) older versions of setuptools do not have the
            # replace=True option here.  These versions are old enough that all
            # bets may be off anyways, but it's easy enough to work around just
            # in case...
            if dist.key in pkg_resources.working_set.by_key:
                del pkg_resources.working_set.by_key[dist.key]
            pkg_resources.working_set.add(dist) 
Example #3
Source File: ah_bootstrap.py    From specidentify with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def run(self):
        strategies = ['local_directory', 'local_file', 'index']
        dist = None

        # First, remove any previously imported versions of astropy_helpers;
        # this is necessary for nested installs where one package's installer
        # is installing another package via setuptools.sandbox.run_setup, as in
        # the case of setup_requires
        for key in list(sys.modules):
            try:
                if key == PACKAGE_NAME or key.startswith(PACKAGE_NAME + '.'):
                    del sys.modules[key]
            except AttributeError:
                # Sometimes mysterious non-string things can turn up in
                # sys.modules
                continue

        # Check to see if the path is a submodule
        self.is_submodule = self._check_submodule()

        for strategy in strategies:
            method = getattr(self, 'get_{0}_dist'.format(strategy))
            dist = method()
            if dist is not None:
                break
        else:
            raise _AHBootstrapSystemExit(
                "No source found for the {0!r} package; {0} must be "
                "available and importable as a prerequisite to building "
                "or installing this package.".format(PACKAGE_NAME))

        # This is a bit hacky, but if astropy_helpers was loaded from a
        # directory/submodule its Distribution object gets a "precedence" of
        # "DEVELOP_DIST".  However, in other cases it gets a precedence of
        # "EGG_DIST".  However, when activing the distribution it will only be
        # placed early on sys.path if it is treated as an EGG_DIST, so always
        # do that
        dist = dist.clone(precedence=pkg_resources.EGG_DIST)

        # Otherwise we found a version of astropy-helpers, so we're done
        # Just active the found distribution on sys.path--if we did a
        # download this usually happens automatically but it doesn't hurt to
        # do it again
        # Note: Adding the dist to the global working set also activates it
        # (makes it importable on sys.path) by default.

        try:
            pkg_resources.working_set.add(dist, replace=True)
        except TypeError:
            # Some (much) older versions of setuptools do not have the
            # replace=True option here.  These versions are old enough that all
            # bets may be off anyways, but it's easy enough to work around just
            # in case...
            if dist.key in pkg_resources.working_set.by_key:
                del pkg_resources.working_set.by_key[dist.key]
            pkg_resources.working_set.add(dist) 
Example #4
Source File: ah_bootstrap.py    From banzai with GNU General Public License v3.0 4 votes vote down vote up
def run(self):
        strategies = ['local_directory', 'local_file', 'index']
        dist = None

        # First, remove any previously imported versions of astropy_helpers;
        # this is necessary for nested installs where one package's installer
        # is installing another package via setuptools.sandbox.run_setup, as in
        # the case of setup_requires
        for key in list(sys.modules):
            try:
                if key == PACKAGE_NAME or key.startswith(PACKAGE_NAME + '.'):
                    del sys.modules[key]
            except AttributeError:
                # Sometimes mysterious non-string things can turn up in
                # sys.modules
                continue

        # Check to see if the path is a submodule
        self.is_submodule = self._check_submodule()

        for strategy in strategies:
            method = getattr(self, 'get_{0}_dist'.format(strategy))
            dist = method()
            if dist is not None:
                break
        else:
            raise _AHBootstrapSystemExit(
                "No source found for the {0!r} package; {0} must be "
                "available and importable as a prerequisite to building "
                "or installing this package.".format(PACKAGE_NAME))

        # This is a bit hacky, but if astropy_helpers was loaded from a
        # directory/submodule its Distribution object gets a "precedence" of
        # "DEVELOP_DIST".  However, in other cases it gets a precedence of
        # "EGG_DIST".  However, when activing the distribution it will only be
        # placed early on sys.path if it is treated as an EGG_DIST, so always
        # do that
        dist = dist.clone(precedence=pkg_resources.EGG_DIST)

        # Otherwise we found a version of astropy-helpers, so we're done
        # Just active the found distribution on sys.path--if we did a
        # download this usually happens automatically but it doesn't hurt to
        # do it again
        # Note: Adding the dist to the global working set also activates it
        # (makes it importable on sys.path) by default.

        try:
            pkg_resources.working_set.add(dist, replace=True)
        except TypeError:
            # Some (much) older versions of setuptools do not have the
            # replace=True option here.  These versions are old enough that all
            # bets may be off anyways, but it's easy enough to work around just
            # in case...
            if dist.key in pkg_resources.working_set.by_key:
                del pkg_resources.working_set.by_key[dist.key]
            pkg_resources.working_set.add(dist) 
Example #5
Source File: ah_bootstrap.py    From pydis with MIT License 4 votes vote down vote up
def run(self):
        strategies = ['local_directory', 'local_file', 'index']
        dist = None

        # First, remove any previously imported versions of astropy_helpers;
        # this is necessary for nested installs where one package's installer
        # is installing another package via setuptools.sandbox.run_setup, as in
        # the case of setup_requires
        for key in list(sys.modules):
            try:
                if key == PACKAGE_NAME or key.startswith(PACKAGE_NAME + '.'):
                    del sys.modules[key]
            except AttributeError:
                # Sometimes mysterious non-string things can turn up in
                # sys.modules
                continue

        # Check to see if the path is a submodule
        self.is_submodule = self._check_submodule()

        for strategy in strategies:
            method = getattr(self, 'get_{0}_dist'.format(strategy))
            dist = method()
            if dist is not None:
                break
        else:
            raise _AHBootstrapSystemExit(
                "No source found for the {0!r} package; {0} must be "
                "available and importable as a prerequisite to building "
                "or installing this package.".format(PACKAGE_NAME))

        # This is a bit hacky, but if astropy_helpers was loaded from a
        # directory/submodule its Distribution object gets a "precedence" of
        # "DEVELOP_DIST".  However, in other cases it gets a precedence of
        # "EGG_DIST".  However, when activing the distribution it will only be
        # placed early on sys.path if it is treated as an EGG_DIST, so always
        # do that
        dist = dist.clone(precedence=pkg_resources.EGG_DIST)

        # Otherwise we found a version of astropy-helpers, so we're done
        # Just active the found distribution on sys.path--if we did a
        # download this usually happens automatically but it doesn't hurt to
        # do it again
        # Note: Adding the dist to the global working set also activates it
        # (makes it importable on sys.path) by default.

        try:
            pkg_resources.working_set.add(dist, replace=True)
        except TypeError:
            # Some (much) older versions of setuptools do not have the
            # replace=True option here.  These versions are old enough that all
            # bets may be off anyways, but it's easy enough to work around just
            # in case...
            if dist.key in pkg_resources.working_set.by_key:
                del pkg_resources.working_set.by_key[dist.key]
            pkg_resources.working_set.add(dist)