def _fetch_metadata_using_lazy_wheel(self, link):
        # type: (Link) -> Optional[Distribution]
        """Fetch metadata using lazy wheel, if possible."""
        if not self.use_lazy_wheel:
            return None
        if self.require_hashes:
            logger.debug('Lazy wheel is not used as hash checking is required')
            return None
        if link.is_file or not link.is_wheel:
            logger.debug(
                'Lazy wheel is not used as '
                '%r does not points to a remote wheel',
                link,
            )
            return None

        wheel = Wheel(link.filename)
        name = canonicalize_name(wheel.name)
        logger.info(
            'Obtaining dependency information from %s %s',
            name,
            wheel.version,
        )
        url = link.url.split('#', 1)[0]
        try:
            return dist_from_wheel_url(name, url, self._session)
        except HTTPRangeRequestUnsupported:
            logger.debug('%s does not support range requests', url)
            return None
Esempio n. 2
0
def test_dist_from_wheel_url(session):
    """Test if the acquired distribution contain correct information."""
    dist = dist_from_wheel_url('mypy', MYPY_0_782_WHL, session)
    assert dist.key == 'mypy'
    assert dist.version == '0.782'
    assert dist.extras == ['dmypy']
    assert set(dist.requires(dist.extras)) == MYPY_0_782_REQS
Esempio n. 3
0
def test_dist_from_wheel_url(session: PipSession) -> None:
    """Test if the acquired distribution contain correct information."""
    dist = dist_from_wheel_url("mypy", MYPY_0_782_WHL, session)
    assert dist.canonical_name == "mypy"
    assert dist.version == Version("0.782")
    extras = list(dist.iter_provided_extras())
    assert extras == ["dmypy"]
    assert {str(d) for d in dist.iter_dependencies(extras)} == MYPY_0_782_REQS
Esempio n. 4
0
 def _fetch_metadata(preparer, link):
     # type: (Link) -> Optional[Distribution]
     """Fetch metadata, using lazy wheel if possible."""
     use_lazy_wheel = preparer.use_lazy_wheel
     remote_wheel = link.is_wheel and not link.is_file
     if use_lazy_wheel and remote_wheel and not preparer.require_hashes:
         wheel = Wheel(link.filename)
         name = canonicalize_name(wheel.name)
         # If HTTPRangeRequestUnsupported is raised, fallback silently.
         with indent_log(), suppress(HTTPRangeRequestUnsupported):
             logger.info(
                 'Obtaining dependency information from %s %s',
                 name, wheel.version,
             )
             url = link.url.split('#', 1)[0]
             session = preparer.downloader._session
             return dist_from_wheel_url(name, url, session)
     return None
Esempio n. 5
0
 def _fetch_metadata(self):
     # type: () -> None
     """Fetch metadata, using lazy wheel if possible."""
     preparer = self._factory.preparer
     use_lazy_wheel = self._factory.use_lazy_wheel
     remote_wheel = self._link.is_wheel and not self._link.is_file
     if use_lazy_wheel and remote_wheel and not preparer.require_hashes:
         assert self._name is not None
         logger.info('Collecting %s', self._ireq.req or self._ireq)
         # If HTTPRangeRequestUnsupported is raised, fallback silently.
         with indent_log(), suppress(HTTPRangeRequestUnsupported):
             logger.info(
                 'Obtaining dependency information from %s %s',
                 self._name, self._version,
             )
             url = self._link.url.split('#', 1)[0]
             session = preparer.downloader._session
             self._dist = dist_from_wheel_url(self._name, url, session)
             self._check_metadata_consistency()
     if self._dist is None:
         self._prepare()
Esempio n. 6
0
def test_dist_from_wheel_url_not_zip(session):
    """Test handling with the given URL does not point to a ZIP."""
    with raises(BadZipfile):
        dist_from_wheel_url('python', 'https://www.python.org/', session)
Esempio n. 7
0
def test_dist_from_wheel_url_no_range(session, mypy_whl_no_range):
    """Test handling when HTTP range requests are not supported."""
    with raises(HTTPRangeRequestUnsupported):
        dist_from_wheel_url('mypy', mypy_whl_no_range, session)
Esempio n. 8
0
def test_dist_from_wheel_url_no_range(session, monkeypatch):
    """Test handling when HTTP range requests are not supported."""
    monkeypatch.setattr(session, 'head', lambda *a, **kw: MockResponse(b''))
    with raises(RuntimeError):
        dist_from_wheel_url('mypy', MYPY_0_782_WHL, session)
Esempio n. 9
0
def test_dist_from_wheel_url_not_zip(session: PipSession) -> None:
    """Test handling with the given URL does not point to a ZIP."""
    with raises(InvalidWheel):
        dist_from_wheel_url("python", "https://www.python.org/", session)
Esempio n. 10
0
def test_dist_from_wheel_url_no_range(session: PipSession,
                                      mypy_whl_no_range: str) -> None:
    """Test handling when HTTP range requests are not supported."""
    with raises(HTTPRangeRequestUnsupported):
        dist_from_wheel_url("mypy", mypy_whl_no_range, session)