示例#1
0
    def store_path(self,
                   artifact,
                   path,
                   name=None,
                   checksum=True,
                   max_objects=None):
        # Resolve the reference until the result is a concrete asset
        # so that we don't have multiple hops.
        artifact_id, artifact_file_path = WBArtifactHandler.parse_path(path)
        target_artifact = PublicApi().artifact_from_id(
            util.hex_to_b64_id(artifact_id))
        entry = target_artifact._manifest.get_entry_by_path(artifact_file_path)

        while entry.ref is not None and urlparse(
                entry.ref).scheme == self._scheme:
            artifact_id, artifact_file_path = WBArtifactHandler.parse_path(
                entry.ref)
            target_artifact = PublicApi().artifact_from_id(
                util.hex_to_b64_id(artifact_id))
            entry = target_artifact._manifest.get_entry_by_path(
                artifact_file_path)

        path = "wandb-artifact://{}/{}".format(
            util.b64_to_hex_id(target_artifact.id), str(entry.path))

        size = 0
        return [
            ArtifactManifestEntry(
                name or os.path.basename(path),
                path,
                size=size,
                digest=path,
            )
        ]
示例#2
0
 def _resolve_client_id_manifest_references(self) -> None:
     for entry_path in self._manifest.entries:
         entry = self._manifest.entries[entry_path]
         if entry.ref is not None:
             if entry.ref.startswith("wandb-client-artifact:"):
                 client_id = util.host_from_path(entry.ref)
                 artifact_file_path = util.uri_from_path(entry.ref)
                 artifact_id = self._api._resolve_client_id(client_id)
                 if artifact_id is None:
                     raise RuntimeError(
                         "Could not resolve client id {}".format(client_id))
                 entry.ref = "wandb-artifact://{}/{}".format(
                     util.b64_to_hex_id(artifact_id), artifact_file_path)
示例#3
0
    def store_path(self,
                   artifact,
                   path,
                   name=None,
                   checksum=True,
                   max_objects=None):
        """
        Stores the file or directory at the given path within the specified artifact. In this
        case we recursively resolve the reference until the result is a concrete asset so that 
        we don't have multiple hops. TODO-This resolution could be done in the server for
        performance improvements.

        Arguments:
            artifact: The artifact doing the storing
            path (str): The path to store
            name (str): If specified, the logical name that should map to `path`
        
        Returns:
            (list[ArtifactManifestEntry]): A list of manifest entries to store within the artifact
        """

        # Recursively resolve the reference until a concrete asset is found
        while path is not None and urlparse(path).scheme == self._scheme:
            artifact_id = util.host_from_path(path)
            artifact_file_path = util.uri_from_path(path)
            target_artifact = PublicArtifact.from_id(
                util.hex_to_b64_id(artifact_id), self.client)

            # this should only have an effect if the user added the reference by url
            # string directly (in other words they did not already load the artifact into ram.)
            target_artifact._load_manifest()

            entry = target_artifact._manifest.get_entry_by_path(
                artifact_file_path)
            path = entry.ref

        # Create the path reference
        path = "wandb-artifact://{}/{}".format(
            util.b64_to_hex_id(target_artifact.id), artifact_file_path)

        # Return the new entry
        return [
            ArtifactManifestEntry(
                name or os.path.basename(path),
                path,
                size=0,
                digest=entry.digest,
            )
        ]