Skip to content

Add API to make all settings available as a dictionary #5

@grimmy

Description

@grimmy

I need to output my settings at start up as well pass them around to other things (like jinja2). Currently I'm using a semi-dirty function that's monkey patched in (really dirty).

import types

from settingsd import install, pathing

settings = install(
    __name__,
    __path__=[
        pathing.home,
        pathing.default
    ]
)

def _settings_as_dict(self):
    def is_basic(instance):
        basics = (basestring, bool, dict, float, int, list, tuple)
        return isinstance(instance, basics)

    return {k: settings[k] for k in settings if k[0] != '_' and is_basic(settings[k])}
settings.as_dict = types.MethodType(_settings_as_dict, settings)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions