swh.lister.hackage.lister module#

class swh.lister.hackage.lister.HackageListerState(last_listing_date: datetime | None = None)[source]#

Bases: object

Store lister state for incremental mode operations

last_listing_date: datetime | None = None#

Last date when Hackage lister was executed

class swh.lister.hackage.lister.HackageLister(scheduler: SchedulerInterface, url: str = 'https://hackage.haskell.org/', instance: str = 'hackage', credentials: Dict[str, Dict[str, List[Dict[str, str]]]] | None = None, max_origins_per_page: int | None = None, max_pages: int | None = None, enable_origins: bool = True)[source]#

Bases: Lister[HackageListerState, List[Dict[str, Any]]]

List Hackage (The Haskell Package Repository) origins.

LISTER_NAME: str = 'hackage'#
VISIT_TYPE = 'hackage'#
INSTANCE = 'hackage'#
BASE_URL = 'https://hackage.haskell.org/'#
PACKAGE_NAMES_URL_PATTERN = '{base_url}packages/search'#
PACKAGE_INFO_URL_PATTERN = '{base_url}package/{pkgname}'#
state_from_dict(d: Dict[str, Any]) HackageListerState[source]#

Convert the state stored in the scheduler backend (as a dict), to the concrete StateType for this lister.

state_to_dict(state: HackageListerState) Dict[str, Any][source]#

Convert the StateType for this lister to its serialization as dict for storage in the scheduler.

Values must be JSON-compatible as that’s what the backend database expects.

get_pages() Iterator[List[Dict[str, Any]]][source]#

Yield an iterator which returns ‘page’

It uses the http api endpoint https://hackage.haskell.org/packages/search to get a list of package names from which we build an origin url.

Results are paginated.

get_origins_from_page(page: List[Dict[str, Any]]) Iterator[ListedOrigin][source]#

Iterate on all pages and yield ListedOrigin instances.

finalize() None[source]#

Custom hook to finalize the lister state before returning from the main loop.

This method must set updated if the lister has done some work.

If relevant, this method can use :meth`get_state_from_scheduler` to merge the current lister state with the one from the scheduler backend, reducing the risk of race conditions if we’re running concurrent listings.

This method is called in a finally block, which means it will also run when the lister fails.