Skip to content

Utilities#

utils #

RemoteArchive #

RemoteArchive(url: str, archive_extension: str)
Source code in src/imgnet/utils/archive.py
def __init__(self, url: str, archive_extension: str) -> None:
    self.url = url

    if archive_extension not in SUPPORTED_EXTENSIONS:
        msg = f"Invalid zip extension: {archive_extension}"
        raise ValueError(msg)
    self.archive_extension = archive_extension

check_tar_filenames #

check_tar_filenames(filenames: list[str]) -> list[str]

Check if the filenames roots are the same as the url filename stem. If they are, we can skip the extraction.

Source code in src/imgnet/utils/archive.py
def check_tar_filenames(self, filenames: list[str]) -> list[str]:
    """Check if the filenames roots are the same as the url filename stem.
    If they are, we can skip the extraction.
    """
    return [
        filename
        for filename in filenames
        if self._tar_check_root(filename)
    ]

get_idc_client #

get_idc_client() -> idc_index.IDCClient

Return the shared IDC client, creating it on first use. Thread-safe.

Source code in src/imgnet/utils/idc.py
def get_idc_client() -> IDCClient:
    """Return the shared IDC client, creating it on first use. Thread-safe."""
    if _state["client"] is None:
        with _lock:
            if _state["client"] is None:
                _state["client"] = IDCClient()

    if _state["client"] is None:
        raise RuntimeError("Failed to create IDC client")
    return _state["client"]