Esempio n. 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()
Esempio n. 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"}')
def direct_url_from_link(link: Link,
                         source_dir: Optional[str] = None,
                         link_is_in_wheel_cache: bool = False) -> DirectUrl:
    if link.is_vcs:
        vcs_backend = vcs.get_backend_for_scheme(link.scheme)
        assert vcs_backend
        url, requested_revision, _ = vcs_backend.get_url_rev_and_auth(
            link.url_without_fragment)
        # For VCS links, we need to find out and add commit_id.
        if link_is_in_wheel_cache:
            # If the requested VCS link corresponds to a cached
            # wheel, it means the requested revision was an
            # immutable commit hash, otherwise it would not have
            # been cached. In that case we don't have a source_dir
            # with the VCS checkout.
            assert requested_revision
            commit_id = requested_revision
        else:
            # If the wheel was not in cache, it means we have
            # had to checkout from VCS to build and we have a source_dir
            # which we can inspect to find out the commit id.
            assert source_dir
            commit_id = vcs_backend.get_revision(source_dir)
        return DirectUrl(
            url=url,
            info=VcsInfo(
                vcs=vcs_backend.name,
                commit_id=commit_id,
                requested_revision=requested_revision,
            ),
            subdirectory=link.subdirectory_fragment,
        )
    elif link.is_existing_dir():
        return DirectUrl(
            url=link.url_without_fragment,
            info=DirInfo(),
            subdirectory=link.subdirectory_fragment,
        )
    else:
        hash = None
        hash_name = link.hash_name
        if hash_name:
            hash = f"{hash_name}={link.hash}"
        return DirectUrl(
            url=link.url_without_fragment,
            info=ArchiveInfo(hash=hash),
            subdirectory=link.subdirectory_fragment,
        )
Esempio n. 4
0
def test_as_pep440_requirement_archive():
    direct_url = DirectUrl(
        url="file:///home/user/archive.tgz",
        info=ArchiveInfo(),
    )
    direct_url.validate()
    assert (direct_url_as_pep440_direct_reference(
        direct_url, "pkg") == "pkg @ file:///home/user/archive.tgz")
    direct_url.subdirectory = "subdir"
    direct_url.validate()
    assert (direct_url_as_pep440_direct_reference(
        direct_url,
        "pkg") == "pkg @ file:///home/user/archive.tgz#subdirectory=subdir")
    direct_url.info.hash = "sha1=1b8c5bc61a86f377fea47b4276c8c8a5842d2220"
    direct_url.validate()
    assert (
        direct_url_as_pep440_direct_reference(
            direct_url, "pkg") == "pkg @ file:///home/user/archive.tgz"
        "#sha1=1b8c5bc61a86f377fea47b4276c8c8a5842d2220&subdirectory=subdir")
Esempio n. 5
0
 def test_download_info_archive_cache_with_origin(
         self, tmp_path: Path, shared_data: TestData) -> None:
     """Test download_info hash is set for a web archive with cache entry
     that has origin.json."""
     url = shared_data.packages.joinpath("simple-1.0.tar.gz").as_uri()
     hash = "sha256=ad977496000576e1b6c41f6449a9897087ce9da6db4f15b603fe8372af4bf3c6"
     finder = make_test_finder()
     wheel_cache = WheelCache(str(tmp_path / "cache"), FormatControl())
     cache_entry_dir = wheel_cache.get_path_for_link(Link(url))
     Path(cache_entry_dir).mkdir(parents=True)
     Path(cache_entry_dir).joinpath("origin.json").write_text(
         DirectUrl(url, ArchiveInfo(hash=hash)).to_json())
     wheel.make_wheel(name="simple",
                      version="1.0").save_to_dir(cache_entry_dir)
     with self._basic_resolver(finder, wheel_cache=wheel_cache) as resolver:
         ireq = get_processed_req_from_line(f"simple @ {url}")
         reqset = resolver.resolve([ireq], True)
         assert len(reqset.all_requirements) == 1
         req = reqset.all_requirements[0]
         assert req.original_link_is_in_wheel_cache
         assert req.download_info
         assert req.download_info.url == url
         assert isinstance(req.download_info.info, ArchiveInfo)
         assert req.download_info.info.hash == hash
Esempio n. 6
0
 def _redact_archive(url):
     direct_url = DirectUrl(
         url=url,
         info=ArchiveInfo(),
     )
     return direct_url.redacted_url