pattern: Fix and improve config overriding in from_configfile method
Fix error when a configuration value loaded from a config file is also
given as keyword parameter to the from_configfile
method.
Override configuration loaded from config file only if the provided
value is not None
.
The purpose of the second change is to be able to write a task implementation the following way (I take the Bitbucket lister as an example):
@shared_task(name=__name__ + ".IncrementalBitBucketLister")
def list_bitbucket_incremental(
page_size: Optional[int] = None,
username: Optional[str] = None,
password: Optional[str] = None,
):
"""Incremental listing of the public Bitbucket repositories."""
lister = BitbucketLister.from_configfile(
page_size=page_size, username=username, password=pasword)
return lister.run().dict()
When all parameter values are None
, those from the config file will
then be used.
When one of a task parameter is not None
, it will override the value
from the config file. This is useful when testing a lister in the docker
environment as parameters can be overridden through the swh scheduler
CLI.
Migrated from D4872 (view on Phabricator)