Skip to content

Source

source #

BaseSource #

Bases: pydantic.BaseModel

get_downloader abstractmethod #

get_downloader() -> imgnet.download.base.BaseDownloader

Get the downloader for this source.

Source code in src/imgnet/collections/source.py
@abstractmethod
def get_downloader(self) -> BaseDownloader:
    """Get the downloader for this source."""
    raise NotImplementedError

CompositeSource #

Bases: imgnet.collections.source.BaseSource

A source that combines one or more other sources.

get_downloader #

get_downloader() -> imgnet.download.base.BaseDownloader

Return a special CompositeDownloader.

Source code in src/imgnet/collections/source.py
def get_downloader(self) -> BaseDownloader:
    """Return a special CompositeDownloader."""
    return CompositeDownloader([source.get_downloader() for source in self.sources])

validate_composite #

validate_composite() -> imgnet.collections.source.CompositeSource

Validate that all sources have the same file_type.

Source code in src/imgnet/collections/source.py
@model_validator(mode="after")
def validate_composite(self) -> "CompositeSource":
    """Validate that all sources have the same file_type."""
    if not self.sources:
        raise ValueError("CompositeSource must have at least one source")

    # Check all sources have the same file_type
    first_file_type = self.sources[0].file_type
    for source in self.sources[1:]:
        if source.file_type != first_file_type:
            msg = f"All sources in composite must have the same file_type.\nFound '{first_file_type}' and '{source.file_type}' in source '{source.source}'"
            raise ValueError(
                msg
            )

    # Ensure composite's file_type matches the sources
    if self.file_type != first_file_type:
        msg = f"Composite file_type '{self.file_type}' does not match source file_type '{first_file_type}'"
        raise ValueError(
            msg
        )

    return self