Skip to content

src.brag.sources

Sources of data.

Modules:

Name Description
git_commits

Load and format Git commits from a local repository.

github_commits

Fetch and format Github commits.

Classes:

Name Description
DataSource

A source of data.

LimitDataSource

A data source that limits the number of items it yields.

MapDataSource

A data source that maps a function over a data source.

DataSource 🔗

Bases: ABC

A source of data.

Methods:

Name Description
limit

Limit the number of items this data source yields.

map

Map a function over a data source.

Source code in src/brag/sources/__init__.py
class DataSource[T](abc.ABC):
    """A source of data."""

    @abc.abstractmethod
    def __iter__(self) -> Iterator[T]: ...

    @abc.abstractmethod
    def __len__(self) -> int: ...

    def limit(self, count: int) -> LimitDataSource[T]:
        """Limit the number of items this data source yields."""
        return LimitDataSource(self, count)

    def map[R](self, mapper: Callable[[T], R]) -> MapDataSource[T, R]:
        """Map a function over a data source."""
        return MapDataSource(self, mapper)

limit 🔗

limit(count: int) -> LimitDataSource[T]

Limit the number of items this data source yields.

Source code in src/brag/sources/__init__.py
def limit(self, count: int) -> LimitDataSource[T]:
    """Limit the number of items this data source yields."""
    return LimitDataSource(self, count)

map 🔗

map(mapper: Callable[[T], R]) -> MapDataSource[T, R]

Map a function over a data source.

Source code in src/brag/sources/__init__.py
def map[R](self, mapper: Callable[[T], R]) -> MapDataSource[T, R]:
    """Map a function over a data source."""
    return MapDataSource(self, mapper)

LimitDataSource dataclass 🔗

Bases: DataSource[T]

A data source that limits the number of items it yields.

Source code in src/brag/sources/__init__.py
@dataclass(frozen=True, slots=True)
class LimitDataSource[T](DataSource[T]):
    """A data source that limits the number of items it yields."""

    inner: DataSource[T]
    count: int

    def __iter__(self) -> Iterator[T]:
        return islice(self.inner, self.count)

    def __len__(self) -> int:
        return min(self.count, len(self.inner))

MapDataSource dataclass 🔗

Bases: DataSource[R]

A data source that maps a function over a data source.

Source code in src/brag/sources/__init__.py
@dataclass(frozen=True, slots=True)
class MapDataSource[T, R](DataSource[R]):
    """A data source that maps a function over a data source."""

    inner: DataSource[T]
    mapper: Callable[[T], R]

    def __iter__(self) -> Iterator[R]:
        return map(self.mapper, self.inner)

    def __len__(self) -> int:
        return len(self.inner)