Example #1
0
 def test_std_install_with_direct_url(self, data, tmpdir):
     """Test that install_wheel creates direct_url.json metadata when
     provided with a direct_url argument. Also test that the RECORDS
     file contains an entry for direct_url.json in that case.
     Note direct_url.url is intentionally different from wheelpath,
     because wheelpath is typically the result of a local build.
     """
     self.prep(data, tmpdir)
     direct_url = DirectUrl(
         url="file:///home/user/archive.tgz",
         info=ArchiveInfo(),
     )
     wheel.install_wheel(
         self.name,
         self.wheelpath,
         scheme=self.scheme,
         req_description=str(self.req),
         direct_url=direct_url,
     )
     direct_url_path = os.path.join(
         self.dest_dist_info, DIRECT_URL_METADATA_NAME
     )
     self.assert_permission(direct_url_path, 0o644)
     with open(direct_url_path, 'rb') as f:
         expected_direct_url_json = direct_url.to_json()
         direct_url_json = f.read().decode("utf-8")
         assert direct_url_json == expected_direct_url_json
     # check that the direc_url file is part of RECORDS
     with open(os.path.join(self.dest_dist_info, "RECORD")) as f:
         assert DIRECT_URL_METADATA_NAME in f.read()
Example #2
0
def test_to_json():
    direct_url = DirectUrl(
        url="file:///home/user/archive.tgz",
        info=ArchiveInfo(),
    )
    direct_url.validate()
    assert direct_url.to_json() == (
        '{"archive_info": {}, "url": "file:///home/user/archive.tgz"}')
Example #3
0
 def record_download_origin(cache_dir: str,
                            download_info: DirectUrl) -> None:
     origin_path = Path(cache_dir) / ORIGIN_JSON_NAME
     if origin_path.is_file():
         origin = DirectUrl.from_json(origin_path.read_text())
         # TODO: use DirectUrl.equivalent when https://github.com/pypa/pip/pull/10564
         # is merged.
         if origin.url != download_info.url:
             logger.warning(
                 "Origin URL %s in cache entry %s does not match download URL %s. "
                 "This is likely a pip bug or a cache corruption issue.",
                 origin.url,
                 cache_dir,
                 download_info.url,
             )
     origin_path.write_text(download_info.to_json(), encoding="utf-8")