- class swh.lister.packagist.lister.PackagistListerState(last_listing_date: Optional[datetime.datetime] = None)
State of Packagist lister
- class swh.lister.packagist.lister.PackagistLister(scheduler: swh.scheduler.interface.SchedulerInterface, credentials: Optional[Dict[str, Dict[str, List[Dict[str, str]]]]] = None)
List all Packagist projects and send associated origins to scheduler.
The lister queries the Packagist API, whose documentation can be found at https://packagist.org/apidoc.
For each package, its metadata are retrieved using Packagist API endpoints whose responses are served from static files, which are guaranteed to be efficient on the Packagist side (no dymamic queries). Furthermore, subsequent listing will send the “If-Modified-Since” HTTP header to only retrieve packages metadata updated since the previous listing operation in order to save bandwidth and return only origins which might have new released versions.
- PACKAGIST_PACKAGES_LIST_URL = 'https://packagist.org/packages/list.json'
- PACKAGIST_REPO_BASE_URL = 'https://repo.packagist.org/p'
- state_from_dict(d: Dict[str, Any]) swh.lister.packagist.lister.PackagistListerState
Convert the state stored in the scheduler backend (as a dict), to the concrete StateType for this lister.
- state_to_dict(state: swh.lister.packagist.lister.PackagistListerState) Dict[str, Any]
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_origins_from_page(page: List[str]) Iterator[swh.scheduler.model.ListedOrigin]
Iterate on all Packagist projects and yield ListedOrigin instances.
- finalize() None
Custom hook to finalize the lister state before returning from the main loop.
This method must set
updatedif 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.