settngs/README.md
Timmy Welch 38e42bf3f9
Make most functions work off of Config objects and Values/Namespace objects
Used Generic for better typing
Backported BooleanOptionalAction for tests on Python 3.8
Remove merge support in normalize_config
Add test to validate that the example works
2022-12-15 18:53:29 -08:00

2.1 KiB

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. 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
$ 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
  }
}

What happened to the 'i'?

PyPi wouldn't let me use 'settings'