Package: clickset
ClickSetClickSet is a thin wrapper around theclickandconfuselibraries, combining
them both into a simple property-like interface for use with python classes.fromclicksetimportSettingfromclicksetimportClickParamsfromclicksetimportget_configimportconfuseimportclickclassMyClass:verbose=Setting(# confuse storage path'general.verbose',# click boolean optionoption=ClickParams('--verbose/--quiet',help='Verbose or Quiet Output'))defmy_func(self):# Get the value of a Settingprint(f"verbose status:{self.verbose}")# Set the value of the property ... in memory only!self.verbose=Falseassertself.verbose==False@click.command# Load all options set in classes@Setting.optionsdefmain(**kw):# Get the default global confuse configuration singletonconfig=get_config()foo=MyClass()print(f"verbose:{foo.verbose}")assertfoo.verbose==kw['verbose']assertfoo.verbose==config['general']['verbose'].get()# confuse/click values can also be obtained directly from classes# ... NOTE: The value here is read-only!assertMyClass.verbose.get()==kw['verbose']# confuse/click values can also be obtained without a classverbose=Setting(# confuse storage path'general.verbose',# click boolean optionoption=ClickParams('--verbose/--quiet',help='Verbose or Quiet Output'))assertverbose==MyClass.verbose.get()assertverbose==foo.verbosemain(['--verbose'])Design ConceptsThis library is built around the following design concept:Define app configuration in the class where it is usedLink command line options to configuration file entriesPermit multiple configuration files covering different purposesProvide a persistent application state storage mechanismProvide a simple interface which covers common use scenariosProvide as much access as possible to underlying librariesThese design concepts led me to utilizing two base libraries to provide
functionality:confuse: Provides configurable values to an application by providing multiple
sources (memory, command line arguments, YAML files, etc.) in a priority based
list.click: Provides a command line interface which is easily extended with
additional funcitonality.While both of these libraries are very powerful tools in their own right, they
both force their relevant settings into a central location.  In order to keep
all configuration settings in the location they are used, this library combinesconfuseandclickinto a single class calledSetting. The resulting class
has the following features:All data is stored using confuseCommand line parameters provided by click are inserted into the confuse data
storeData is accessed in the same mechanism as a pythonpropertyValues can be overridden on a per-instance basis (same as setting aproperty)click/confuse values can obtained direclty usingSetting(...).get()in order
to easily obtain configured values outside of class restrictions (see the
example above)While this design is highly flexible, there are noteworthy drawbacks which must
be considered:clickparameter definitions andconfusedata stores must be defined as global
singletons.Generally this is acceptable as both configuration files and command line
interfaces have one instance per application.Multiple singletons can be created for bothconfuseandclickin order
to provide design flexibility.Command line options arealwaysgenerated if the relevant class has been
imported. This means that care must be taken with inactive code to ensure it
is not imported by the main application.This is generally a small risk if one is following good coding practices by
importing only files which are used in a module.