Go to file
Timmy Welch d2326eadb9
Add support for persistent setting groups
Persistent setting groups allow settings that are not declared to
 survive normalization and other operations that would normally remove
 any unknown keys in a group.

Calling normalize or get_namespace with persistent=False will remove
 unknown keys even from persistent groups.

Currently the only way to retrieve the defaults for a config and
 preserve unknown keys is to manually get the defaults and update each
 existing group with the default values.
2023-01-31 19:18:09 -08:00
.github/workflows Initial Commit 2022-12-14 20:57:57 -08:00
testing Add support for persistent setting groups 2023-01-31 19:18:09 -08:00
tests Add support for persistent setting groups 2023-01-31 19:18:09 -08:00
workflows Initial Commit 2022-12-14 20:57:57 -08:00
.gitignore Initial Commit 2022-12-14 20:57:57 -08:00
.pre-commit-config.yaml Initial Commit 2022-12-14 20:57:57 -08:00
LICENSE Initial Commit 2022-12-14 20:57:57 -08:00
README.md Add support for persistent setting groups 2023-01-31 19:18:09 -08:00
requirements-dev.txt Initial Commit 2022-12-14 20:57:57 -08:00
settngs.py Add support for persistent setting groups 2023-01-31 19:18:09 -08:00
setup.cfg Version Bump 2022-12-15 19:00:40 -08:00
setup.py Initial Commit 2022-12-14 20:57:57 -08:00
tox.ini Initial Commit 2022-12-14 20:57:57 -08:00

CI GitHub release (latest by date) PyPI PyPI - Downloads PyPI - License

Settngs

This library is an attempt to merge reading flags/options from the commandline (argparse) and settings from a file (json).

It is a modified argparse inspired by how flake8 loads their settings. Note that this does not attempt to be a drop-in replacement for argparse.

Install with pip

pip install settngs

A trivial example is included at the bottom of settngs.py with the output below (using bash). For a more complete example see ComicTagger.

$ python -m settngs
Hello world
$ python -m settngs --hello lordwelch
Hello lordwelch
$ python -m settngs --hello lordwelch -s
Hello lordwelch
Successfully saved settings to settings.json
$ python -m settngs
Hello lordwelch
$ python -m settngs -v
Hello lordwelch
merged_namespace.values.example_verbose=True
$ python -m settngs -v -s
Hello lordwelch
Successfully saved settings to settings.json
merged_namespace.values.example_verbose=True
$ python -m settngs
Hello lordwelch
merged_namespace.values.example_verbose=True
$ cat >settings.json << EOF
{
  "example": {
    "hello": "lordwelch",
    "verbose": true
  },
  "persistent": {
    "test": false,
    "hello": "world"
  }
}
EOF
$ python -m settngs --no-verbose
Hello lordwelch
$ python -m settngs --no-verbose -s
Hello lordwelch
Successfully saved settings to settings.json
$ python -m settngs --hello world --no-verbose -s
Hello world
Successfully saved settings to settings.json
$ python -m settngs
Hello world

settngs.json at the end:

{
  "example": {
    "hello": "world",
    "verbose": false
  },
  "persistent": false,
  "hello": "world"
}

What happened to the 'i'?

PyPi wouldn't let me use 'settings'