Package: cinnamon-core
Cinnamon (Core Package)Cinnamon is a simple framework for general-purpose configuration and code logic de-coupling.
It was developed to offer two main functionalities:De-couplinga code logic from its regulating parametersRe-useof code logic without effortDocumentationCheck the online documentation ofcinnamon-corefor more information.Check also the centralcinnamondocumentation to overview all cinnamon packages!BackgroundConsider a code logic that has to load some data.classDataLoader:defload(...):data=read_from_file(folder_name=self.folder_name)returndataThe data loader reads from a file located according toself.folder_name's value.Ifself.folder_namehas multiple values, we can use the same code logic to load data from different folders.Hypothetically, we would define multiple data loaders:data_loader_1=DataLoader(folder_name='*folder_name1*')data_loader_2=DataLoader(folder_name='*folder_name2*')...Now, if the data loader code block is used in a project, we require some code modularity to avoid
defining several versions of the same script.
One common solution is to rely onconfiguration files(e.g., JSON file).{'data_loader':{'folder_name':'*folder_name1*'}}The main script is modified to load our configuration file so that each code logic is properly initialized.CinnamonWell, cinnamon keeps this <configuration, code logic> dichotomy where a configuration is written inplain Python code!classDataLoaderConfig(Configuration):@classmethoddefget_default(cls):config=super().get_default()config.add(name='folder_name',type_hint=str,is_required=True,variants=['*folder_name1*','*folder_name2*',...],description="Base folder name from which to look for data files.")returnconfigCinnamon allowshigh-level configuration definition(constraints, type-checking, description, variants, etc...)To quickly load any instance of our data loader code logic, weregisterthe configuration via aregistration keykey=RegistrationKey(name='data_loader',namespace='showcase')Registry.add_configuration_variants_from_key(config_class=DataLoaderConfig,key=key)bindthe configuration to its code logic:DataLoaderConfig-->DataLoaderRegistry.bind(config_class=DataLoaderConfig,component_class=DataLoader,key=key)buildtheDataLoadercode logic with a specific configuration instance via the usedregistration keyvariant_key=RegistrationKey(name='data_loader',tags={'folder_name=*folder_name1*'},namespace='showcase')data_loader=Registry.build_component(key=variant_key)That's it!This is all of you need to use cinnamon.FeaturesGeneral-purposecinnamonis meant tosimplifyyour code organization for betterre-use.Simplecinnamonis a small library that acts as ahigh-level wrapperfor your projects.Modularcinnamonis shipped inseveral small packagesto meet different requirements.Community-basedtheComponentandConfigurationyou define can beimported from/exported toother users and project!Flexiblecinnamonimposesminimal APIsfor a quick learning curve.You are still free to code as you like!Installpippip install cinnamon-coregitgit clone https://github.com/federicoruggeri/cinnamon_coreContributeWant to contribute with newComponentandConfiguration?Feel free to submit a merge request!Cinnamon is meant to be a community project :)ContactDon't hesitate to contact:Federico Ruggeri @federico.ruggeri6@unibo.itfor questions/doubts/issues!