Package: byoc
BYOC is a python library for integrating configuration values from any
number/kind of sources, e.g. files, command-line arguments, environment
variables, remote JSON APIs, etc.  The primary goal of BYOC is to give you
complete control over your configuration.  This means:Complete control over how files, options, etc. are named and organized.Complete control over how values from different config sources are parsed and
merged.Support for any kind of file format, argument parsing library, etc.No opinions about anything enforced by BYOC.To use BYOC, you would create a class with special attributes (called
parameters) that know where to look for configuration values.  When these
parameters are accessed, the desired values are looked up, possibly merged,
possibly cached, and returned.  Here’s a brief example:importbyocfrombyocimportKey,DocoptConfig,AppDirsConfigclassGreet(byoc.App):"""
    Say a greeting.

    Usage:
        greet <name> [-g <greeting>]
    """# Define which config sources are available to this class.__config__=[DocoptConfig,AppDirsConfig.setup(name='conf.yml'),]# Define how to search for each config value.name=byoc.param(Key(DocoptConfig,'<name>'),)greeting=byoc.param(Key(DocoptConfig,'-g'),Key(AppDirsConfig,'greeting'),default='Hello',)defmain(self):self.load(DocoptConfig)print(f"{self.greeting},{self.name}!")if__name__=='__main__':Greet.entry_point()We can configure this script from the command line:$./greet'Sir Bedevere'Hello,SirBedevere!$./greet'Sir Lancelot'-gGoodbyeGoodbye,SirLancelot!…or from its config files:$mkdir-p~/.config/greet$echo"greeting: Run away">~/.config/greet/conf.yml$greet'Sir Robin'Runaway,SirRobin!This example only scratches the surface, but hopefully you can already get a
sense for how powerful and flexible these parameters are.  For more
information, refer to the following examples (in lieu of complete
documentation).ExamplesFor some examples ofbyocbeing used in real scripts, check out theStepwise — Molecular Biologyrepository.  Almost every script in this
repository usesbyoc.  Below are some particular scripts that might be
useful:Simple scripts:aliquot.pyanneal.pykld.pyLong but straight-forward scripts:pcr.pyspin_cleanup.pygels/gel.pygels/stain.pyComplex scripts:serial_dilution.pyThis script features parameters that depend on other parameters.
Specifically, the user must provide values for any three ofvolume,conc_high,conc_low, andfactor.  Whichever one isn’t specified
is inferred from the ones that are.  This is implemented by making thebyocparameters (which in this case read only from the command-line and
not from any config files) private, then adding public properties that are
calculated from the private ones.digest.pyThis script is actually pretty simple, but it makes used of__bareinit__()to download some data from the internet.  As alluded to
above,__init__()is not called whenAppinstances are initialized
from the command-line, because__init__()might require arbitrary
arguments and is therefore considered to be part of the python API.  Instead,Appinstances are initialized by calling__bareinit__()with no
arguments.ivtt.pyThis script defines a customConfigclass to read from a sequence
database. (This example might go out of date, though; I have plans to move
that customConfiginto a different package.)