- class swh.lister.packagist.lister.PackagistListerState(last_listing_date: Optional[datetime] = None)[source]#
State of Packagist lister
- class swh.lister.packagist.lister.PackagistLister(scheduler: SchedulerInterface, credentials: Optional[Dict[str, Dict[str, List[Dict[str, str]]]]] = None, max_origins_per_page: Optional[int] = None, max_pages: Optional[int] = None, enable_origins: bool = True)[source]#
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]) PackagistListerState [source]#
Convert the state stored in the scheduler backend (as a dict), to the concrete StateType for this lister.
- state_to_dict(state: PackagistListerState) 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_origins_from_page(page: List[str]) Iterator[ListedOrigin] [source]#
Iterate on all Packagist projects and yield ListedOrigin instances.
- finalize() None [source]#
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.