def get(path, root, type): public_api = PublicApi() entity, project, artifact_name = public_api._parse_artifact_path(path) if project is None: project = click.prompt("Enter the name of the project you want to use") try: artifact_parts = artifact_name.split(":") if len(artifact_parts) > 1: version = artifact_parts[1] artifact_name = artifact_parts[0] else: version = "latest" full_path = "{entity}/{project}/{artifact}:{version}".format( entity=entity, project=project, artifact=artifact_name, version=version ) wandb.termlog( "Downloading {type} artifact {full_path}".format( type=type or "dataset", full_path=full_path ) ) artifact = public_api.artifact(full_path, type=type) path = artifact.download(root=root) wandb.termlog("Artifact downloaded to %s" % path) except ValueError: raise ClickException("Unable to download artifact")
def put(path, name, description, type, alias): if name is None: name = os.path.basename(path) public_api = PublicApi() entity, project, artifact_name = public_api._parse_artifact_path(name) if project is None: project = click.prompt("Enter the name of the project you want to use") # TODO: settings nightmare... api = InternalApi() api.set_setting("entity", entity) api.set_setting("project", project) artifact = wandb.Artifact(name=artifact_name, type=type, description=description) artifact_path = "{entity}/{project}/{name}:{alias}".format(entity=entity, project=project, name=artifact_name, alias=alias[0]) if os.path.isdir(path): wandb.termlog("Uploading directory {path} to: \"{artifact_path}\" ({type})".format( path=path, type=type, artifact_path=artifact_path)) artifact.add_dir(path) elif os.path.isfile(path): wandb.termlog("Uploading file {path} to: \"{artifact_path}\" ({type})".format( path=path, type=type, artifact_path=artifact_path)) artifact.add_file(path) elif "://" in path: wandb.termlog("Logging reference artifact from {path} to: \"{artifact_path}\" ({type})".format( path=path, type=type, artifact_path=artifact_path)) artifact.add_reference(path) else: raise ClickException("Path argument must be a file or directory") run = wandb.init(entity=entity, project=project, config={"path": path}, job_type="cli_put") # We create the artifact manually to get the current version res = api.create_artifact(type, artifact_name, artifact.digest, entity_name=entity, project_name=project, run_name=run.id, description=description, aliases=[{"artifactCollectionName": artifact_name, "alias": a} for a in alias]) artifact_path = artifact_path.split(":")[0] + ":" + res.get("version", "latest") # Re-create the artifact and actually upload any files needed run.log_artifact(artifact, aliases=alias) wandb.termlog("Artifact uploaded, use this artifact in a run by adding:\n", prefix=False) wandb.termlog(" artifact = run.use_artifact(\"{path}\")\n".format( path=artifact_path, ), prefix=False)