Example #1
0
 def __init__(self,
              index_url="https://pypi.org/simple/",
              hosts=('*', ),
              ca_bundle=None,
              verify_ssl=True,
              *args,
              **kw):
     Environment.__init__(self, *args, **kw)
     self.index_url = index_url + "/"[:not index_url.endswith('/')]
     self.scanned_urls = {}
     self.fetched_urls = {}
     self.package_pages = {}
     self.allows = re.compile('|'.join(map(translate, hosts))).match
     self.to_scan = []
     use_ssl = (verify_ssl and ssl_support.is_available
                and (ca_bundle or ssl_support.find_ca_bundle()))
     if use_ssl:
         self.opener = ssl_support.opener_for(ca_bundle)
     else:
         self.opener = urllib.request.urlopen
Example #2
0
    def _load_internal_cache(cls, pex, pex_info):
        """Possibly cache out the internal cache."""
        internal_cache = os.path.join(pex, pex_info.internal_cache)
        with TRACER.timed("Searching dependency cache: %s" % internal_cache, V=2):
            if len(pex_info.distributions) == 0:
                # We have no .deps to load.
                return

            if os.path.isdir(pex):
                search_path = [
                    os.path.join(internal_cache, dist_chroot)
                    for dist_chroot in os.listdir(internal_cache)
                ]
                internal_env = Environment(search_path=search_path)
                for dist_name in internal_env:
                    for dist in internal_env[dist_name]:
                        yield dist
            else:
                with open_zip(pex) as zf:
                    for dist in cls._write_zipped_internal_cache(zf, pex_info):
                        yield dist
Example #3
0
    def _iter_requirements_requests(self, install_requests):
        if self.is_installed:
            # N.B.: Direct snip from the Environment docs:
            #
            #  You may explicitly set `platform` (and/or `python`) to ``None`` if you
            #  wish to map *all* distributions, not just those compatible with the
            #  running platform or Python version.
            #
            # Since our requested target may be foreign, we make sure find all distributions installed by
            # explicitly setting both `python` and `platform` to `None`.
            environment = Environment(search_path=[self.install_chroot],
                                      python=None,
                                      platform=None)

            distributions = []
            for dist_project_name in environment:
                distributions.extend(environment[dist_project_name])

            for install_request in install_requests:
                yield DistributionRequirements.Request(
                    target=install_request.target, distributions=distributions)