Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example should show case where no existing config file exists #109

Open
larocquemb opened this issue Aug 27, 2020 · 3 comments
Open

example should show case where no existing config file exists #109

larocquemb opened this issue Aug 27, 2020 · 3 comments

Comments

@larocquemb
Copy link

larocquemb commented Aug 27, 2020

example.py should create a new_template for the case where there is no existing configuration file, in order to create one the first time.

eg.

new_template = {
    'library': 'test_library.db',
    'import_write': 'yes',
    'ignore': 'ignore regex string',
    'plugins': [],

    'paths': {
        'directory': '.Music',
        'default': 'iTunes',
    },

    'servers': [
        {
            'hostname': 'matane.plar.ca',
            'options': ['foo'],
        },
        {
            'hostname': 'arsène.plar.ca',
            'options': ['bar', 'baz'],
        },
    ]
}

and then change from LazyConfig to base Configuration and set read=False.

config = confuse.Configuration('PaulConfuseExample', __name__, read=False)

@sampsyo
Copy link
Member

sampsyo commented Aug 27, 2020

Hi! I am not quite able to understand what you're proposing here… maybe you could consider putting together a PR showing what you're suggesting?

@larocquemb
Copy link
Author

The idea is for those who have no experience authoring YAML, is to create a Python dictionary of the configuration settings for their application. The Python dictionary method is useful because it is what the YAML is going to map to, and what the application will be unit tested against. Especially for those who already have a working application.

Then provide a way for clients to call Confuse to persist the Python config dict in memory to disk, in YAML format. Then the next time the program runs, there is a default YAML config available to be loaded. It should virtually guarantee that there are no syntax errors in the YAML. It takes a load off the developper trying to debug YAML.

@larocquemb
Copy link
Author

It would also be nice to show an example on how to do this in the documentation . I am sure it would drive more adoption in the module as I wasn't able to find many examples on the Internet. I ended having to clone your example project to debug it to better understand how it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants