Package: nostalgic
Savor what you feel and what you see / Things that may not seem important now / But may be tomorrow–Chuck SchuldinerNostalgicA configuration module to save and restore end-user and application
settings.No meta-filesBuilt using only the Python standard libraryHandle UI syncingInstallpipinstallnostalgicMotivationMany configuration packages themselves require configuration files.
This often is extraneous.Others provide a non-Pythonic API which hinders comprehension.  For
example, QSettings looks like# badself.settings.setValue("my_tracked_variable",value)and# badself.settings.value("my_tracked_variable",DEFAULT_SETTINGS["my_tracked_variable"])How you work with a variable depends on whether or not it's been
touched by Qt.With Nostalgic, these calls look simply like# goodself.settings.my_tracked_value=valueand# goodself.settings.my_tracked_valueFurthermore, most applications likely require only a single
configuration.  Nostalgic uses a Configuration singleton for this
reason.  Instantiate a Configuration and the next time one is created,
it will be a reference to the already extant Configuration.  This
means explicit references to the Configuration don't need to be passed
around.Quick StartA Configuration is a collection of Settings.Use a dot to get the Setting value (like an attribute)Settings can have a default initial valuewrite()settings to disk andread()them back in# basic usageimportos# needed only for demonstrationimportsys# needed only for demonstrationimportnostalgicif__name__=='__main__':# create configuration in current directorycfg=nostalgic.Configuration("sample_config")# declare a setting 'foo' with initial valuecfg.add_setting("foo",default="bar")print(cfg.foo)# "bar"# change the valuecfg.foo="baz"try:# second runcfg.read()print("Config just read")print(cfg.foo)# "baz"os.remove(cfg.config_file)ifnotos.path.exists(cfg.config_file):print("Removed config file")exceptFileNotFoundError:# first run, no config yetcfg.write()print("Wrote config")sys.exit()$python3"/home/ahab/Projects/nostalgic/scratch/sample1.py"bar
Wroteconfig

$python3"/home/ahab/Projects/nostalgic/scratch/sample1.py"bar
Configjustreadbaz
RemovedconfigfileAdvanced: coordinate a configuration with the UIOptional setter and getter functions handle updating other parts of your code.# demonstrate getting on write() and setting on read()importos# needed only for demonstrationimportsys# needed only for demonstrationimportnostalgicclassSettingsUI:def__init__(self):self.some_ui_thing_the_end_user_uses=0classMain:def__init__(self):self.cfg=nostalgic.Configuration("sample_config")self.settings_ui=SettingsUI()self.cfg.add_setting("ui_related_thing",setter=self.custom_setter,# called on read()getter=self.custom_getter)# called on write()defcustom_setter(self,value):print(f"Setting some_ui_thing_the_end_user_uses")self.settings_ui.some_ui_thing_the_end_user_uses=valuedefcustom_getter(self):print(f"Getting some_ui_thing_the_end_user_uses")returnself.settings_ui.some_ui_thing_the_end_user_usesif__name__=='__main__':main=Main()print(f"some_ui_thing_the_end_user_uses: "f"{main.settings_ui.some_ui_thing_the_end_user_uses}")# 0, the initial valuetry:# second runmain.cfg.read()print("Config just read")print(f"some_ui_thing_the_end_user_uses: "f"{main.settings_ui.some_ui_thing_the_end_user_uses}")os.remove(main.cfg.config_file)ifnotos.path.exists(main.cfg.config_file):print("Removed config file")exceptFileNotFoundError:# first run, no config yet# user changed the UI thingmain.settings_ui.some_ui_thing_the_end_user_uses=42main.cfg.write()print("Wrote config")sys.exit()The first run gets the end-user value before writing:$python3"/home/ahab/Projects/nostalgic/scratch/sample2.py"some_ui_thing_the_end_user_uses:0Gettingsome_ui_thing_the_end_user_uses
WroteconfigThe second run sets the end-user's previous value:$python3"/home/ahab/Projects/nostalgic/scratch/sample2.py"some_ui_thing_the_end_user_uses:0Settingsome_ui_thing_the_end_user_uses
Configjustreadsome_ui_thing_the_end_user_uses:42RemovedconfigfileUse thesyncparameter ofread()andwrite()to toggle whether
setters or getters are called.UseConfiguration.set()andConfiguration.get()to apply or update
settings en masse without accessing the hard disk.NotesShadowing Configuration methods with Settings of the same name is
possible, although not recommended.  A warning will be given.DevelopmentInstall as "editable" usingpip:~$cdProjects/nostalgic
~/Projects/nostalgic$python3-mvenvvenv
~/Projects/nostalgic$sourcevenv/bin/activate(venv)~/Projects/nostalgic$pipinstall-e.TestingRun tests using:(venv)~/Projects/nostalgic$python3tests/test_nostalgic.py