id int64 1 6.07M | name stringlengths 1 295 | code stringlengths 12 426k | language stringclasses 1
value | source_file stringlengths 5 202 | start_line int64 1 158k | end_line int64 1 158k | repo dict |
|---|---|---|---|---|---|---|---|
2,901 | commit_hash | def commit_hash(self) -> str:
return self._instance.commit_hash | python | wandb/sdk/wandb_run.py | 3,815 | 3,816 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,902 | description | def description(self) -> Optional[str]:
return self._instance.description | python | wandb/sdk/wandb_run.py | 3,819 | 3,820 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,903 | description | def description(self, desc: Optional[str]) -> None:
self._instance.description = desc | python | wandb/sdk/wandb_run.py | 3,823 | 3,824 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,904 | metadata | def metadata(self) -> dict:
return self._instance.metadata | python | wandb/sdk/wandb_run.py | 3,827 | 3,828 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,905 | metadata | def metadata(self, metadata: dict) -> None:
self._instance.metadata = metadata | python | wandb/sdk/wandb_run.py | 3,831 | 3,832 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,906 | aliases | def aliases(self) -> List[str]:
return self._instance.aliases | python | wandb/sdk/wandb_run.py | 3,835 | 3,836 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,907 | aliases | def aliases(self, aliases: List[str]) -> None:
self._instance.aliases = aliases | python | wandb/sdk/wandb_run.py | 3,839 | 3,840 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,908 | used_by | def used_by(self) -> List["wandb.apis.public.Run"]:
return self._instance.used_by() | python | wandb/sdk/wandb_run.py | 3,842 | 3,843 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,909 | logged_by | def logged_by(self) -> "wandb.apis.public.Run":
return self._instance.logged_by() | python | wandb/sdk/wandb_run.py | 3,845 | 3,846 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,910 | get_path | def get_path(self, name: str) -> "ArtifactManifestEntry":
return self._instance.get_path(name) | python | wandb/sdk/wandb_run.py | 3,848 | 3,849 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,911 | get | def get(self, name: str) -> "WBValue":
return self._instance.get(name) | python | wandb/sdk/wandb_run.py | 3,851 | 3,852 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,912 | download | def download(
self, root: Optional[str] = None, recursive: bool = False
) -> util.FilePathStr:
return self._instance.download(root, recursive) | python | wandb/sdk/wandb_run.py | 3,854 | 3,857 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,913 | checkout | def checkout(self, root: Optional[str] = None) -> str:
return self._instance.checkout(root) | python | wandb/sdk/wandb_run.py | 3,859 | 3,860 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,914 | verify | def verify(self, root: Optional[str] = None) -> Any:
return self._instance.verify(root) | python | wandb/sdk/wandb_run.py | 3,862 | 3,863 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,915 | save | def save(self) -> None:
self._instance.save() | python | wandb/sdk/wandb_run.py | 3,865 | 3,866 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,916 | delete | def delete(self) -> None:
self._instance.delete() | python | wandb/sdk/wandb_run.py | 3,868 | 3,869 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,917 | save | def save(path, overwrite=None):
logger.info("Saving file: %s", path)
wandb.run.save(path) | python | wandb/sdk/wandb_save.py | 11 | 13 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,918 | __init__ | def __init__(self, entry: ArtifactManifestEntry, obj: data_types.WBValue):
self.entry = entry
self.obj = obj | python | wandb/sdk/wandb_artifacts.py | 95 | 97 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,919 | _normalize_metadata | def _normalize_metadata(metadata: Optional[Dict[str, Any]]) -> Dict[str, Any]:
if metadata is None:
return {}
if not isinstance(metadata, dict):
raise TypeError(f"metadata must be dict, not {type(metadata)}")
return cast(
Dict[str, Any], json.loads(json.dumps(util.json_friendly_val(metadata)))
) | python | wandb/sdk/wandb_artifacts.py | 100 | 107 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,920 | __init__ | def __init__(
self,
name: str,
type: str,
description: Optional[str] = None,
metadata: Optional[dict] = None,
incremental: Optional[bool] = None,
use_as: Optional[str] = None,
) -> None:
if not re.match(r"^[a-zA-Z0-9_\-.]+$", name):
raise ValueError(
"Artifact name may only contain alphanumeric characters, dashes, underscores, and dots. "
'Invalid name: "%s"' % name
)
metadata = _normalize_metadata(metadata)
# TODO: this shouldn't be a property of the artifact. It's a more like an
# argument to log_artifact.
storage_layout = StorageLayout.V2
if env.get_use_v1_artifacts():
storage_layout = StorageLayout.V1
self._storage_policy = WandbStoragePolicy(
config={
"storageLayout": storage_layout,
# TODO: storage region
}
)
self._api = InternalApi()
self._final = False
self._digest = ""
self._file_entries = None
self._manifest = ArtifactManifestV1(self._storage_policy)
self._cache = get_artifacts_cache()
self._added_objs = {}
self._added_local_paths = {}
# You can write into this directory when creating artifact files
self._artifact_dir = tempfile.TemporaryDirectory()
self._type = type
self._name = name
self._description = description
self._metadata = metadata
self._distributed_id = None
self._logged_artifact = None
self._incremental = False
self._client_id = runid.generate_id(128)
self._sequence_client_id = runid.generate_id(128)
self._cache.store_client_artifact(self)
self._use_as = use_as
if incremental:
self._incremental = incremental
wandb.termwarn("Using experimental arg `incremental`") | python | wandb/sdk/wandb_artifacts.py | 154 | 205 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,921 | id | def id(self) -> Optional[str]:
if self._logged_artifact:
return self._logged_artifact.id
# The artifact hasn't been saved so an ID doesn't exist yet.
return None | python | wandb/sdk/wandb_artifacts.py | 208 | 213 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,922 | source_version | def source_version(self) -> Optional[str]:
if self._logged_artifact:
return self._logged_artifact.source_version
return None | python | wandb/sdk/wandb_artifacts.py | 216 | 220 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,923 | version | def version(self) -> str:
if self._logged_artifact:
return self._logged_artifact.version
raise ArtifactNotLoggedError(self, "version") | python | wandb/sdk/wandb_artifacts.py | 223 | 227 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,924 | entity | def entity(self) -> str:
if self._logged_artifact:
return self._logged_artifact.entity
return self._api.settings("entity") or self._api.viewer().get("entity") # type: ignore | python | wandb/sdk/wandb_artifacts.py | 230 | 233 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,925 | project | def project(self) -> str:
if self._logged_artifact:
return self._logged_artifact.project
return self._api.settings("project") # type: ignore | python | wandb/sdk/wandb_artifacts.py | 236 | 240 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,926 | manifest | def manifest(self) -> ArtifactManifest:
if self._logged_artifact:
return self._logged_artifact.manifest
self.finalize()
return self._manifest | python | wandb/sdk/wandb_artifacts.py | 243 | 248 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,927 | digest | def digest(self) -> str:
if self._logged_artifact:
return self._logged_artifact.digest
self.finalize()
# Digest will be none if the artifact hasn't been saved yet.
return self._digest | python | wandb/sdk/wandb_artifacts.py | 251 | 257 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,928 | type | def type(self) -> str:
if self._logged_artifact:
return self._logged_artifact.type
return self._type | python | wandb/sdk/wandb_artifacts.py | 260 | 264 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,929 | name | def name(self) -> str:
if self._logged_artifact:
return self._logged_artifact.name
return self._name | python | wandb/sdk/wandb_artifacts.py | 267 | 271 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,930 | state | def state(self) -> str:
if self._logged_artifact:
return self._logged_artifact.state
return "PENDING" | python | wandb/sdk/wandb_artifacts.py | 274 | 278 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,931 | size | def size(self) -> int:
if self._logged_artifact:
return self._logged_artifact.size
sizes: List[int]
sizes = []
for entry in self._manifest.entries:
e_size = self._manifest.entries[entry].size
if e_size is not None:
sizes.append(e_size)
return sum(sizes) | python | wandb/sdk/wandb_artifacts.py | 281 | 290 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,932 | commit_hash | def commit_hash(self) -> str:
if self._logged_artifact:
return self._logged_artifact.commit_hash
raise ArtifactNotLoggedError(self, "commit_hash") | python | wandb/sdk/wandb_artifacts.py | 293 | 297 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,933 | description | def description(self) -> Optional[str]:
if self._logged_artifact:
return self._logged_artifact.description
return self._description | python | wandb/sdk/wandb_artifacts.py | 300 | 304 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,934 | description | def description(self, desc: Optional[str]) -> None:
if self._logged_artifact:
self._logged_artifact.description = desc
return
self._description = desc | python | wandb/sdk/wandb_artifacts.py | 307 | 312 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,935 | metadata | def metadata(self) -> dict:
if self._logged_artifact:
return self._logged_artifact.metadata
return self._metadata | python | wandb/sdk/wandb_artifacts.py | 315 | 319 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,936 | metadata | def metadata(self, metadata: dict) -> None:
metadata = _normalize_metadata(metadata)
if self._logged_artifact:
self._logged_artifact.metadata = metadata
return
self._metadata = metadata | python | wandb/sdk/wandb_artifacts.py | 322 | 328 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,937 | aliases | def aliases(self) -> List[str]:
if self._logged_artifact:
return self._logged_artifact.aliases
raise ArtifactNotLoggedError(self, "aliases") | python | wandb/sdk/wandb_artifacts.py | 331 | 335 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,938 | aliases | def aliases(self, aliases: List[str]) -> None:
"""Set artifact aliases.
Arguments:
aliases: (list) The list of aliases associated with this artifact.
"""
if self._logged_artifact:
self._logged_artifact.aliases = aliases
return
raise ArtifactNotLoggedError(self, "aliases") | python | wandb/sdk/wandb_artifacts.py | 338 | 348 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,939 | use_as | def use_as(self) -> Optional[str]:
return self._use_as | python | wandb/sdk/wandb_artifacts.py | 351 | 352 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,940 | distributed_id | def distributed_id(self) -> Optional[str]:
return self._distributed_id | python | wandb/sdk/wandb_artifacts.py | 355 | 356 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,941 | distributed_id | def distributed_id(self, distributed_id: Optional[str]) -> None:
self._distributed_id = distributed_id | python | wandb/sdk/wandb_artifacts.py | 359 | 360 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,942 | incremental | def incremental(self) -> bool:
return self._incremental | python | wandb/sdk/wandb_artifacts.py | 363 | 364 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,943 | used_by | def used_by(self) -> List["wandb.apis.public.Run"]:
if self._logged_artifact:
return self._logged_artifact.used_by()
raise ArtifactNotLoggedError(self, "used_by") | python | wandb/sdk/wandb_artifacts.py | 366 | 370 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,944 | logged_by | def logged_by(self) -> "wandb.apis.public.Run":
if self._logged_artifact:
return self._logged_artifact.logged_by()
raise ArtifactNotLoggedError(self, "logged_by") | python | wandb/sdk/wandb_artifacts.py | 372 | 376 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,945 | new_file | def new_file(
self, name: str, mode: str = "w", encoding: Optional[str] = None
) -> Generator[IO, None, None]:
self._ensure_can_add()
path = os.path.join(self._artifact_dir.name, name.lstrip("/"))
if os.path.exists(path):
raise ValueError(f"File with name {name!r} already exists at {path!r}")
filesystem.mkdir_exists_ok(os.path.dirname(path))
try:
with util.fsync_open(path, mode, encoding) as f:
yield f
except UnicodeEncodeError as e:
wandb.termerror(
f"Failed to open the provided file (UnicodeEncodeError: {e}). Please provide the proper encoding."
)
raise e
self.add_file(path, name=name) | python | wandb/sdk/wandb_artifacts.py | 379 | 396 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,946 | add_file | def add_file(
self,
local_path: str,
name: Optional[str] = None,
is_tmp: Optional[bool] = False,
) -> ArtifactManifestEntry:
self._ensure_can_add()
if not os.path.isfile(local_path):
raise ValueError("Path is not a file: %s" % local_path)
name = util.to_forward_slash_path(name or os.path.basename(local_path))
digest = md5_file_b64(local_path)
if is_tmp:
file_path, file_name = os.path.split(name)
file_name_parts = file_name.split(".")
file_name_parts[0] = b64_to_hex_id(digest)[:20]
name = os.path.join(file_path, ".".join(file_name_parts))
return self._add_local_file(name, local_path, digest=digest) | python | wandb/sdk/wandb_artifacts.py | 398 | 417 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,947 | add_dir | def add_dir(self, local_path: str, name: Optional[str] = None) -> None:
self._ensure_can_add()
if not os.path.isdir(local_path):
raise ValueError("Path is not a directory: %s" % local_path)
termlog(
"Adding directory to artifact (%s)... "
% os.path.join(".", os.path.normpath(local_path)),
newline=False,
)
start_time = time.time()
paths = []
for dirpath, _, filenames in os.walk(local_path, followlinks=True):
for fname in filenames:
physical_path = os.path.join(dirpath, fname)
logical_path = os.path.relpath(physical_path, start=local_path)
if name is not None:
logical_path = os.path.join(name, logical_path)
paths.append((logical_path, physical_path))
def add_manifest_file(log_phy_path: Tuple[str, str]) -> None:
logical_path, physical_path = log_phy_path
self._add_local_file(logical_path, physical_path)
import multiprocessing.dummy # this uses threads
num_threads = 8
pool = multiprocessing.dummy.Pool(num_threads)
pool.map(add_manifest_file, paths)
pool.close()
pool.join()
termlog("Done. %.1fs" % (time.time() - start_time), prefix=False) | python | wandb/sdk/wandb_artifacts.py | 419 | 452 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,948 | add_manifest_file | def add_manifest_file(log_phy_path: Tuple[str, str]) -> None:
logical_path, physical_path = log_phy_path
self._add_local_file(logical_path, physical_path) | python | wandb/sdk/wandb_artifacts.py | 440 | 442 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,949 | add_reference | def add_reference(
self,
uri: Union[ArtifactManifestEntry, str],
name: Optional[str] = None,
checksum: bool = True,
max_objects: Optional[int] = None,
) -> Sequence[ArtifactManifestEntry]:
self._ensure_can_add()
if name is not None:
name = util.to_forward_slash_path(name)
# This is a bit of a hack, we want to check if the uri is a of the type
# ArtifactManifestEntry which is a private class returned by Artifact.get_path in
# wandb/apis/public.py. If so, then recover the reference URL.
if isinstance(uri, ArtifactManifestEntry) and uri.parent_artifact() != self:
ref_url_fn = uri.ref_url
uri_str = ref_url_fn()
elif isinstance(uri, str):
uri_str = uri
url = urlparse(str(uri_str))
if not url.scheme:
raise ValueError(
"References must be URIs. To reference a local file, use file://"
)
manifest_entries = self._storage_policy.store_reference(
self,
URIStr(uri_str),
name=name,
checksum=checksum,
max_objects=max_objects,
)
for entry in manifest_entries:
self._manifest.add_entry(entry)
return manifest_entries | python | wandb/sdk/wandb_artifacts.py | 454 | 489 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,950 | add | def add(self, obj: data_types.WBValue, name: str) -> ArtifactManifestEntry:
self._ensure_can_add()
name = util.to_forward_slash_path(name)
# This is a "hack" to automatically rename tables added to
# the wandb /media/tables directory to their sha-based name.
# TODO: figure out a more appropriate convention.
is_tmp_name = name.startswith("media/tables")
# Validate that the object is one of the correct wandb.Media types
# TODO: move this to checking subclass of wandb.Media once all are
# generally supported
allowed_types = [
data_types.Bokeh,
data_types.JoinedTable,
data_types.PartitionedTable,
data_types.Table,
data_types.Classes,
data_types.ImageMask,
data_types.BoundingBoxes2D,
data_types.Audio,
data_types.Image,
data_types.Video,
data_types.Html,
data_types.Object3D,
data_types.Molecule,
data_types._SavedModel,
]
if not any(isinstance(obj, t) for t in allowed_types):
raise ValueError(
"Found object of type {}, expected one of {}.".format(
obj.__class__, allowed_types
)
)
obj_id = id(obj)
if obj_id in self._added_objs:
return self._added_objs[obj_id].entry
# If the object is coming from another artifact, save it as a reference
ref_path = obj._get_artifact_entry_ref_url()
if ref_path is not None:
return self.add_reference(ref_path, type(obj).with_suffix(name))[0]
val = obj.to_json(self)
name = obj.with_suffix(name)
entry = self._manifest.get_entry_by_path(name)
if entry is not None:
return entry
def do_write(f: IO) -> None:
import json
# TODO: Do we need to open with utf-8 codec?
f.write(json.dumps(val, sort_keys=True))
if is_tmp_name:
file_path = os.path.join(ARTIFACT_TMP.name, str(id(self)), name)
folder_path, _ = os.path.split(file_path)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
with open(file_path, "w") as tmp_f:
do_write(tmp_f)
else:
with self.new_file(name) as f:
file_path = f.name
do_write(f)
# Note, we add the file from our temp directory.
# It will be added again later on finalize, but succeed since
# the checksum should match
entry = self.add_file(file_path, name, is_tmp_name)
self._added_objs[obj_id] = _AddedObj(entry, obj)
if obj._artifact_target is None:
obj._set_artifact_target(self, entry.path)
if is_tmp_name:
if os.path.exists(file_path):
os.remove(file_path)
return entry | python | wandb/sdk/wandb_artifacts.py | 491 | 572 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,951 | do_write | def do_write(f: IO) -> None:
import json
# TODO: Do we need to open with utf-8 codec?
f.write(json.dumps(val, sort_keys=True)) | python | wandb/sdk/wandb_artifacts.py | 542 | 546 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,952 | get_path | def get_path(self, name: str) -> ArtifactManifestEntry:
if self._logged_artifact:
return self._logged_artifact.get_path(name)
raise ArtifactNotLoggedError(self, "get_path") | python | wandb/sdk/wandb_artifacts.py | 574 | 578 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,953 | get | def get(self, name: str) -> data_types.WBValue:
if self._logged_artifact:
return self._logged_artifact.get(name)
raise ArtifactNotLoggedError(self, "get") | python | wandb/sdk/wandb_artifacts.py | 580 | 584 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,954 | download | def download(
self, root: Optional[str] = None, recursive: bool = False
) -> FilePathStr:
if self._logged_artifact:
return self._logged_artifact.download(root=root, recursive=recursive)
raise ArtifactNotLoggedError(self, "download") | python | wandb/sdk/wandb_artifacts.py | 586 | 592 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,955 | checkout | def checkout(self, root: Optional[str] = None) -> str:
if self._logged_artifact:
return self._logged_artifact.checkout(root=root)
raise ArtifactNotLoggedError(self, "checkout") | python | wandb/sdk/wandb_artifacts.py | 594 | 598 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,956 | verify | def verify(self, root: Optional[str] = None) -> bool:
if self._logged_artifact:
return self._logged_artifact.verify(root=root)
raise ArtifactNotLoggedError(self, "verify") | python | wandb/sdk/wandb_artifacts.py | 600 | 604 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,957 | save | def save(
self,
project: Optional[str] = None,
settings: Optional["wandb.wandb_sdk.wandb_settings.Settings"] = None,
) -> None:
"""Persist any changes made to the artifact.
If currently in a run, that run will log this artifact. If not currently in a
run, a run of type "auto" will be created to track this artifact.
Arguments:
project: (str, optional) A project to use for the artifact in the case that
a run is not already in context settings: (wandb.Settings, optional) A
settings object to use when initializing an automatic run. Most commonly
used in testing harness.
Returns:
None
"""
if self._incremental:
with wandb_lib.telemetry.context() as tel:
tel.feature.artifact_incremental = True
if self._logged_artifact:
return self._logged_artifact.save()
else:
if wandb.run is None:
if settings is None:
settings = wandb.Settings(silent="true")
with wandb.init(
project=project, job_type="auto", settings=settings
) as run:
# redoing this here because in this branch we know we didn't
# have the run at the beginning of the method
if self._incremental:
with wandb_lib.telemetry.context(run=run) as tel:
tel.feature.artifact_incremental = True
run.log_artifact(self)
else:
wandb.run.log_artifact(self) | python | wandb/sdk/wandb_artifacts.py | 606 | 645 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,958 | delete | def delete(self) -> None:
if self._logged_artifact:
return self._logged_artifact.delete()
raise ArtifactNotLoggedError(self, "delete") | python | wandb/sdk/wandb_artifacts.py | 647 | 651 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,959 | wait | def wait(self, timeout: Optional[int] = None) -> ArtifactInterface:
"""Wait for an artifact to finish logging.
Arguments:
timeout: (int, optional) Wait up to this long.
"""
if self._logged_artifact:
return self._logged_artifact.wait(timeout) # type: ignore [call-arg]
raise ArtifactNotLoggedError(self, "wait") | python | wandb/sdk/wandb_artifacts.py | 653 | 662 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,960 | get_added_local_path_name | def get_added_local_path_name(self, local_path: str) -> Optional[str]:
"""Get the artifact relative name of a file added by a local filesystem path.
Arguments:
local_path: (str) The local path to resolve into an artifact relative name.
Returns:
str: The artifact relative name.
Examples:
Basic usage
```
artifact = wandb.Artifact('my_dataset', type='dataset')
artifact.add_file('path/to/file.txt', name='artifact/path/file.txt')
# Returns `artifact/path/file.txt`:
name = artifact.get_added_local_path_name('path/to/file.txt')
```
"""
entry = self._added_local_paths.get(local_path, None)
if entry is None:
return None
return entry.path | python | wandb/sdk/wandb_artifacts.py | 664 | 686 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,961 | finalize | def finalize(self) -> None:
"""Mark this artifact as final, disallowing further modifications.
This happens automatically when calling `log_artifact`.
Returns:
None
"""
if self._final:
return self._file_entries
# mark final after all files are added
self._final = True
self._digest = self._manifest.digest() | python | wandb/sdk/wandb_artifacts.py | 688 | 701 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,962 | json_encode | def json_encode(self) -> Dict[str, Any]:
if not self._logged_artifact:
raise ArtifactNotLoggedError(self, "json_encode")
return util.artifact_to_json(self) | python | wandb/sdk/wandb_artifacts.py | 703 | 706 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,963 | _ensure_can_add | def _ensure_can_add(self) -> None:
if self._final:
raise ArtifactFinalizedError(artifact=self) | python | wandb/sdk/wandb_artifacts.py | 708 | 710 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,964 | _add_local_file | def _add_local_file(
self, name: str, path: str, digest: Optional[B64MD5] = None
) -> ArtifactManifestEntry:
digest = digest or md5_file_b64(path)
size = os.path.getsize(path)
name = util.to_forward_slash_path(name)
with tempfile.NamedTemporaryFile(dir=get_staging_dir(), delete=False) as f:
staging_path = f.name
shutil.copyfile(path, staging_path)
entry = ArtifactManifestEntry(
path=name,
digest=digest,
size=size,
local_path=staging_path,
)
self._manifest.add_entry(entry)
self._added_local_paths[path] = entry
return entry | python | wandb/sdk/wandb_artifacts.py | 712 | 732 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,965 | version | def version(cls) -> int:
return 1 | python | wandb/sdk/wandb_artifacts.py | 737 | 738 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,966 | from_manifest_json | def from_manifest_json(cls, manifest_json: Dict) -> "ArtifactManifestV1":
if manifest_json["version"] != cls.version():
raise ValueError(
"Expected manifest version 1, got %s" % manifest_json["version"]
)
storage_policy_name = manifest_json["storagePolicy"]
storage_policy_config = manifest_json.get("storagePolicyConfig", {})
storage_policy_cls = StoragePolicy.lookup_by_name(storage_policy_name)
if storage_policy_cls is None:
raise ValueError('Failed to find storage policy "%s"' % storage_policy_name)
if not issubclass(storage_policy_cls, WandbStoragePolicy):
raise ValueError(
"No handler found for storage handler of type '%s'"
% storage_policy_name
)
entries: Mapping[str, ArtifactManifestEntry]
entries = {
name: ArtifactManifestEntry(
path=LogicalFilePathStr(name),
digest=val["digest"],
birth_artifact_id=val.get("birthArtifactID"),
ref=val.get("ref"),
size=val.get("size"),
extra=val.get("extra"),
local_path=val.get("local_path"),
)
for name, val in manifest_json["contents"].items()
}
return cls(storage_policy_cls.from_config(storage_policy_config), entries) | python | wandb/sdk/wandb_artifacts.py | 741 | 772 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,967 | __init__ | def __init__(
self,
storage_policy: "WandbStoragePolicy",
entries: Optional[Mapping[str, ArtifactManifestEntry]] = None,
) -> None:
super().__init__(storage_policy, entries=entries) | python | wandb/sdk/wandb_artifacts.py | 774 | 779 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,968 | to_manifest_json | def to_manifest_json(self) -> Dict:
"""This is the JSON that's stored in wandb_manifest.json.
If include_local is True we also include the local paths to files. This is
used to represent an artifact that's waiting to be saved on the current
system. We don't need to include the local paths in the artifact manifest
contents.
"""
contents = {}
for entry in sorted(self.entries.values(), key=lambda k: k.path):
json_entry: Dict[str, Any] = {
"digest": entry.digest,
}
if entry.birth_artifact_id:
json_entry["birthArtifactID"] = entry.birth_artifact_id
if entry.ref:
json_entry["ref"] = entry.ref
if entry.extra:
json_entry["extra"] = entry.extra
if entry.size is not None:
json_entry["size"] = entry.size
contents[entry.path] = json_entry
return {
"version": self.__class__.version(),
"storagePolicy": self.storage_policy.name(),
"storagePolicyConfig": self.storage_policy.config() or {},
"contents": contents,
} | python | wandb/sdk/wandb_artifacts.py | 781 | 808 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,969 | digest | def digest(self) -> HexMD5:
hasher = hashlib.md5()
hasher.update(b"wandb-artifact-manifest-v1\n")
for name, entry in sorted(self.entries.items(), key=lambda kv: kv[0]):
hasher.update(f"{name}:{entry.digest}\n".encode())
return HexMD5(hasher.hexdigest()) | python | wandb/sdk/wandb_artifacts.py | 810 | 815 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,970 | name | def name(cls) -> str:
return "wandb-storage-policy-v1" | python | wandb/sdk/wandb_artifacts.py | 820 | 821 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,971 | from_config | def from_config(cls, config: Dict) -> "WandbStoragePolicy":
return cls(config=config) | python | wandb/sdk/wandb_artifacts.py | 824 | 825 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,972 | __init__ | def __init__(
self,
config: Optional[Dict] = None,
cache: Optional[ArtifactsCache] = None,
api: Optional[InternalApi] = None,
) -> None:
self._cache = cache or get_artifacts_cache()
self._config = config or {}
self._session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
max_retries=_REQUEST_RETRY_STRATEGY,
pool_connections=_REQUEST_POOL_CONNECTIONS,
pool_maxsize=_REQUEST_POOL_MAXSIZE,
)
self._session.mount("http://", adapter)
self._session.mount("https://", adapter)
s3 = S3Handler()
gcs = GCSHandler()
http = HTTPHandler(self._session)
https = HTTPHandler(self._session, scheme="https")
artifact = WBArtifactHandler()
local_artifact = WBLocalArtifactHandler()
file_handler = LocalFileHandler()
self._api = api or InternalApi()
self._handler = MultiHandler(
handlers=[
s3,
gcs,
http,
https,
artifact,
local_artifact,
file_handler,
],
default_handler=TrackingHandler(),
) | python | wandb/sdk/wandb_artifacts.py | 827 | 864 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,973 | config | def config(self) -> Dict:
return self._config | python | wandb/sdk/wandb_artifacts.py | 866 | 867 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,974 | load_file | def load_file(
self,
artifact: ArtifactInterface,
manifest_entry: ArtifactManifestEntry,
) -> str:
path, hit, cache_open = self._cache.check_md5_obj_path(
B64MD5(manifest_entry.digest), # TODO(spencerpearson): unsafe cast
manifest_entry.size if manifest_entry.size is not None else 0,
)
if hit:
return path
response = self._session.get(
self._file_url(self._api, artifact.entity, manifest_entry),
auth=("api", self._api.api_key),
stream=True,
)
response.raise_for_status()
with cache_open(mode="wb") as file:
for data in response.iter_content(chunk_size=16 * 1024):
file.write(data)
return path | python | wandb/sdk/wandb_artifacts.py | 869 | 891 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,975 | store_reference | def store_reference(
self,
artifact: ArtifactInterface,
path: Union[URIStr, FilePathStr],
name: Optional[str] = None,
checksum: bool = True,
max_objects: Optional[int] = None,
) -> Sequence[ArtifactManifestEntry]:
return self._handler.store_path(
artifact, path, name=name, checksum=checksum, max_objects=max_objects
) | python | wandb/sdk/wandb_artifacts.py | 893 | 903 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,976 | load_reference | def load_reference(
self,
manifest_entry: ArtifactManifestEntry,
local: bool = False,
) -> str:
return self._handler.load_path(manifest_entry, local) | python | wandb/sdk/wandb_artifacts.py | 905 | 910 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,977 | _file_url | def _file_url(
self, api: InternalApi, entity_name: str, manifest_entry: ArtifactManifestEntry
) -> str:
storage_layout = self._config.get("storageLayout", StorageLayout.V1)
storage_region = self._config.get("storageRegion", "default")
md5_hex = b64_to_hex_id(B64MD5(manifest_entry.digest))
if storage_layout == StorageLayout.V1:
return "{}/artifacts/{}/{}".format(
api.settings("base_url"), entity_name, md5_hex
)
elif storage_layout == StorageLayout.V2:
return "{}/artifactsV2/{}/{}/{}/{}".format(
api.settings("base_url"),
storage_region,
entity_name,
quote(
manifest_entry.birth_artifact_id
if manifest_entry.birth_artifact_id is not None
else ""
),
md5_hex,
)
else:
raise Exception(f"unrecognized storage layout: {storage_layout}") | python | wandb/sdk/wandb_artifacts.py | 912 | 936 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,978 | store_file_sync | def store_file_sync(
self,
artifact_id: str,
artifact_manifest_id: str,
entry: ArtifactManifestEntry,
preparer: "StepPrepare",
progress_callback: Optional["progress.ProgressFn"] = None,
) -> bool:
"""Upload a file to the artifact store.
Returns:
True if the file was a duplicate (did not need to be uploaded),
False if it needed to be uploaded or was a reference (nothing to dedupe).
"""
resp = preparer.prepare_sync(
{
"artifactID": artifact_id,
"artifactManifestID": artifact_manifest_id,
"name": entry.path,
"md5": entry.digest,
}
).get()
entry.birth_artifact_id = resp.birth_artifact_id
if resp.upload_url is None:
return True
if entry.local_path is None:
return False
with open(entry.local_path, "rb") as file:
# This fails if we don't send the first byte before the signed URL expires.
self._api.upload_file_retry(
resp.upload_url,
file,
progress_callback,
extra_headers={
header.split(":", 1)[0]: header.split(":", 1)[1]
for header in (resp.upload_headers or {})
},
)
self._write_cache(entry)
return False | python | wandb/sdk/wandb_artifacts.py | 938 | 980 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,979 | store_file_async | async def store_file_async(
self,
artifact_id: str,
artifact_manifest_id: str,
entry: ArtifactManifestEntry,
preparer: "StepPrepare",
progress_callback: Optional["progress.ProgressFn"] = None,
) -> bool:
"""Async equivalent to `store_file_sync`."""
resp = await preparer.prepare_async(
{
"artifactID": artifact_id,
"artifactManifestID": artifact_manifest_id,
"name": entry.path,
"md5": entry.digest,
}
)
entry.birth_artifact_id = resp.birth_artifact_id
if resp.upload_url is None:
return True
if entry.local_path is None:
return False
with open(entry.local_path, "rb") as file:
# This fails if we don't send the first byte before the signed URL expires.
await self._api.upload_file_retry_async(
resp.upload_url,
file,
progress_callback,
extra_headers={
header.split(":", 1)[0]: header.split(":", 1)[1]
for header in (resp.upload_headers or {})
},
)
self._write_cache(entry)
return False | python | wandb/sdk/wandb_artifacts.py | 982 | 1,020 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,980 | _write_cache | def _write_cache(self, entry: ArtifactManifestEntry) -> None:
if entry.local_path is None:
return
# Cache upon successful upload.
_, hit, cache_open = self._cache.check_md5_obj_path(
B64MD5(entry.digest),
entry.size if entry.size is not None else 0,
)
if not hit:
with cache_open() as f:
shutil.copyfile(entry.local_path, f.name) | python | wandb/sdk/wandb_artifacts.py | 1,022 | 1,033 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,981 | name | def name(cls) -> str:
return "wandb-s3-bucket-policy-v1" | python | wandb/sdk/wandb_artifacts.py | 1,039 | 1,040 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,982 | from_config | def from_config(cls, config: Dict[str, str]) -> "__S3BucketPolicy":
if "bucket" not in config:
raise ValueError("Bucket name not found in config")
return cls(config["bucket"]) | python | wandb/sdk/wandb_artifacts.py | 1,043 | 1,046 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,983 | __init__ | def __init__(self, bucket: str) -> None:
self._bucket = bucket
s3 = S3Handler(bucket)
local = LocalFileHandler()
self._handler = MultiHandler(
handlers=[
s3,
local,
],
default_handler=TrackingHandler(),
) | python | wandb/sdk/wandb_artifacts.py | 1,048 | 1,059 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,984 | config | def config(self) -> Dict[str, str]:
return {"bucket": self._bucket} | python | wandb/sdk/wandb_artifacts.py | 1,061 | 1,062 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,985 | load_path | def load_path(
self,
manifest_entry: ArtifactManifestEntry,
local: bool = False,
) -> Union[URIStr, FilePathStr]:
return self._handler.load_path(manifest_entry, local=local) | python | wandb/sdk/wandb_artifacts.py | 1,064 | 1,069 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,986 | store_path | def store_path(
self,
artifact: ArtifactInterface,
path: Union[URIStr, FilePathStr],
name: Optional[str] = None,
checksum: bool = True,
max_objects: Optional[int] = None,
) -> Sequence[ArtifactManifestEntry]:
return self._handler.store_path(
artifact, path, name=name, checksum=checksum, max_objects=max_objects
) | python | wandb/sdk/wandb_artifacts.py | 1,071 | 1,081 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,987 | __init__ | def __init__(
self,
handlers: Optional[List[StorageHandler]] = None,
default_handler: Optional[StorageHandler] = None,
) -> None:
self._handlers = {}
self._default_handler = default_handler
handlers = handlers or []
for handler in handlers:
self._handlers[handler.scheme] = handler | python | wandb/sdk/wandb_artifacts.py | 1,087 | 1,097 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,988 | scheme | def scheme(self) -> str:
raise NotImplementedError | python | wandb/sdk/wandb_artifacts.py | 1,100 | 1,101 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,989 | load_path | def load_path(
self,
manifest_entry: ArtifactManifestEntry,
local: bool = False,
) -> Union[URIStr, FilePathStr]:
url = urlparse(manifest_entry.ref)
if url.scheme not in self._handlers:
if self._default_handler is not None:
return self._default_handler.load_path(manifest_entry, local=local)
raise ValueError(
'No storage handler registered for scheme "%s"' % str(url.scheme)
)
return self._handlers[str(url.scheme)].load_path(manifest_entry, local=local) | python | wandb/sdk/wandb_artifacts.py | 1,103 | 1,115 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,990 | store_path | def store_path(
self,
artifact: ArtifactInterface,
path: Union[URIStr, FilePathStr],
name: Optional[str] = None,
checksum: bool = True,
max_objects: Optional[int] = None,
) -> Sequence[ArtifactManifestEntry]:
url = urlparse(path)
if url.scheme not in self._handlers:
if self._default_handler is not None:
return self._default_handler.store_path(
artifact,
path,
name=name,
checksum=checksum,
max_objects=max_objects,
)
raise ValueError(
'No storage handler registered for scheme "%s"' % url.scheme
)
handler: StorageHandler
handler = self._handlers[url.scheme]
return handler.store_path(
artifact, path, name=name, checksum=checksum, max_objects=max_objects
) | python | wandb/sdk/wandb_artifacts.py | 1,117 | 1,142 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,991 | __init__ | def __init__(self, scheme: Optional[str] = None) -> None:
"""Track paths with no modification or special processing.
Useful when paths being tracked are on file systems mounted at a standardized
location.
For example, if the data to track is located on an NFS share mounted on
`/data`, then it is sufficient to just track the paths.
"""
self._scheme = scheme or "" | python | wandb/sdk/wandb_artifacts.py | 1,146 | 1,155 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,992 | scheme | def scheme(self) -> str:
return self._scheme | python | wandb/sdk/wandb_artifacts.py | 1,158 | 1,159 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,993 | load_path | def load_path(
self,
manifest_entry: ArtifactManifestEntry,
local: bool = False,
) -> Union[URIStr, FilePathStr]:
if local:
# Likely a user error. The tracking handler is
# oblivious to the underlying paths, so it has
# no way of actually loading it.
url = urlparse(manifest_entry.ref)
raise ValueError(
"Cannot download file at path %s, scheme %s not recognized"
% (str(manifest_entry.ref), str(url.scheme))
)
# TODO(spencerpearson): should this go through util.to_native_slash_path
# instead of just getting typecast?
return FilePathStr(manifest_entry.path) | python | wandb/sdk/wandb_artifacts.py | 1,161 | 1,177 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,994 | store_path | def store_path(
self,
artifact: ArtifactInterface,
path: Union[URIStr, FilePathStr],
name: Optional[str] = None,
checksum: bool = True,
max_objects: Optional[int] = None,
) -> Sequence[ArtifactManifestEntry]:
url = urlparse(path)
if name is None:
raise ValueError(
'You must pass name="<entry_name>" when tracking references with unknown schemes. ref: %s'
% path
)
termwarn(
"Artifact references with unsupported schemes cannot be checksummed: %s"
% path
)
name = LogicalFilePathStr(name or url.path[1:]) # strip leading slash
return [ArtifactManifestEntry(path=name, ref=path, digest=path)] | python | wandb/sdk/wandb_artifacts.py | 1,179 | 1,198 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,995 | __init__ | def __init__(self, scheme: Optional[str] = None) -> None:
"""Track files or directories on a local filesystem.
Expand directories to create an entry for each file contained.
"""
self._scheme = scheme or "file"
self._cache = get_artifacts_cache() | python | wandb/sdk/wandb_artifacts.py | 1,207 | 1,213 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,996 | scheme | def scheme(self) -> str:
return self._scheme | python | wandb/sdk/wandb_artifacts.py | 1,216 | 1,217 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,997 | load_path | def load_path(
self,
manifest_entry: ArtifactManifestEntry,
local: bool = False,
) -> Union[URIStr, FilePathStr]:
if manifest_entry.ref is None:
raise ValueError(f"Cannot add path with no ref: {manifest_entry.path}")
local_path = util.local_file_uri_to_path(str(manifest_entry.ref))
if not os.path.exists(local_path):
raise ValueError(
"Local file reference: Failed to find file at path %s" % local_path
)
path, hit, cache_open = self._cache.check_md5_obj_path(
B64MD5(manifest_entry.digest), # TODO(spencerpearson): unsafe cast
manifest_entry.size if manifest_entry.size is not None else 0,
)
if hit:
return path
md5 = md5_file_b64(local_path)
if md5 != manifest_entry.digest:
raise ValueError(
"Local file reference: Digest mismatch for path %s: expected %s but found %s"
% (local_path, manifest_entry.digest, md5)
)
filesystem.mkdir_exists_ok(os.path.dirname(path))
with cache_open() as f:
shutil.copy(local_path, f.name)
return path | python | wandb/sdk/wandb_artifacts.py | 1,219 | 1,250 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,998 | store_path | def store_path(
self,
artifact: ArtifactInterface,
path: Union[URIStr, FilePathStr],
name: Optional[str] = None,
checksum: bool = True,
max_objects: Optional[int] = None,
) -> Sequence[ArtifactManifestEntry]:
local_path = util.local_file_uri_to_path(path)
max_objects = max_objects or DEFAULT_MAX_OBJECTS
# We have a single file or directory
# Note, we follow symlinks for files contained within the directory
entries = []
def md5(path: str) -> B64MD5:
return (
md5_file_b64(path)
if checksum
else md5_string(str(os.stat(path).st_size))
)
if os.path.isdir(local_path):
i = 0
start_time = time.time()
if checksum:
termlog(
'Generating checksum for up to %i files in "%s"...\n'
% (max_objects, local_path),
newline=False,
)
for root, _, files in os.walk(local_path):
for sub_path in files:
i += 1
if i > max_objects:
raise ValueError(
"Exceeded %i objects tracked, pass max_objects to add_reference"
% max_objects
)
physical_path = os.path.join(root, sub_path)
# TODO(spencerpearson): this is not a "logical path" in the sense that
# `util.to_forward_slash_path` returns a "logical path"; it's a relative path
# **on the local filesystem**.
logical_path = os.path.relpath(physical_path, start=local_path)
if name is not None:
logical_path = os.path.join(name, logical_path)
entry = ArtifactManifestEntry(
path=LogicalFilePathStr(logical_path),
ref=FilePathStr(os.path.join(path, logical_path)),
size=os.path.getsize(physical_path),
digest=md5(physical_path),
)
entries.append(entry)
if checksum:
termlog("Done. %.1fs" % (time.time() - start_time), prefix=False)
elif os.path.isfile(local_path):
name = name or os.path.basename(local_path)
entry = ArtifactManifestEntry(
path=LogicalFilePathStr(name),
ref=path,
size=os.path.getsize(local_path),
digest=md5(local_path),
)
entries.append(entry)
else:
# TODO: update error message if we don't allow directories.
raise ValueError('Path "%s" must be a valid file or directory path' % path)
return entries | python | wandb/sdk/wandb_artifacts.py | 1,252 | 1,319 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
2,999 | md5 | def md5(path: str) -> B64MD5:
return (
md5_file_b64(path)
if checksum
else md5_string(str(os.stat(path).st_size))
) | python | wandb/sdk/wandb_artifacts.py | 1,266 | 1,271 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
3,000 | __init__ | def __init__(self, scheme: Optional[str] = None) -> None:
self._scheme = scheme or "s3"
self._s3 = None
self._versioning_enabled = None
self._cache = get_artifacts_cache() | python | wandb/sdk/wandb_artifacts.py | 1,327 | 1,331 | {
"name": "Git-abouvier/wandb",
"url": "https://github.com/Git-abouvier/wandb.git",
"license": "MIT",
"stars": 0,
"forks": 0
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.