A package designed to simplify configurable defaults from argparse.
Project description
cfg_argparser 1.1.0
a config wrapper I made to be easily applied to argparse objects.
Installation
# from pypi:
pip install cfg-argparser
# from github:
git clone "https://github.com/zeptofine/cfg-argparser"
cd cfg-argparser
pip install -e .
Example
import argparse
from cfg_argparser import ConfigArgParser
def parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument("--file")
return parser
if __name__ == "__main__":
args = ConfigArgParser(parser(),
"config.json",
exit_on_change=True).parse_args()
print(args.file)
Wrapping the ConfigArgParser
around parser()
adds a few "magic" arguments.
here's what it adds:
Config options:
--set KEY VAL change a default argument's options
--reset [VALUE ...] removes a changed option.
--reset_all resets every option.
Here's what it looks like in practice:
> python example.py
None
> python example.py --file foo.txt
foo.txt
> python example.py --set file foo.txt
> python example.py
foo.txt
Compatibilty
This was mainly tested on 3.9 and 3.10, but it should work from 3.6 onwards. i can't test earlier versions for some reason.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cfg-argparser-1.1.0.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for cfg_argparser-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5583e627da772142a0699a5cad9b5f658fe140fc76bc6bf21f858e1ea2eaf88 |
|
MD5 | 0ad264dc0e3b96cd1e04e96723c7d7b7 |
|
BLAKE2b-256 | 6c7cccd49d8788782bb05f70ddc20ac768c665c85f2b4ea6c97396ffd74a573c |